Home > Archive > PERL Beginners > March 2006 > grep file file handle
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
grep file file handle
|
|
| perlnewbie02 2006-03-30, 9:57 pm |
| Hello,
In this script i am copying files to another machine which are newer
than 1 day.
I just want to grep out particular files like *.html and not have
everything copy over.
opendir DIR, '.';
while ($filename = readdir DIR)
{
if ( -M $filename < 1){
system "/bin/rcp $filename server1:/tmp";
}else{
print "no files\n";
}
}
Thanks in advance,
| |
|
| perlnewbie02 wrote:
>
use strict;
use warnings;
>
> opendir DIR, '.';
Should always check against failure
> while ($filename = readdir DIR)
You are using readdir in a scalar context,
but grep operates on an array/list. so if you want to utilize grep(),
this probably will get from the current directory all .html files that
is less than a day old:
my @html_files = grep { /\.html$/i && -M $_ < 1 } readdir DIR ;
Here readdir is used in a list context.
|
|
|
|
|