Some additional notes: it actually gets even simpler.
my @cxx = map /(\w+\.cxx)@@/, <FILE>;
Lines that don't match will not return anything, so they simply fall through the cracks. Lines that match return a list of captured strings, of which there's only one here, so we get exactly what we want. For the latter snippet I'd advise using
<> so that you can take input from an arbitrary number of files or optionally from STDIN. By printing to STDOUT the user can redirect output to wherever he wants, including piping to another command. Not only is this much more flexible, you can also skip typing out a lot of file interaction and error checking code. The entire script is now reduced to a single line:
print map /(\w+\.cxx)@@/, <>;
That's all it takes. Pass it to
perl -e and you have a perfect oneliner. :)
Makeshifts last the longest.
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.