Explain to me why this wouldn't work:
sub exampl {
my %p = @_;
my @data = UNIVESAL::isa($p{data}, 'ARRAY')
? @{$p{data}}
: ( $p{data} );
foreach my $datum (@data)
{
return if $p{required} && !$datum;
# Do stuff that references $datum
}
return 1; # Everything is OK
}
The point here is that you're stuck in the mode of "I have to reference things the same way". Much better is to say "I have an array of stuff. Let's work with that array." Remember - You used to call it $p{data} because it was a member of that hash. Now, it's not. So, don't call it that. Embrace the refactoring goodness.
------ We are the carpenters and bricklayers of the Information Age. Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement. Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified. |