Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Fellow Monks,
I must confess I am confused.

In one of my programs I concatenate some user-provided strings to build a file-match pattern which I then feed to bsd_glob from the File::Glob module. Then I need to detect whether it matched some files and proceed doing something with them. Sounds quite straightforward to me. But during this I ran into a strange runtime behaviour that I could boil down to the following test script:

#! /usr/bin/perl use strict; use warnings; use Data::Dumper; use File::Glob qw/:glob/; # There lives a file "passwords.dat" in the current directory.... # This matches the whole filename. OK my $pat1 = "passwords.dat"; print "\nPATT $pat1\n"; print "PRE ERR: ", Dumper($!); my @list = bsd_glob($pat1, GLOB_ERR); print Dumper(\@list); print "POST ERR: ", Dumper($!); print "\n"; # This file is not there so it doesn't match and afterwards $! ist # set. OK my $pat2 = "this_will_miss_in_globbing"; print "\nPATT $pat2\n"; print "PRE ERR: ", Dumper($!); @list = bsd_glob($pat2, GLOB_ERR); print Dumper(\@list); print "POST ERR: ", Dumper($!); print "\n"; # This should match again since it is just the same as the first match # but *afterwards $! ist still set*!!?? my $pat3 = "passwords.dat"; print "\nPATT $pat3\n"; print "PRE ERR: ", Dumper($!); @list = bsd_glob($pat3, GLOB_ERR); print Dumper(\@list); print "POST ERR: ", Dumper($!); print "\n"; # This resets $! back to normal which is just fine my $pat4 = "*.dat"; print "\nPATT $pat4\n"; print "PRE ERR: ", Dumper($!); @list = bsd_glob($pat4, GLOB_ERR); print Dumper(\@list); print "POST ERR: ", Dumper($!); print "\n";
Using GLOB_ERR or GLOB_NOCHECK or both of them changes nothing. Now my questions are
  • Why is the variable $! not reset back to normal on successful glob with $pat3?
  • How do I get bsd_glob() to do just that?
  • What is The Right Way to check the outcome of bsd_glob?
I assume that the error is on my side since this module is a core module which is even used to implement Perls glob() built-in.

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

In reply to bsd_glob does not reset $! by stefan k

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (6)
    As of 2018-03-20 22:29 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (260 votes). Check out past polls.