in reply to Odd workings of split
One more, kinda unrelated, point. In Perl, unlike say in C#, the foreach loop variable is an alias to the list element and MAY be modified. So there is no reason to bother with the indices:
for (@cmd) { $_ = [split "\n", $_]->[0]; }
Next thing ... you don't have to create an anonymous reference and then dereference it to get the first element from a list returned by a subroutine. A pair of braces is enough:
for (@cmd) { $_ = (split "\n", $_)[0]; }
And last there really is no reason to avoid regexps. They tend to make the code simpler.
for (@cmd) { s/\n.*$//s; }
Jenda
Enoch was right!
Enjoy the last years of Rome.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Odd workings of split
by Ralesk (Pilgrim) on Mar 30, 2012 at 23:17 UTC | |
by Jenda (Abbot) on Mar 31, 2012 at 07:16 UTC |