http://qs321.pair.com?node_id=575488


in reply to bsd_glob does not reset $!

Hi,
thanks to the help from the CB I have collected some answers. I think this sums it up.

Thanks

Regards... stefan k
you begin bashing the string with a +42 regexp of confusion

Replies are listed 'Best First'.
Re^2: bsd_glob does not reset $! (The lessons learned)
by ikegami (Patriarch) on Sep 29, 2006 at 15:33 UTC

    For performance and sanity my routine will first do a test for file-existance and then try to glob it. It feels clumsy, though.

    You need to check for file-existance afterwards, not beforehand. glob is not guaranteed to produce a list of existing files. For example, glob('file{a,b}') will return filea and fileb whether either, neither or both exists.

    @list = bsd_glob('~gnat', GLOB_ERR); die("Unable to glob: $!\n") if GLOB_ERROR; # Keep only references to existing files. @list = grep -f, @list; die("glob returned no existing results\n") if not @list;

    I am still confused about the way $! behaves in this case

    This case is not special.

    # XXX WRONG $rv = print $fh (...); if ($!) { die("Unable to write to file: $!\n") } # Ok $rv = print $fh (...); if ($rv) { die("Unable to write to file: $!\n") }