Anoop Kurup wrote:
>
> Can somebody explain to me what is the syntax error in the following
> code:
>
>
> 20 sub func()
> 21 {
> 22 my ($retension_period, $file_list) = @_;
> 23 my $file;
> 24
> 25 while(defined($file = glob("$file_list")))
> 26 {
> 27 -s $file && -M $file > $retension_period && { print "File name
is: $file\n"; print "File found\n"; }
> 28 }
> 29 }
>
> The error that I get is:
>
> syntax error at 2perlfind.pl line 27, near "; print"
> syntax error at 2perlfind.pl line 29, near "}"
> 2perlfind.pl had compilation errors.
>
> However, if I use the normal "if" condition, the error disappears. Can
> somebody please explain to me what am I doing wrong here?
I hope the question is academic, as it's beyond me why you should want to use an
ugly piece of code like this instead of a regular if statement! But if we're
into academia, there's no reason to stop using the && operator half-way through
the expression:
-s $file && -M $file > $retention_period && print "File name is: $file\n" &&
print "File found\n";
:)
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>