dolphin wrote:
Hi,
Hello,
Correct me that the "2" in the following means read?
:
my ( $label, $value ) = split /,/, $line, 2;
The third argument to split determines how many list elements will be
returned. For example, if:
my $line = 'one,two,three,four,five,six,seven';
Then:
split /,/, $line, 2
Would return the list:
( 'one', 'two,three,four,five,six,seven' )
However if you did:
my ( $label, $value ) = split /,/, $line;
Then split would return the list:
( 'one', 'two', 'three,four,five,six,seven' )
Just as if you had done:
my ( $label, $value ) = split /,/, $line, 3;
Perl knows how many list elements are expected and only splits enough to
satisfy that request.
Also, if:
my $line = 'one,two,three,,,,';
And you do:
my @array = split /,/, $line;
Then split will return the list:
( 'one', 'two', 'three' )
But if the third argument is a negative number:
my @array = split /,/, $line, -1;
Then split will return the list:
( 'one', 'two', 'three', '', '', '', '' )
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/