in reply to Match into scalar
I Trying to do a match on a scalar and put only the matching words into another scalar,
I'm skipping your code because it doesn't seem to bear any relation to your actual question. However I notice an issue here... you talk about "matching words" which is a plural and putting them into "another scalar" which is a singular. Now, this is somewhat odd. Of course you may join the matched words on spaces and assign the resulting string to a scalar. Otherwise just use an array instead. For example, suppose you want to match "words" beginning with "a":
my @matched = $str =~ /\ba\w+\b/g;
or, as hinted above:
my $matched = join ' ', $str =~ /\ba\w+\b/g;
Else, I don't know how to help you further without you giving us any further detail.
|
|---|