Saturday, July 9, 2011

What does this split expression mean in Perl?

while (<>) {
 chomp;
 print join("\t", (split /:/)[0, 2, 1, 5] ), "\n";
}

What does (split /:/)[0, 2, 1, 5] mean here?


It means

my @fields            = split /:/, $_;
my @fields_to_display = ($fields[0], $fields[2], $fields[1], $fields[5]);

create a list by splitting the line on :, then take elements 0,2,1,5
of this list

No comments: