OK, well I started this email looking for help with some weird errors that I
just wasn't getting. As I described the problem, I thought of a couple more
things to try - why not - and one of them worked. But I'm still not _sure_ why,
so I thought I'd send it on anyway in hopes someone can explain it to me -
preferably in small words ;-}. Besides, the information might help someone else.
The problem was exposed while running make test on a module I'm working on. The
subroutine is being called from within an AUTOLOAD subroutine, which sends the
results to the appropriate code for processing and then munges the return. The
error was reported when doing the hash assignment to %params below:
=code
sub _munge_seq_input {
my $self = shift;
my $seq = (ref($self) && ref($self) !~ /ARRAY|HASH|SCALAR/) ? shift : $self;
_help() if (! ref($seq) && $seq eq "help");
warn join("==",@_),"\t",scalar(@_),"\n";
my %params = @_ || (); # what if it's a ref, does this DWIM?
local $DEBUG = exists $params{DEBUG} ? $params{DEBUG} : $DEBUG;
if ($DEBUG >= 3) { foreach my $k (keys %$self) { print "$k\t$$self{$k}\n" }
}
print ref($seq),"<- ref?\n" if $DEBUG >= 2;
if ($DEBUG >= 2) { foreach my $k (keys %params) { print "$k\t$params{$k}\n"
} }
=cut
The error was odd number of elements assigned...?! OK, so I threw in the warn,
which indicated that @_ contained excactly what I expected; DEBUG and 2. Well,
after thrashing and skimming some docs for a while without result, I started up
an email. For some reason, maybe the lack of pretty print and syntax
highlighting, I started wondering about precidence in @_ || (); So I switched
the problem line to:
my %params = @_ or ();
And it worked! <SIGH> As a personal fan of the my $arg = shift || "default" type
syntax, I was a bit disapointed, but now I know. However, this exposed another
problem. The return from that routine was:
return($self,$AR_seqs,$return_type,%params);
Which was expected by the calling statement:
my ($self,$AR_seqs,$return_type,%params) = _munge_seq_input(@_);
Which I expected to work fine, after all,
sub new($%) {
my ($proto,%parameters) = @_;
worked fine (tested), and I knew things like,
456: 10:15am % perl -e '%h = (foo => 1, bar => 2);@a = %h;print "@a\n"'
foo 1 bar 2
worked. So why the (appears to me) inconsitant behavior? So I changed the return
statement to:
return($self,$AR_seqs,$return_type,(each %params));
Which works fine, but seems like a lot of extra work. So there's my morning so
far. If anyone who understands the guts of perl enough to explain why that works
that way so I can avoid incorect thinking in the future, I would be apreciative.
:D And please feel free to recomend better (or just alternate) ways of handling
this. Thanks!!!
BTW, in answer to the commented question,
my %params = @_ || (); # what if it's a ref, does this DWIM?
which has since been removed, no, apparently it does not. Although I didn't
really expect it to, man would that be cool! Anywho, thanks to anyone who made
it this far for listening to me ramble! Also, thanks to whomever (Ronald?)
helped explain what I was doing wrong using AUTOLOAD (use vars($AUTOLOAD), not
use AutoLoader - the docs really were _NO_ help [who can I send a doc patch
too?]).
And thanks Uri for hosting the social yesterday, I had fun, even without my dog!
;-}
--------------------------
Sean Quinlan
mailto:[EMAIL PROTECTED]
http://bmerc-www.bu.edu/
"You can discover more about a person in an hour of play than in a year of
conversation" - Plato