Dear monks,
My input is a list with names following this pattern (in fact, matching the pattern is not my real issue):
1-PVC_0
2-PVC_0
2-PVC_1
etc...
I need to replace this list with a list of "features" of those names, that come as the output of a function, say function1.
I have done this with the following code:
@newlist = grep (s/(\d+-PVC_\d+)/ &function1($1)/e, @oldlist);
So far, so good. What if I want to replace each item with a string that is the concatenation of the result of function1, of the character "/" and the result of another function, function2. Then using this code:
@newlist = grep (s/(\d+-PVC_\d+)/ &function1($1) \/ &function2($1)/e,
+@oldlist);
(of course) gives me the result of a division :-)
How can I use s// with /e but in a way that evaluates, then quotes, then evaluates again?
Hope my problem statement was clear and I am not giving anyone a headache...
Athanasia
Update:
Sometimes, the obvious just does not pass from one's mind... However, I learned something new, that is the "map" function. Thanks to all those who responded!
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.