in reply to newbie having syntax/variable problems
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:
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.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 }
update: clarified which end that shift operates on.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: newbie having syntax/variable problems
by dragonchild (Archbishop) on Aug 07, 2001 at 16:48 UTC |