in reply to Re^3: split/map weirdness: empty strings vs undef
in thread split/map weirdness: empty strings vs undef

That is damn elegant.

UPDATE: After reading your update, i was a little dissapointed that i wouldn't be able to use your clean little trick, untill I looked at my data some more. Unlike ever other "seperated" data format I've ever seen, it allways puts a trailing seperator after the last field -- which means your orriginal one liner will work perfect for me ...I need to ignore the last pipe

go figure

  • Comment on Re: Re^3: split/map weirdness: empty strings vs undef

Replies are listed 'Best First'.
Re^5: split/map weirdness: empty strings vs undef
by Aristotle (Chancellor) on Oct 05, 2002 at 18:01 UTC
    You know, that gives me another idea for the cases you need to conserve the last field, although it is so similar to the add a bogus field approach that it bears the question whether the capture/grep hoopla is worth the hassle if you went that route anyway: add a field separator to the string.
    $ perl -le'$_ = "2|3|||||"; print join " : ", grep ++$i%2, split /(\|) +/, "$_|"' 2 : 3 : : : : :

    Makeshifts last the longest.