Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Reopen file when contents changed?

by salva (Canon)
on Jun 07, 2005 at 13:59 UTC ( #464306=note: print w/replies, xml ) Need Help??


in reply to Reopen file when contents changed?

just once per second? performance is not going to be an issue: use the aproach that seems simpler for you.

I would go for...

sub first_line_from_file { my $fn = shift; open my $file, "<", $fn or die "unable to open file $fn"; scalar <$file> }

update: added the scalar in front of <$file>. blazar, thanks for pointing it out.

Replies are listed 'Best First'.
Re^2: Reopen file when contents changed?
by blazar (Canon) on Jun 07, 2005 at 14:05 UTC
    sub first_line_from_file { my $fn = shift; open my $file, "<", $fn or die "unable to open file $fn"; <$file> }
    To return the first line I'd say
    scalar <$file>;
    (The semicolon is cosmetic. But I consider it good style)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://464306]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-08-08 11:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?