On 3/9/06, Brian Poellnitz <[EMAIL PROTECTED]> wrote:

> The sample data below is read into a list, @dir_files.  What I'd like to do
> is grep() the list so that I'm left with only files that end in ".wav" and 
> contain
> certain string.  The "certain string" is where I run into problems.  Something
> like
>
> grep(/.*\.wav/)
>
> works fine for getting the items with .wav extensions.

Well, kinda. That pattern is looking for any item with '.wav' in the
name, so 'tidal.wave.jpg' qualifies. (And you've got the syntax for
grep wrong, but you knew that.) A better pattern might be /\.wav\z/ ,
which anchors the search to the end of the string.

> What I'd like to do is
> also filter for the existence of a string held in the variable $feed_date (In 
> my
> test case, $feed_date = "9mar").

Although it's tempting to use a pattern match for this, that's not the
right tool for the job. To see whether a string contains a given
substring, check whether the return value of index() is not -1. So
your grep might look something like this:

    my @result = grep /\.wav\z/ && (index(...) != -1), @source_list;

...once you have filled in the arguments to index, and assuming I
haven't made any errors. Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to