OfficeLinebacker has asked for the wisdom of the Perl Monks concerning the following question:
I have two lists, one of which is a subset of the other. So for example,
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".my @l1=("Date","IndexID","Maturity","OnTheRun","CompositePrice","Compo +siteSpread","ModelPrice","ModelSpread","Depth","Heat"); my @l2=("OnTheRun","CompositePrice","CompositeSpread","Depth");
I'm thinking there has to be a more elegant and/or efficient and/or more robust way.foreach my $f (@l1){ if (join(",",@l2) !~ /\b$f\b/){ $f='null'; } }
my @l3= map {(join(",",@l2) =~ /\b$f\b/)?$f:"null"} @l1; ?
_________________________________________________________________________________
I like computer programming because it's like Legos for the mind.
|
---|