[NCLUG] perl/programming question

S. Luke Jones luke at 6d.com
Mon Feb 19 08:55:19 MST 2001


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.pl
Type: application/x-perl
Size: 659 bytes
Desc: not available
URL: <http://lists.nclug.org/pipermail/nclug/attachments/20010219/64956780/attachment.bin>


More information about the NCLUG mailing list