Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

split with no argument in perl

Tags:

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} ++;
  }
}
like image 489
realjin Avatar asked Oct 03 '11 12:10

realjin


People also ask

How do I split a value in Perl?

Perl | split() Function. split() is a string function in Perl which is used to split or you can say to cut a string into smaller sections or pieces. There are different criteria to split a string, like on a single character, a regular expression(pattern), a group of characters or on undefined value etc..

What is a dummy split?

Dummy-spit definition Filters. (idiomatic) The act of overreacting (as an adult) to a situation childishly, in an angry or frustrated manner.

How do I split a string into substrings in Perl?

Split (Split function is used to split a string into substring) /pattern/ (Pattern is used to split string into substring.) Split (Using split function divide string into substring) /pattern/ (We have used pattern to split string into substring.), Expression (Expression name used to split string.)

How do I split a string with spaces in Perl?

How can we split a string in Perl on whitespace? The simplest way of doing this is to use the split() function, supplying a regular expression that matches whitespace as the first argument.


1 Answers

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

like image 60
jpalecek Avatar answered Oct 11 '22 09:10

jpalecek