in reply to Using map
is rather a waste of time...$_ =~ s/taxman.add.subloc.//g if $_ =~ /taxman.add.subloc./
is sufficient since s will only do the replace if it matches, making the check for a match just slow you down... also you will notice that I removed $_ =~... s/// and // default to use $_, so it is just extra typing (you can do it if you want). I also changed your . to \. this is because . has special meaning in a regexp, which is that . will match any single character...s/taxman\.add\.subloc\.//g
As to why you are editing your main array. Map goes through your array and aliases each item of the array to $_. That means that any changes to $_ change the array items (this happens in for(@session_keys) as well), what you want to do is find the value you need and return it from the code block without editing $_... like so
That should do what you want... the .* matches everything after taxman.add.subloc. and the parens around it tell perl to store what it finds in $1. the ? : says if I matched sucessfully, return $1, if not return () which means nothing will be put into @sub_locs unless there is a match...my @sub_locs = map { /taxman\.add\.subloc\.(.*)/ ? $1 : () } @session_ +keys;
sound good?
Update my using return was wrong.. fixed...
- Ant
- Some of my best work - Fish Dinner
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Using map
by blackjudas (Pilgrim) on Oct 05, 2001 at 10:16 UTC | |
by suaveant (Parson) on Oct 05, 2001 at 17:26 UTC |