and it works just as well if you assign to a hashref rather than a hash.

There is a difference in the return value of Vars().
If you request a hash this is obviously a copy of the param hash of the CGI object.
If you request a a scalar you'll get a hashref, which is a variable tied to the CGI object, where the STORE/FETCH are implemented via the param() method of the CGI object.

The latter has some implications if you ever decide to assign to that hashref. Since the FETCH is implemented with a join("\0", $cgi->param('x')); (for cgilib compatible multi-value parameter handling), assigning refs to the hashref will lead to confusing results (due to the forced stringification on reading):

use CGI; use Data::Dumper; use strict; my $q = CGI->new; $q->param('form', 1 .. 5); my $h = $q->Vars(); $h->{'form'} = [ 4 .. 6 ]; print Dumper($h, $q);

In reply to Re^2: How to cycle through CGI query params? by pKai
in thread How to cycle through CGI query params? by punch_card_don

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.