in reply to Re: passing arrays
in thread passing arrays

Actually all three arguments to split [pattern[, expression[, limit]]] are optional. Pattern defaults to whitespace splitting (' '). Expression defaults to $_. Limit defaults to 0 - that is, no limit.


Perl is environmentally friendly - it saves trees

Replies are listed 'Best First'.
Re^3: passing arrays
by Not_a_Number (Prior) on Apr 19, 2008 at 21:00 UTC
    Actually all three arguments to split [pattern;[, expression, limit]] are optional.

    I find that statement misleading. See the 'template' at the top of spilt:

    split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/ split

    This implicitly (and rightly) excludes:

    split EXPR

    Which is exactly what the OP tries to do in the line:

    @mails = split ('$line');

    This is why the OP's code generates the following error:

    Use of uninitialized value $_ in split at XX.pl line YY.

    IOW, the 'expression' argument is optional only if the 'pattern' argument is present.

      In that case the expression to be split is defaulting to $_, but at the time of his call it contains undef. You don't have to explicitly provide the text to split, but if you don't do so you should have what you want to split in $_ or it's not going to be very useful.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Re^3: passing arrays
by ikegami (Patriarch) on Apr 19, 2008 at 19:50 UTC
    -1 is no limit. 0 is no limit and discard empty trailing fields.

      Bah, so much for the 'Perl Pocket Reference' (where I 'checked' the parameters). ;)

      Actually, although I don't use it much now, the 'Perl Pocket Reference' is a really handy little book. It has exactly the right amount of information in it for a quick reference and is well indexed. Highly recommended for Perl newbies (ikegami is not a Perl newbie btw)!


      Perl is environmentally friendly - it saves trees
        Just ordered that book. :)