in reply to more ways to filesize

if (-s $file) { my $size = (stat $file)[7];

That would be better written as: my $size = -s $file;

See perlfunc for documentation of the fact that -s returns the size of the file (in bytes.)

Update: (Answering Chmrr's reply below...)

my $size = -s $file; if ($size) { . . . }
-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: more ways to filesize
by Chmrr (Vicar) on Aug 06, 2002 at 01:05 UTC

    Actually, it's probably better written as:

    if (my $size = -s $file)

    ..or, if you don't like the assignment in the if, you can keep the (oh-so-slight..) efficiency increase by saying:

    if (-s $file) my $size = -s _;

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'