Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: passing arrays

by elmex (Friar)
on Apr 19, 2008 at 17:46 UTC ( #681679=note: print w/replies, xml ) Need Help??

in reply to passing arrays

Somehow this line looks a bit weird, I didn't know there is a one-argument form of split?

@mails = split ('$line');

Did you maybe mean: split ("$line") or even split ($line) or even: split (/;/, $line)?

Replies are listed 'Best First'.
Re^2: passing arrays
by GrandFather (Saint) on Apr 19, 2008 at 19:35 UTC

    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
      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.

      -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
Re^2: passing arrays
by ScOut3R (Sexton) on Apr 19, 2008 at 18:00 UTC
    My bad. I wanted to write split (' ', $line);.

Log In?

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

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

    Results (72 votes). Check out past polls.