Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re^2: passing arrays

by GrandFather (Saint)
on Apr 19, 2008 at 19:35 UTC ( #681688=note: print w/replies, xml ) Need Help??

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 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 (Pope) 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. :)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://681688]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2021-10-17 20:27 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (72 votes). Check out past polls.