some perl help required

Posted by: ukengb

some perl help required - 14/05/2004 05:29

I'm in the process of fine tuning my perl server for RioReceivers but could do with some help regarding perl and I'm sure there are some experts here.

When does perl actually output what is specified with a 'print' command?

AFAICT it does not occur immediately, but it also appears not to wait until the script ends. In fact it seems to be quite inconsistent, but maybe that's me.

A perl script of mine that runs from cron and contains 2 consecutive procedures will show in the email (standard) errors from the second procedure BEFORE perl has 'printed' that the first procedure has ended, let alone the second one started. IOW, the perl 'printing' is delayed, but why and by how much?

This is important since I want to 'print' some output for apache to make into a web page, but then to continue with some further processing before the CGI actually ends - I don't want apache to have to wait for the output until the entire process has finished.

Any suggestions?
Posted by: geeknerd

Re: some perl help required - 15/05/2004 12:40

It has been a long time since I've touched perl, but I might be able to give you a push in the right direction.

I think that a print statement is buffered and doesn't guarantee that whatever printed happens right then. I believe there is a "flush" command that you can run to tell perl "Hey, print now what I've told you to print".
Posted by: ukengb

Re: some perl help required - 16/05/2004 01:05

There's no 'flush' command as such that I can find. I've been looking at $OUTPUT_AUTOFLUSH which may do what I need, but it's unclear to me exactly what it does. I'll check it out further. Any other ideas gratefully received.

I'm also looking for a faster way to find (i.e. discover the path to) a file by its inode number. Using 'find -inum xxxxxx' is very slow until the data is cached, which is too late. Any other faster ways to do this from within perl?

Thanks.

Posted by: geeknerd

Re: some perl help required - 16/05/2004 07:23

http://66.102.7.104/search?q=cache:3qQl9flOtrEJ:perl.plover.com/FAQs/Buffering.html+stdout+perl+flush+buffer&hl=en

Here's a good article on buffering. "Suffering from Buffering." (I sent you a copy from the google archive since it seems to have been taken down.) In the last few paragraphs it mentions that if you use the file or IO module, you can use the flush() command.

I'm not exactly clear on what autoflush does either.
Posted by: ukengb

Re: some perl help required - 17/05/2004 03:17

$OUTPUT_AUTOFLUSH is a synonym for $| which is covered in the info you supplied. There's a number of options in there so I think I'll be able to sort it out now.

Thanks.

BTW, any ideas on finding by the inode number?