tamaguchi has asked for the wisdom of the Perl Monks concerning the following question:
In my folder C:/dataset/
I have the following files:
20051026ng3_Well A1_21593.pkl
20051026ng3_Well A2_21593.pkl
20051026ng3_Well A3_21593.pkl
20051026ng3_Well A4_21593.pkl
20051026ng3_Well A5_21593.pkl
20051026ng3_Well A6_21593.pkl
20051026ng3_Well A7_21593.pkl
20051026ng3_Well A8_21593.pkl
20051026ng3_Well A9_21593.pkl
To search for filenames containing alphanumeric signatures like A1, A2 etc. I have written the following:
C:/dataset/20051026ng3_Well A1_21593.pkl A1
Not found A2
C:/dataset/20051026ng3_Well A3_21593.pkl A3
Not found A4
C:/dataset/20051026ng3_Well A5_21593.pkl A5
Not found A6
C:/dataset/20051026ng3_Well A7_21593.pkl A7
Not found A8
C:/dataset/20051026ng3_Well A9_21593.pkl A9
I wonder how this small code could generate this results why are not all filenames containing the signatures A1, A2 etc. found? Thank you for your help.
I have the following files:
20051026ng3_Well A1_21593.pkl
20051026ng3_Well A2_21593.pkl
20051026ng3_Well A3_21593.pkl
20051026ng3_Well A4_21593.pkl
20051026ng3_Well A5_21593.pkl
20051026ng3_Well A6_21593.pkl
20051026ng3_Well A7_21593.pkl
20051026ng3_Well A8_21593.pkl
20051026ng3_Well A9_21593.pkl
To search for filenames containing alphanumeric signatures like A1, A2 etc. I have written the following:
The ouput I get is following:#!/usr/bin/perl -w use strict; my $path='C:/dataset/'; my @sign_arr=('A1', 'A2', 'A3','A4', 'A5', 'A6', 'A7', 'A8', 'A9'); foreach (@sign_arr) { if(defined (my $filename=(glob("$path*$_*.pkl")))) {print "$filename $_\n"} else {print "not found $_\n";} }
C:/dataset/20051026ng3_Well A1_21593.pkl A1
Not found A2
C:/dataset/20051026ng3_Well A3_21593.pkl A3
Not found A4
C:/dataset/20051026ng3_Well A5_21593.pkl A5
Not found A6
C:/dataset/20051026ng3_Well A7_21593.pkl A7
Not found A8
C:/dataset/20051026ng3_Well A9_21593.pkl A9
I wonder how this small code could generate this results why are not all filenames containing the signatures A1, A2 etc. found? Thank you for your help.
2006-08-21 Retitled by holli, as per Monastery guidelines
Original title: 'Glob strange bahavor'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Glob strange behavior
by jhourcle (Prior) on Aug 21, 2006 at 12:50 UTC | |
Re: Glob strange bahavor
by Sidhekin (Priest) on Aug 21, 2006 at 12:57 UTC | |
by ikegami (Patriarch) on Aug 21, 2006 at 14:52 UTC | |
Re: Glob strange behavior
by un-chomp (Scribe) on Aug 21, 2006 at 13:40 UTC | |
Re: Glob strange behavior
by cdarke (Prior) on Aug 21, 2006 at 12:46 UTC | |
Re: Glob strange behavior
by calin (Deacon) on Aug 21, 2006 at 15:41 UTC | |
by Anonymous Monk on Aug 22, 2006 at 03:15 UTC | |
Re: Glob strange behavior
by mobby_6kl (Novice) on Aug 21, 2006 at 22:22 UTC | |
Re: Glob strange behavior
by johnnywang (Priest) on Aug 21, 2006 at 23:37 UTC | |
by graff (Chancellor) on Aug 22, 2006 at 02:24 UTC | |
by Anonymous Monk on Aug 22, 2006 at 13:30 UTC | |
Re: Glob strange behavior
by Anonymous Monk on Aug 22, 2006 at 13:40 UTC |
Back to
Seekers of Perl Wisdom