Ok, for one...
$_ =~ s/taxman.add.subloc.//g if $_ =~ /taxman.add.subloc./
is rather a waste of time...
s/taxman\.add\.subloc\.//g
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...

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

my @sub_locs = map { /taxman\.add\.subloc\.(.*)/ ? $1 : () } @session_ +keys;
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...

sound good?

Update my using return was wrong.. fixed...

                - Ant
                - Some of my best work - Fish Dinner


In reply to Re: Using map by suaveant
in thread Using map by blackjudas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.