jffry has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to refactor it into one subroutine. The only thing that changes is the @list_var and the My::Class::Child.my @list_var; if (ref $giant_hash{key} eq 'ARRAY') { for (@{ $giant_hash{key} }) { push @list_var, My::Class::Child->new( $_ ); } } else { push @list_var, My::Class::Child->new( $giant_hash{key} ); }
I did this:
But I'm getting a reference violation error that I can't quite understand why.our %giant_hash = Module->whatever(); sub _fill_lists { my ($thing, $thing_ref) = @_; my ($method , $flag); SWITCH: for ($thing) { /XXX/ && do { $method = \&My::Class::XXX->new; last; }; /YYY/ && do { $method = \&My::Class::YYY->new; last; }; /etc/ && do {$and_so_on; last; }; } if (ref $giant_hash{$thing} eq 'ARRAY') { for (@{ $giant_hash{$thing} }) { push @{ $thing_ref }, $method->( $_ ); } } else { push @{ $thing_ref }, $method->( $giant_hash{$thing} ); } }
Nor am I feeling inspired right about now with a decent solution.Can't use string ("XXX") as an ARRAY ref while "strict refs" in use at + ./testme.pl line 76.
Any ideas?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need Help Refactoring Method Calls
by rhesa (Vicar) on Jan 30, 2006 at 00:59 UTC | |
by jffry (Hermit) on Jan 30, 2006 at 17:14 UTC | |
by rhesa (Vicar) on Feb 02, 2006 at 20:37 UTC | |
|
Re: Need Help Refactoring Method Calls
by dragonchild (Archbishop) on Jan 30, 2006 at 03:15 UTC | |
by merlyn (Sage) on Feb 02, 2006 at 17:07 UTC |