Click to See Complete Forum and Search --> : quick perl ?


moose
02-22-2001, 11:15 AM
I'm working through Learning Perl and just finished the RegExp chapter...

Anywho...

I understand what the 'split' function does, but I didn't get what the second comma was for in:

= (split /,/, $line)

I know the first comma is delimiting $line by commas, but what about that second comma?

Thanks...

Moose

Ben Briggs
02-22-2001, 11:33 AM
To start off, it's technically written:

$foo = split(/,/, $line);

(Note the position of the first parentheses.)

The second comma is a delimeter to the function split, it tells split that another argument is coming ($line).

jemfinch
02-22-2001, 12:06 PM
Originally posted by Ben Briggs:
To start off, it's technically written:

$foo = split(/,/, $line);



Technically, it doesn't matter. Not only that, but you'll find the code of more experienced perl users tends not to use the parentheses.

You're right about the comma, though. It's to separate arguments to split.

Jeremy

YaRness
02-22-2001, 01:44 PM
the simplest way to write it is

= split /,/, $line;

a more readable version that does the same thing in this case is

= split ',', $line;

or, as above, split(...).