in reply to Re^2: Perl : Split/Regex
in thread Perl : Split/Regex
Since the OP mentions that the "Y" will be at the end, why not use a [ -1 ] subscript to avoid the "defined" complication?
That works, but what if you just so happen to have a "Y" in the third field? The OP's example lines only have numbers, granted, but I didn't want to assume too much about how his/her data is structured.
You could also use a single push with the conditional and target arrays in a ternary. Some may find this less readable than the if ... else ... but I prefer it for simple "push to this or that depending" situations.
Ah, yes, that's a good point. I was trying that, actually; it didn't work ("Not an ARRAY reference at ..."), but it didn't occur to me to wrap the whole shebang in a @{ }. OTOH, between that and the need to take references to the arrays you want to push to, it is indeed on the cryptic side.
Nevertheless, I learned something new. Thank you for enlightening me, brother!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Perl : Split/Regex
by 2teez (Vicar) on Sep 03, 2014 at 23:19 UTC | |
by AppleFritter (Vicar) on Sep 03, 2014 at 23:29 UTC | |
by 2teez (Vicar) on Sep 03, 2014 at 23:39 UTC |