in reply to Re: split empty (lead|trail)ing fields
in thread split empty (lead|trail)ing fields

i think u didnt get the point: i was just counting the splitted elemets

my @our_arguments_are_safe =split /:/, ':'; print scalar @our_arguments_are_safe;

is it ok?

$p = "::"; @m = ($p =~ /(:)/g);

mm, why now do u count separators?

the 'no-code' question was:
why do split consider all empty fields as trailing when he find a list of two?

Replies are listed 'Best First'.
Re: Re: Re: split empty (lead|trail)ing fields
by BrowserUk (Patriarch) on Sep 27, 2003 at 12:35 UTC

    I think the answer to your question is in this paragraph of the docs.

    Empty leading (or trailing) fields are produced when there are positive width matches at the beginning (or end) of the string; a zero-width match at the beginning (or end) of the string does not produce an empty field.

    I say I think, because, even with the example given, I find it quite difficult to interpret that sentence. Especially in the light of a couple of other sentances

    By default, empty leading fields are preserved, and empty trailing ones are deleted.

    and

    If LIMIT is unspecified or zero, trailing null fields are stripped

    and

    Note that splitting an EXPR that evaluates to the empty string always returns the empty list, regardless of the LIMIT specified.

    Not at all clear to me:)


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
    If I understand your problem, I can solve it! Of course, the same can be said for you.