I love your solution:

my %args; if (ref $_[0] eq "HASH") { %args = %{$_[0]}; } else { @args{qw(flags img name big gallery page caption num)} = @_; }

But one of the things I left out so as to keep the code concise was the use of default values to apply to the locals in the even the caller didn't pass them in. This is why I used the looping mechanism that I did. Rather than specifying each line precisely, which worked, I wrote a loop for brevity and attempted elegance. The solution above is what the doctor (or grandfather) ordered. So, let's revisit my other original objective again and replace what i took out:

$defaults = { flags => 0x8001, img => "/path/file.jpg", ... }; for (qw( flags img name big gallery page caption num ) ) { $$_ = $opts->{$_} || $defaults->{$_}; }

We know why this doesn't work now, but how can I apply defaults from a default hash for those values not passed in using the new method (to me) shown above?


In reply to Re^2: these aren't locals, but they seem to act like it by argv
in thread these aren't locals, but they seem to act like it by argv

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.