Re: using file globs and regex
- From: Tad J McClellan <tadmc@xxxxxxxxxxxxxx>
- Date: Fri, 07 Aug 2009 12:06:08 -0500
pgodfrin <pgodfrin@xxxxxxxxx> wrote:
Greetings,
This program works fine (with file names f1..f8 in the directory):
#!/usr/bin/perl
use warnings;
use strict;
$\="\n";
while(<f*>)
{
print "$_";
if(/f5/)
{
my $fn=$_;
print "File name $fn found..." and exit;
}
}
exit;
But I was hoping to be able to do something like:
my $fn=grep (/f5/,<f*>);
Basically just trying to have less lines of code...any suggestions?
use grep() in a list context instead of in a scalar context.
I don't like using overloaded angle brackets in my code.
If I want equality, I use an operator that tests for equality.
my($fn) = grep ( $_ eq 'f5' , glob 'f*');
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
.
- Follow-Ups:
- Re: using file globs and regex
- From: Xho Jingleheimerschmidt
- Re: using file globs and regex
- From: pgodfrin
- Re: using file globs and regex
- References:
- using file globs and regex
- From: pgodfrin
- using file globs and regex
- Prev by Date: Re: Perl process as a unix background process
- Next by Date: Re: using file globs and regex
- Previous by thread: using file globs and regex
- Next by thread: Re: using file globs and regex
- Index(es):
Relevant Pages
|