split with no argument in perl
I'm new to perl, and I wonder what this line of code mean?
($q,$dummy, $d,$v) = split;
I search through google, but i found no explanation of using split without argument, does this kind of use related to the "while" block?
And the full code fragment is:
open(T,"$opt_judgments") || die "can't open judgment file: $opt_judgments\n";
while (<T>) {
if ($opt_trec) {
($q,$dummy, $d,$v) = split;
} else {
($q,$d,$v) = split;
}
$dict{$q ."=".$d} =$v;
if ($v != 0) {
$totalRels{$q开发者_高级运维} ++;
}
}
It splits the current line ($_
) on whitespace. Quoting the manual:
If EXPR is omitted, splits the $_ string. If PATTERN is also omitted, splits on whitespace (after skipping any leading whitespace).
From perldoc:
The general syntax of split is:
split /PATTERN/,EXPR
If EXPR
is omitted, it splits the $_
string.
If PATTERN
is also omitted, splits on whitespace (after skipping any leading whitespace). Anything matching PATTERN
is taken to be a delimiter separating the fields. (Note that the delimiter may be longer than one character.)
Since in your case both PATTERN
and EXPR
are omitted. A split of $_
on whitespace occurs and the first four pieces of the split are assigned to $q
, $dummy
, $d
and $v
respectively.
精彩评论