Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by stefan k (Curate)
on Sep 29, 2006 at 09:31 UTC ( #575488=note: print w/replies, xml ) Need Help??


in reply to bsd_glob does not reset $!

Hi,
thanks to the help from the CB I have collected some answers.
  • I am still confused about the way $! behaves in this case, but I am not supposed to understand it (unless I learn the internals of Perl) and I am only supposed to use it when any error was signaled.
  • The desired outcome of bsd_glob can be achieved by passing the flag !GLOB_NOCHECK. Then the returned list will not contain the search pattern upon unsuccessful globbing. In my case this was hard because the real-world application in question sometimes uses a full pathname as a search pattern.
  • For performance and sanity my routine will first do a test for file-existance and then try to glob it. It feels clumsy, though.
  • Another way to check the outcome would be to undef $! before calling bsd_glob but since the documentation does not explicitly state the observed behaviour I will not rely on it to work.
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 (Pope) 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") }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://575488]
help
Chatterbox?
[Corion]: ambrus: Well, for mathematical notation, I find blackboard much more convenient than a computer. But when inserting text or moving text around, the computer wins obviously
[ambrus]: But either of these is a big problem in practice, so I'd need to spend like thirty years of my life to solve (a) and five more years to solve (b)
[ambrus]: Corion: yes, CURRENTLY the blackboard is more convenient
[ambrus]: and it's not like I want to ban blackboards anyway
[ambrus]: you already have blackboards and a canvas for projector or overhead transparencies (or positive film slide projector, not used for maths) canvas in the same lecture halls today, and switch in a few minutes between presentations,
[ambrus]: they're only difficult to use together.
[ambrus]: overhead transparencies are a nice convenience by the way that mix the two slides, because you can write them in advance and edit them during the presentation easily. but they're not very much in fasion these days.
[ambrus]: you can even print them.
[Discipulus]: ambrus i'm trying out MremoteNG which wrap putty and rdp and many other things..
[Corion]: ambrus: Yes, ideally you would have the ease of overhead projection transparencies and pens drawing on them, combined with the computer generated slide text...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2017-09-26 10:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (293 votes). Check out past polls.

    Notices?