[NCLUG] perl/programming question

Charles Clarke clarke at clarkecomputer.com
Mon Feb 19 11:48:25 MST 2001


If you do a "man perlobj" and read it, it will answer your question for
you.  From the first page of the man page...

 
       3.  A method is simply a subroutine that expects an object
           reference (or a package name, for class methods) as
           the first argument.

So, $S contains the object reference and %params now contains %blocks

charles

On Mon, 19 Feb 2001, S. Luke Jones wrote:

> Date: Mon, 19 Feb 2001 08:55:19 -0700
> From: "S. Luke Jones" <luke at 6d.com>
> Reply-To: nclug at nclug.org
> To: nclug at nclug.org
> Subject: Re: [NCLUG] perl/programming question
> 
> Sean Reifschneider wrote:
> > On Sun, Feb 18, 2001 at 09:33:47PM -0700, mike cullerton wrote:
> > >  sub page_out {
> > >    my $S = shift;
> > >    my %params = @_;
> > >so, does %params now contain %blocks?
> > 
> > My guess would be that %params contains all but the first element of
> > %blocks.  "shift" consumes one argument.  It could also be that $S
> > contains "%blocks", and "%params" is nothing though.  I never really
> > could understand how to pass an array to a function in Perl.
> 
> Well, they're passing the hash to a subroutine so it will get flattened
> into an array. Then, before they can turn it back into a hash, they
> peel off the first element with a shift. The problem here is that the
> definition of "first" is undefined since this is a hash, which perl
> will store however it feels like. The standard idiom if you care about
> the ordering of the hash is to do something like:
> 
> 	for $k in (sort keys %hash) {
> 		do something
> 	}
> 
> I've attached a sample perl program for anybody to play with if they want
> to figure this one out, because it beats me.
> 
> Luke Jones


--------------------------------------------------------------------------
 Domain hosting from $15/month with error log analysis and link checking.
 http://www.clarkecomputer.com/sig.html       domains at clarkecomputer.com


More information about the NCLUG mailing list