in reply to Re: Re: Surpised by foreach iterator limitation
in thread Surpised by foreach iterator limitation
Explain to me why this wouldn't work:
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."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 }
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re3: Surpised by foreach limitation
by shotgunefx (Parson) on Apr 08, 2003 at 18:03 UTC |
In Section
Seekers of Perl Wisdom