Strange problem with glob <>
- From: physiologoius@xxxxxxxxx ("Madhur Kashyap")
- Date: Thu, 28 Dec 2006 13:12:06 +0530
Hi there,
Have a look at these two different implementations. IMPL2 works somehow. The
problem I am facing is that the glob <$pat> does not return any value in
IMPL1 but it returns in IMPL2. Can somebody tell what could be the problem.
I have also tried including the advanced glob module using
use File::Glob qw(:globally :case);
============
=== IMPL 1 ===
============
#!/usr/local/bin/perl
$long=0;
$pat="*";
if ($#ARGV>2) {
print "Too many arguments.\nUsage: ldir [-lrh] [regexp] [dir]\n";
} elsif ($ARGV[0]=~/^-/) {
$args=$ARGV[0]; $args=~s/^-//g;
for ($i=0;$i<length($args);$i++) {
$temp=substr($args,$i,1);
if ($temp eq "r") {
if ($#ARGV<1) {
print "Too few arguments. Regexp expected with \"r\"
option."; exit 1;
} elsif ($#ARGV>1) {
$pat="$ARGV[2]/$ARGV[1]";
} else {
$pat="$ARGV[1]";
}
} elsif ($temp eq "l") {
$long=1;
if ($#ARGV>1) {
"Too many arguments with \"-l\" option.\nUsage: ldir [-lrh]
[regexp] [dir]\n";
} elsif ($#ARGV==1) {
$pat="$ARGV[1]/*";
}
} elsif ($temp eq "h") {
print "Usage: ldir [-lrh] [regexp] [dir]\n"; exit 0;
} else {
print "Unknown option \"$temp\"\nUsage: ldir [-lrh] [regexp]
[dir]\n"; exit 1;
}
}
} else {
if ($#ARGV>0) {
print "Too many arguments without any option.\nUsage: ldir [-lrh]
[regexp] [dir]\n"; exit 0;
} elsif ($#ARGV==0) {
$pat="$ARGV[0]/*";
}
}
@dirs=<$pat>;
print "pat=$pat,dirs=@dirs\n";
foreach $file (@dirs) {
if (-d $file) {
if (!$long) {
@dir=split("/",$file);
print "$dir[$#dir]\n";
} else {
print "$file\n";
}
}
}
============
=== IMPL 2 ===
============
#!/usr/local/bin/perl
use Switch;
$dummy="a";
switch ($dummy) {
case "a" {}
}
# Rest of the implementation is same as above
$long=0;
$pat="*";
- Follow-Ups:
- Re: Strange problem with glob <>
- From: Mumia W.
- Re: Strange problem with glob <>
- From: "Igor Sutton"
- Re: Strange problem with glob <>
- Prev by Date: Re: HoA building
- Next by Date: click_button gives error on a existing button
- Previous by thread: 1, random; 2, unicode
- Next by thread: Re: Strange problem with glob <>
- Index(es):