DeusVult has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|