Geezer said:
@a contains:-
abcdefg1234
1234 this is a test
test
test 1234
I want to print everything with 1234 so:-
$list = @a =~ /1234/ ;
chomp($list);
print ($list);
Why doesn't this work?
"it doesn't work" is about the worst possible description of a problem.
What _does_ it do? Print something you didn't expect? Fail with an error
message? Hang in a loop? ...?
Well, at least you sort of told us what you did expect.
If you would have "use warnings;" then perl would have told you already what
is probably wrong (see output of warnings enabled).
Another hint can be found in the man page for m// (perldoc perlop, section
Regexp Quote-Like Operators):
If the "/g" option is not used, "m//" in list context returns a
list consisting of the subexpressions matched by the parentheses
in the pattern, i.e., ("$1", "$2", "$3"...). [...]
I don't see any capturing parathesis in your code.
When there are no parentheses in the pattern, the
return value is the list "(1)" for success.
Well, guess that's not what you are looking for, either. Seems like m// is
the wrong tool for the job.
Be grateful if someone can point me in the right direction.
From your description it seems you are looking for a plain old grep()?
jue