Re: grep file file handle



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.

.



Relevant Pages

  • Re: Getting a dir list (Why does this happen)
    ... opendir(DIR, $testDir); ... period character you need to precede it with a backslash. ... grep BLOCK LIST ... scalar context, returns the number of times the expression was ...
    (perl.beginners)
  • Re: Where am I going wrong?
    ... code, cuz' my mama told me if I can't say something nice, don't say ... In scalar context, grep() behaves exactly like ... scalar context the value of the array is one (regardless of the value ...
    (perl.beginners)
  • Re: usage of grep and map
    ... scalar context. ... These properties make grep useful for simply ... So map function returns the transformed or changed ... for/foreach loops/statement modifiers) they alias $_ ...
    (perl.beginners)
  • Re: map woes
    ... sort ... The readdir and grep work as I expect. ... The result of the map is a ...
    (comp.lang.perl.misc)
  • Re: Re: usage of grep and map
    ... elements but not the original ones and grep still ... (the value of the map expression). ... in scalar context. ... Mail has the best spam protection around ...
    (perl.beginners)