Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: bsd_glob does not reset $! (The lessons learned)

by ikegami (Pope)
on Sep 29, 2006 at 15:33 UTC ( #575555=note: print w/ replies, xml ) Need Help??


in reply to Re: bsd_glob does not reset $! (The lessons learned)
in thread bsd_glob does not reset $!

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") }


Comment on Re^2: bsd_glob does not reset $! (The lessons learned)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://575555]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (16)
As of 2015-07-06 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls