[KLUG Members] perl syntax help

Jamie McCarthy members@kalamazoolinux.org
Mon, 8 Apr 2002 12:36:25 -0400


dbartley@schupan.com (Dirk H Bartley) writes:

> My Perl in a nutshell book tells me everythin I want to know but
> the syntax.
> 
> -z operator to determine if size is zero.
> -s will return the file size.
> 
> No examples are shown.  I tried a couple of ways like
> 
> if( -z /home/dbartley/file ){ do stuff here }
> 
> $var = -s /home/dbartley/file;
> 
> but it always errors out.  Anyone familiar with this.

"-z" and "-s" are operators, just like "+" and "." and so on.
They happen to be unary operators, like the minus sign that
precedes a number ("-123").

Their arguments have to be legal perl scalar values.  In this
case you want to pass them a string, and strings in perl are
quoted.

So you want:  if( -z "/home/dbartley/file" ){ etc.

Either single or double quotes will work.
--
 Jamie McCarthy
 jamie@mccarthy.vg