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



Andy Greenwood wrote:
On 1/30/07, Michael Alipio <daem0nb0y@xxxxxxxxx> wrote:

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

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

What does this tells? What does -2 and -1 tells? All I know is that
split will output a list containing two values that will be assigned
to $country and $bytes for every line of that whois.bytes file. But
I'm not sure what those -2,-1 means and how it was able to extract
column 5 and 6. I tried looking at perldoc -f split but cannot seem to
find the explanation. Are those the LIMIT thing?

(split) gives you an array,

Actually, it gives you a list, which you can then store in an array.

perldoc -q "What is the difference between a list and an array"



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.



Relevant Pages

  • Re: SOLVED: How do I scope a variable if the variable name contains a variable?
    ... Either I have it right but am expressing it poorly, ... so I wonder if my understanding is all wrong. ... table so you can't get access to them via symrefs. ... DF> You suggested using a hash INSTEAD of an array, ...
    (comp.lang.perl.misc)
  • Re: style of functions with complex arguments
    ... > where the list at the end is actually a set of 3 triples. ... triples I would use an array reference as well. ... then you need to check that the 'weights' is an array ref (perldoc -f ...
    (perl.beginners)
  • RE: Why doesnt this work?
    ... Any time you don't understand a Perl function, look it up via perldoc. ... the shiftin the sub: ... Removes the first element of an array and stores it in $search. ...
    (perl.beginners)
  • Re: Easy Field Grabbing Question
    ... > ok another stupid question time! ... > how does the above work for an array?? ... While, with perldoc, it can sometimes be a little hard to figure out how ... and learn some of the basics first. ...
    (comp.lang.perl.misc)
  • RE: How to store the out put in StringBuffer
    ... I have been mentioning @tail. ... An array is the one variable that can do what you ... perldoc perlintro ... How to store the out put in StringBuffer ...
    (perl.beginners)