Greetings, esteemed monks!

I have two lists, one of which is a subset of the other. So for example,

my @l1=("Date","IndexID","Maturity","OnTheRun","CompositePrice","Compo +siteSpread","ModelPrice","ModelSpread","Depth","Heat"); my @l2=("OnTheRun","CompositePrice","CompositeSpread","Depth");
I want to end up with a list that is the same length as @l1, but every value that is not also present in @l2 should be replaced with "null".
What I have so far:
foreach my $f (@l1){ if (join(",",@l2) !~ /\b$f\b/){ $f='null'; } }
I'm thinking there has to be a more elegant and/or efficient and/or more robust way.
perhaps something like
my @l3= map {(join(",",@l2) =~ /\b$f\b/)?$f:"null"} @l1; ?

I guess what I don't like is the implied nested looping (I assume the join has to be re-done for each iteration through @l1?). Plus, the join just seems kind of ugly. Maybe it's unavoidable.

For the record, this is for Text::CSV::Simple and I am trying to make a field map.

_________________________________________________________________________________

I like computer programming because it's like Legos for the mind.


In reply to My 'perldar' tells me there is a 'better' solution for this list operation by OfficeLinebacker

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.