How to calculate size of a file from the command line arguments in perl -


i trying out sample program can calculate size of file given in command line arguments. gives size correctly when have file name stored inside variable, doesn't output result when got filename command line arguments.

#! /usr/bin/perl  use file::stat;  while(<>){  if(($_ cmp "\n") == 0){    exit 0;  }  else{    $file_size =  stat($_)->size; # $filesize = s $_;    print $file_size;  } } 

i no output when using file test operator -s , errors when using stat module:

unsuccessful stat on filename containing newline @ /usr/share/perl/5.10/file/stat.pm line 49, <> line 1. can't call method "size" on undefined value @ 2.pl line 17, <> line 1. 

1.txt filename i'm giving input.

#!/usr/bin/perl   (@argv){   $file_size = -s $_;   print $file_size; } 

or similar cmd oneliner,

perl -e 'say "$_, size: ", -s @argv' * 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -