Front page | perl.beginners |
Postings from April 2002
Re: grep
Thread Previous
|
Thread Next
From:
John W. Krahn
Date:
April 2, 2002 23:03
Subject:
Re: grep
Message ID:
3CAAA8FB.E9E9C416@acm.org
Sudarsan Raghavan wrote:
>
> Mandar Rahurkar wrote:
>
> > thanks to everyone for replying however I think i failed to define the
> > problem accurately :
> >
> > i have files assigned to @files variable :
> >
> > 2168a5_vow_band_1.fea
> > 169b2_vow_band_1.fea
> > 2168d6_vow_band_1.fea
> > 2168d5_vow_band_1.fea
> > 169g3_vow_band_1.fea
> > neutral.txt
> >
> > And i want the files say for eg suffix d and 1 and with extension fea.The
> > thing is if i try to match d all will get matched for obvious reason.
> >
> > basically I wanna generate the same output as of the following command on
> > shell prompt :
> > ls ???[g][^1] *.fea
> > ** will generate all files whose 4th char is g followed by character which
> > is not 1.
>
> Loop through the array and check the value against this regexp
> m/.{3}g[^1].*\.fea/
> If the array is being populated through some kind of file listing, my
> earlier suggestion
> holds.
Don't forget to anchor the regex at the beginning and end of the string:
@files = grep /^.{3}g[^1].*\.fea$/, @files;
John
--
use Perl;
program
fulfillment
Thread Previous
|
Thread Next