stefan k has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monks,
I must confess I am confused.
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:
Using GLOB_ERR or GLOB_NOCHECK or both of them changes nothing. Now my questions are#! /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";
- 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?
Regards... | stefan k |
you begin bashing the string with a +42 regexp of confusion |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: bsd_glob does not reset $!
by merlyn (Sage) on Sep 28, 2006 at 16:19 UTC | |
Re: bsd_glob does not reset $!
by ikegami (Patriarch) on Sep 28, 2006 at 16:23 UTC | |
by stefan k (Curate) on Sep 29, 2006 at 07:44 UTC | |
by ikegami (Patriarch) on Sep 29, 2006 at 15:19 UTC | |
Re: bsd_glob does not reset $!
by cdarke (Prior) on Sep 28, 2006 at 16:23 UTC | |
Re: bsd_glob does not reset $!
by chromatic (Archbishop) on Sep 28, 2006 at 20:56 UTC | |
Re: bsd_glob does not reset $! (The lessons learned)
by stefan k (Curate) on Sep 29, 2006 at 09:31 UTC | |
by ikegami (Patriarch) on Sep 29, 2006 at 15:33 UTC |
Back to
Seekers of Perl Wisdom