Maybe I don't understand the question, but it appears to me that you want the list of REQUIRED_FIELDS minus the ones that are in your $a which is a reference to an array?

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

In reply to Re: altering array in foreach during execution? by Marshall
in thread altering array in foreach during execution? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.