Today around 3:34pm, Tom Christiansen hammered out this masterpiece:

: >Today around 11:48am, Tom Christiansen hammered out this masterpiece:
: 
: >: >So basically, it would be nice if each, keys, values, etc. could all deal
: >: >with being handed a hash from a code block or subroutine...
: >: 
: >: In the current Perl World, a function can only return as output to
: >: its caller a LIST, not a HASH nor an ARRAY.  Likewise, it can only
: >: receive a LIST, not those other two.
: 
: >So, this is really a bug?
: 
: >#!/usr/local/bin/perl -w
: >use strict;
: >$|++;
: 
: >sub func {
: >  return qw/KeyOne Value1 KeyTwo Value2/;
: >}
: 
: >print "$_\n" foreach keys &func();
: 
: No.  keys() expects something that starts with a %, not
: something that starts with a &.

Wow.  Now that, that, is lame.  You're saying that keys() expects it's first
argument to begin with a %?  Why should it care what it's argumen begins with?

All functions recieve their arguments in a LIST via @_.  Since &func, in the
above example, returns a LIST, that LIST should just be passed on.  I have to
say, caring about what the argument looks like is bad news.

I know it's core and it can do what it wants, but is should behave intuitivley,
don't you think?

keys( LIST );

Can be:

keys( %hash );

keys( @array );

keys( &func );

Run time error if there is an odd number of elements.

Otherwise, work something like this:

sub keys {
  my %hash = @_;
  return keys %hash;
}

What is so hard about that?  Besides, it's intuitive.  If I were to write my own
keys function, it would behave like above no matter what.  I would expect a
list, and return a list.

-- 


print(join(' ', qw(Casey R. Tweten)));my $sig={mail=>'[EMAIL PROTECTED]',site=>
'http://home.kiski.net/~crt'};print "\n",'.'x(length($sig->{site})+6),"\n";
print map{$_.': '.$sig->{$_}."\n"}sort{$sig->{$a}cmp$sig->{$b}}keys%{$sig};
my $VERSION = '0.01'; #'patched' by Jerrad Pierce <belg4mit at MIT dot EDU>

Reply via email to