1832648 Members
3442 Online
110043 Solutions
New Discussion

killing script (Perl)

 
SOLVED
Go to solution
Victor Mo
Occasional Contributor

killing script (Perl)

Hi, guys !
I can't understand why my script where I was processing files witn .zip extension using:
...
opendir(DIR, "$dirr");
@files = grep(/\.zip$/,readdir(DIR);
closedir(DIR);
...

stopped working, nothing goes into @files now, I ran simple test script that pasted below and same result, it works with and doesn't with @files, tried Everything I could imagine, and still can' get why -(.

Please help.

Vic
-------------------- my test script
#!/usr/local/bin/perl

$dirr="/home/gemsdev/tidalgems";
print " #1 Opening dir $dirr\n";

opendir (DIRR,$dirr) or die "#1 can't open DIRR $dirr\n";
while ($igot = readdir(DIRR)) {
print "#1 list: $igot\n";
}
closedir(DIRR);


print " #2 Opening dir $dirr\n";
opendir (DIRR,$dirr) or die "#2 can't open DIRR $dirr\n";
@files=readdir(DIR);
print "#2 array: @files\n";
closedir(DIRR);
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor
Solution

Re: killing script (Perl)

Hi Victor:

This works:

#!/usr/bin/perl
use strict;
use warnings;
my $dirr = shift || '.';
opendir(DIR, "$dirr") or die;
my @files = grep( /\.zip$/, readdir(DIR) );
closedir(DIR);
print "'@files'\n";

...at the least, you were missing a ')'.

Regards!

...JRF...
Victor Mo
Occasional Contributor

Re: killing script (Perl)

Tx, James
Yes it works, I need to take a break.
Tx again

V