in reply to altering array in foreach during execution?
I personally would use a different return value, either a list or an array reference as the output rather than pervert (grossly modify) the input to such an extent that it no longer means what it did as the input.
I mean if the input is "here's what I have" and the output is "here's what you didn't have" - those are two very different things.
It looks to me like the output of verify() is of a different "type" or "unit" than the input. I would return a list like I did, or a reference to an array of the "new type".
#!/usr/bin/perl -w use strict; use constant REQUIRED_FIELDS => qw/zero one two three four five six se +ven/; my $a_ref = [qw/three one two/]; my @missing_fields = verify($a_ref); print "missing fields: @missing_fields\n"; sub verify { my $a_ref = shift; my %seen = map{$_ => 1}@$a_ref; return (grep{!$seen{$_}}REQUIRED_FIELDS); } __END__ Prints: missing fields: zero four five six seven
|
|---|