Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > readdir and regex

Reply
Thread Tools

readdir and regex

 
 
poncenby
Guest
Posts: n/a
 
      01-24-2007
my perl program accepts arguments which will match a directory under
$path. however this argument may not be specified so all directories
shall be processed under $path.
this is the way i'm doing it:

my $idopt = $ARGV[0];
my $path = "/home/user/";
opendir (ROOT, "$path");

if ($idopt) { $idre = qr/$idopt/o; } elsif ( !$idopt) { $idre =
"!/^\.\.?$/"; }

my @dirid = grep { $idre }, readdir (ROOT);

however the dirid array is populated with every directory under $path,
regardless of what I specify in ARGV[0].

can anyone help?

thanks

 
Reply With Quote
 
 
 
 
Mirco Wahab
Guest
Posts: n/a
 
      01-24-2007
poncenby wrote:
> my perl program accepts arguments which will match a directory under
> $path. however this argument may not be specified so all directories
> shall be processed under $path.
> this is the way i'm doing it:
>
> my $idopt = $ARGV[0];
> my $path = "/home/user/";
> opendir (ROOT, "$path");
>
> if ($idopt) { $idre = qr/$idopt/o; } elsif ( !$idopt) { $idre =
> "!/^\.\.?$/"; }
>
> my @dirid = grep { $idre }, readdir (ROOT);
>
> however the dirid array is populated with every directory under $path,
> regardless of what I specify in ARGV[0].


Of course, there is a lot of things that went wrong here

Try to modify your program step for step
and look what happens.

Here's my first shot at it:

...
my $path = '/home/user/';
my $idre = $ARGV[0] ? qr{$ARGV[0]} : '^(\.(?!\.))?[^\.].+';

opendir ROOT, $path or die "open failed $!";
my @dircont = grep /$idre/, readdir ROOT;
closedir ROOT;

print join "\n", @dircont;


Regards

Mirco
 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      01-24-2007
poncenby <(E-Mail Removed)> wrote in comp.lang.perl.misc:
> my perl program accepts arguments which will match a directory under
> $path. however this argument may not be specified so all directories
> shall be processed under $path.
> this is the way i'm doing it:
>
> my $idopt = $ARGV[0];
> my $path = "/home/user/";
> opendir (ROOT, "$path");
>
> if ($idopt) { $idre = qr/$idopt/o; } elsif ( !$idopt) { $idre =
> "!/^\.\.?$/"; }
>
> my @dirid = grep { $idre }, readdir (ROOT);


The line above is a syntax error. It can't be your real code.
Please copy/paste code instead of re-typing it. Typos like that
confuse the issue unnecessarily.

Anno
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive parallel readdir() with drb and slave libraries John Stoffel Ruby 0 02-06-2009 05:19 PM
readdir the directory name and file name separately? Davy Perl Misc 2 08-24-2006 04:19 AM
opendir and readdir vs glob iteration it_says_BALLS_on_your forehead Perl Misc 9 12-03-2005 08:42 AM
Looking for a class similar to 'opendir' and 'readdir' Ramon Java 5 01-03-2005 01:59 PM
readdir() and S_ISDIR(stat.st_mode) question (OT ?) electric sheep C Programming 2 03-04-2004 08:15 AM



Advertisments