I'm guessing you meant to type $_[KERNEL] etc. but the formatter ate it.

These are references to members in the array named @_ , which is how arguments get passed to subroutines in Perl. I'm guessing that KERNEL and HEAP are defined as constants (or are otherwise subroutines), and that they return numbers that can be used to index into @_. Why would someone get to arguments this way? Perhaps they mean to modify one of their arguments.

shift is used to remove and return an element off the start of an array. It is often used in conjunction with @_ to get (copies of) subroutine arguments. That is, given the following:

use constant KERNEL => 0; sub sub1 { $_[KERNEL] = 3; # modifies caller's version of arg } sub sub2 { my $kernel = shift; # copies arg $kernel = 3; # does not modify caller's version }
The reference to @_ in sub1 allows you to change the caller's version of the subroutine argument. In sub2, the argument is copied, and so changes made later to $kernel (which is copied from $_[0] ) don't get made to the caller's version.

update: clarified which end that shift operates on.


In reply to Re: newbie having syntax/variable problems by bikeNomad
in thread newbie having syntax/variable problems by kvaishnav

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.