Re: confusion with splitting columns using [-n, -n] (e.g; my ( $country, $bytes ) = ( split )[ -2, -1 ])



On Jan 30, 12:35 am, daem0n...@xxxxxxxxx (Michael Alipio) wrote:
Someone has given me this code:

[ . . . ]
my ( $country, $bytes ) = ( split )[ -2, -1 ];

It is working perfectly but now, I need to document this code.
Can anyone help me out on understanding this code.

I have a dumb question. Why aren't you just asking whoever gave you
the code in the first place?

I'm particularly confused with the line:
"my ($country, $bytes) = (split) [-2, -1];

What does this tells? What does -2 and -1 tells?

It's a list slice. Read about slices in:
perldoc perldata

or online at:
http://perldoc.perl.org/perldata.html#Slices-slice-array%2c-slice-hash
%2c-slice

Paul Lalli

.