On Thu, 11 Sep 2014 12:02:30 -0500
"Martin G. McCormick" <mar...@server1.shellworld.net> wrote:

>       I was checking to see how in perl can one quickly test
> for a file which exists but is empty and found an example so I
> wrote the following code which seems to work beautifully but it
> looks a little different compared to some things I have seen so
> I am asking whether it could have unintended consequences. Code
> follows:
> 
> if ( !-z '/usr/home/automation/power' ) {
> 
>     #mail /usr/home/automation/power
>     system("mail -s \"Power Issues\" toptendhcp
> </usr/home/automation/power"); }
> else {
>     #no POE problems
>     system("mail -s \"No Power Issues\" toptendhcp
> </tmp/nothing2report.txt"); }
> 
>       The -z test reminds me a bit of shell scripting when one
> needs to test whether a string is empty or not. If this is safe,
> it is a really nice way to test files for emptiness.
> Thank you.
> 
>       Martin McCormick
> 

Yes, Perl does follow the shell when it comes to file tests. See
`perldoc -f -X

Also, you can use `-s` instead of `! -z`.

-- 
Don't stop where the ink does.
        Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to