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?
In reply to Need Help Refactoring Method Calls by jffry
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |