Re: list of strings to array

From: Rob Dixon (rob_at_dixon.port995.com)
Date: 02/21/04

  • Next message: Anthony Vanelverdinghe: ""tables" in Perl"
    To: beginners@perl.org
    Date: Sat, 21 Feb 2004 12:51:43 -0000
    
    

    David Le Blanc wrote :
    >
    >
    > Just a note.
    >
    > @array = split / /, "one two three four";
    >
    > and
    >
    > @array = split " ", "one two three four";
    >
    > are not the same. The second is special-cased inside perl to do the
    > same as the AWK split command. The first is just a normal regular
    > expression matching exactly one space.
    >
    > Hence
    >
    > if
    > $a=" one two three four "; (note the leading and extra spaces)
    >
    > after
    > @array = split / /, $a
    >
    > @array will contain ( undef, 'one', 'two', undef, 'three', 'four', undef
    > )

    No.

      @array will contain ( '', 'one', 'two', '', 'three', 'four')

    'split' returns the next component up to the next separator. If there
    are no characters before that separator then the component will be an
    empty string. No trailing empty strings are returned.

    Rob


  • Next message: Anthony Vanelverdinghe: ""tables" in Perl"

    Relevant Pages