Thank you so much (and for the tip too). It works great!
One more question, how do I strip out all letters before "xyz". For the original
example, how would I get "xyzb" and "xyzd"?
Thanks again,
Kevin
David Dorward <[EMAIL PROTECTED]> wrote:
Tip: This is a beginners list, therefore many questions will be simple.
Aim for more descriptive subject lines and life will be easier for
users of the list archives.
On 16 Jun 2004, at 17:10, Kevin Zhang wrote:
> For the following string:
>
> "uuuu axyzb oooo cxyzd vvvv"
>
> What is the command to extract the substrings with "xyz" in them? In
> this case, I'd like to get two strings "axyzb" and "cxyzd".
The useful functions here are "grep" and "split" (perdoc -f grep and so
on).
#!/usr/bin/perl
use strict;
use warnings;
my $string = "uuuu axyzb oooo cxyzd vvvv";
my @list_of_words = split /\ /, $string;
my @list_of_words_containing_xyz = grep /xyz/, @list_of_words;
foreach my $word (@list_of_words_containing_xyz) {
print $word, "\n";
}
or, in less verbose form:
foreach (grep(/xyz/,split(/\ /, "uuuu axyzb oooo cxyzd vvvv"))) { print
$_, "\n"; }
--
David Dorward
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.