Erik Witkop wrote:
So I have an array full of elements in the following format:
32F--sometext-xxxx-x
F32-sometext12-xxx
I am only interested in the first portion before the first hyphen.
I am able to grep to get that portion.
@grep_results1 = grep(/[a-zA-Z0-9]{2,4}-/, @sho_port_small_array);
Now I want to print the GREP MATCH, e.g. 32F-.
I know in awk I can print $1 which is the grep match.
How can I do this in perl.
I would rather not split each element delimited by hypens. There must
be an easy way to print the portion that GREP actually matched on.
Use map instead of grep:
my @grep_results1 = map /([a-zA-Z0-9]{2,4}-)/, @sho_port_small_array;
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/