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


In reply to Re: Passing file check operators to a function by sk
in thread Passing file check operators to a function by smartnezz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.