in reply to Passing file check operators to a function

I have just read through your specification

Something like this will do?

#!/usr/bin/perl -w use strict; sub checkit { my $file = shift; return (-e $file && -w _); # the _ is a shortcut for checking on +the same file instead of making another stat call } my $ret = checkit("/home/monk/hello"); if ($ret) { print "File exists with write perm\n" } else { print "File does not exist or no write perm\n"; }

will let you know shortly why your code does not work. In the mean time check out perldoc -f -X

Update: First off why do you need to check for exists and write perm? -w would take care of that.

Why do you think your -e,-w works?  if (-e,-w $file) does not do  if (-e $file && -w $file) The comma operator just returns the last value evaluated. So it basically will do -w $file and tell you the answer. It might work out but if you turn on warnings you will notice -e works on uninit value as it is looking for $_. If you have set $_ elesewhere it makes things worse as it is not doing what you wanted

 $_[0] && $_[1] in your if statement just checks if the values  $_[0] and $_[1] for true/false. It does not evaluate the expression. Besides  if ($_[0] $_[1]) is not a valid syntax

Hope this helps!

cheers

SK