On Jul 27, 11:34 pm, u...@stemsystems.com ("Uri Guttman") wrote: > >>>>> "EW" == Erik Witkop <ewit...@gmail.com> writes: > > EW> I have spent half the day looking at map and I still don't get it. > > it is easier than you think. > > EW> I don't get the EXPR versus BLOCK and how I can treat them differently. > > that is mostly a syntax difference. you can have a single expression, > then a comma then the list OR a {} block of code, NO comma and a > list. the block allows you to declare variables, have multiple > statements, etc. some always use a block and for simple expressions it > is the same as the EXPR one. > > EW> I think I am close but my regex is not hitting. > > EW> @final_results = map { m/^[a-zA-Z0-9]{3,4}?$/$1/ } @just_cust_codes; > > you aren't GRABBING anything. this is not a map issue but a regex > one. people showed you how to do this in replies. why didn't you use > their code? > > secondly m// has TWO slashes, and you have 3. you are NOT doing a > substitution but a simple grab. and you aren't even doing a grab as > there are no parens. a regex in list context (like in a map) will return > its grabs so map will return them. no need for any $1 stuff. > > EW> I see a lot of people use a question mark in there, but I am unsure why. > > EW> All I want is the regex above to be in $1 for me to access. > > no you don't. it will be returned if you just use the code others have > posted. then ask how that code works. you are guessing and typing random > noise in hope that something will work. you need to understand how > regexes AND map work together. > > EW> Any help would be appreciated. > > EW> p.s. I read perldoc -f map, and checked my camel book. I am honestly at > a > EW> loss. > > did you read perldoc perlretut? and then perldoc perlre? the issue is > more regex than map. > > uri > > -- > Uri Guttman ------ u...@stemsystems.com -------- http://www.sysarch.com-- > ----- Perl Code Review , Architecture, Development, Training, Support ------ > --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com---------
Thanks everyone. I missed the earlier posts with the code. That worked beautifully. There is one more task that I am unable to solve. If $_ was something like FYUY or fO76, I would like to remove the first ^[Ff].But keep the last 3 character. Find and Replace does not work obviously as I would lose those last 3 characters that I want. I researched the map functionality and I can't come up with the proper code. This doc is very good at explaining map. http://mailman.linuxchix.org/pipermail/courses/2003-November/001368.html But I don't see how I can still keep the last 3 characters. I tried thinking of it in different way. I tried to do something like: @map_results1 = map(/(^[^Ff]{3})/, @map_results1); Basically saying, if it starts with NOT F or f, then grab 3 characters. Well that didn't work at all. But I understand how map works, a little better from trying new things. Any help on how I can remove F or f and still keep the last 3 characters in $_? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/