>>>>> "EW" == Erik Witkop <ewit...@gmail.com> writes:

  EW> So I have an array full of elements in the following format:
  EW> 32F--sometext-xxxx-x
  EW> F32-sometext12-xxx

  EW> I am only interested in the first portion before the first hyphen.

  EW> I am able to grep to get that portion.

grep doesn't give back portions. you seem to misunderstand what grep
does. it only returns some of the elements in its input list. it is a
filter. 

  EW> @grep_results1 = grep(/[a-zA-Z0-9]{2,4}-/, @sho_port_small_array);

  EW> Now I want to print the GREP MATCH, e.g. 32F-.

  EW> I know in awk I can print $1 which is the grep match.

use grabbing as in most regexes. don't compare perl to awk as perl is a
full programming language vs awk's whatever you call it (and i used awk
a ton before i got into perl!).

  EW> How can I do this in perl.

  EW> I would rather not split each element delimited by hypens. There must
  EW> be an easy way to print the portion that GREP actually matched on.

don't use grep then. or use map and then grab the parts you want. map
has a similar syntax to grep but instead of filtering, it builds a new
list from its expression/code block. you can grab the part you want in
the regex and map will return it in a list.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to