On Saturday 01 December 2007 17:25, Matthew Whipple wrote:
>
> [EMAIL PROTECTED] wrote:
> >
> > kens <[EMAIL PROTECTED]> writes:
> >
> >> This test add nothing. The for loop will fail if there is no
> >> content
> >>
> >>> if ($DirContent[0]){
> >
> > Checking to make sure there are in fact numbered files already in
> > TrgDir.  As often as not it is a newly created and empty directory.
> >
> > If there aren't numbered files alread in it then no need for the
> > for loop.  So testing for value of $DirContent[0]) was supposed to
> > bypass the for loop if it were empty of value.
>
> The for loop won't execute if it has nothing through which to
> iterate. On my system the for won't execute with an empty list, but
> will once when the array is undefined.  Changing the above to 'if
> (defined(@DirContent)) {' would be a bit clearer.

But it would be wrong:

perldoc -f defined
[ SNIP ]
        Use of `defined' on aggregates (hashes and arrays)
        is deprecated.  It used to report whether memory
        for that aggregate has ever been allocated.  This
        behavior may disappear in future versions of Perl.
        You should instead use a simple test for size:

            if (@an_array) { print "has array elements\n" }
            if (%a_hash)   { print "has hash members\n"   }



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to