Is there any way to call
split in such a way that it will return an array without any empty entries? What I want to do is something like the following:
my ( $one, $two ) = split /exp/, $line
I can guarantee that the resulting array will have at least two entries, but it might have more than that, and some of them might be empty. I want $one and $two to contain the first two nonempty array entries.
The best way I can think of doing it now (and I use the word "best" very, very loosely) is declaring an array to hold the return from split, looping through it and pushing all nonempty entries onto yet another array, and taking $yetAnotherArray[0] and $yetAnotherArray[1] and storing them in $one and $two. That solution is simply so hideous I'd be embarrassed to use it.
I sort of thought I might be able to use map to do it, but I'm a map newbie and couldn't figure out exactly how to go about it.
If you have any trouble sounding condescending, find a Unix user to show you how it's done.
- Scott Adams
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.