Perl : Inline program to determine file size

Hi,

I have 5 files as below

$ ll sam*
-rw-rw-rw- 1 sam ugroup 0 Mar 21 06:06 sam3
-rw-rw-rw- 1 sam ugroup 0 Apr 3 22:41 sam2
-rw-rw-rw- 1 sam ugroup 17335 Apr 10 06:07 sam1
-rw-rw-rw- 1 sam ugroup 5 Apr 10 07:53 sam5
-rw-rw-rw- 1 sam ugroup 661 Apr 10 08:16 sam4

I want to list out the files that has a filesize greater than 700 bytes
This is the inline code i have written

$ perl -nwe 'foreach (@ARGV){ print $_ if -s > 700 }' sam*

However i don't get any output on the terminal, can you please tell me what is wrong with this code or if this code is entirely wrong.

Thanks
Sam

You don't need '-n' option here.

1 Like

Please post the output if the following command:

perl -e 'printf "%s --> %d\n", $_, -s for @ARGV' sam*
1 Like

@yazu, thanks i got exactly what i was looking for
i used -n option to suppress $_ when i was testing with the code and didn't use foreach, forgot to remove it...

@radoulov, thanks your code gave the below output

$ perl -e 'printf "%s --> %d\n", $_, -s for @ARGV' sam*
sam1 --> 17335
sam2 --> 0
sam3 --> 0
sam4 --> 661
sam5 --> 5

However I just wanted to get those files greater than a specific size

Does this produce the desired output?

perl -le'-s > 700 and print for @ARGV' sam*