Ah - Thanks for pointing out that this could be done that way.

This works (Plagerized code):

use strict; use Data::Dumper; sub for_pairs (&@) { unless (@_&1) { warn "Odd"; push @_, undef; goto \&for_pairs; } my $code = shift; # Localise $a and $b # (borrowed from List-MoreUtils) my ($caller_a, $caller_b) = do { my $pkg = caller(); no strict 'refs'; \*{$pkg.'::a'}, \*{$pkg.'::b'}; }; local(*$caller_a, *$caller_b); no warnings; if (wantarray) { # list context map {(*$caller_a, *$caller_b) = \splice(@_, 0, 2); $code->()} +(1..@_/2) } elsif (defined wantarray) { # scalar context # count number of returned elements my $i=0; # force list context with =()= for the count $i +=()= $code->() while (*$caller_a, *$caller_b) = \splice(@_ +, 0, 2); $i } else { # void context $code->() while (*$caller_a, *$caller_b) = \splice(@_, 0, 2); } } #--------------------------------------------- my $Incoming = 'uno="one" Blah blah dos="two" * More Noise* tres="thr +ee"'; my %att= (PREEXISTING=>"val1", ANOTHER=>"Val2"); for_pairs { $att{$a} = $b } $Incoming=~m/\b(\w+)="(.+?)"/g; print Dumper \%att;
I don't think I will use it in my current app - I'll stick with the one-liner above.
For future apps with access to Modules, It would be better to go with an established module that provides the function.
Anyway - This has been a fun exercise. Thank you.

     Syntactic sugar causes cancer of the semicolon.        --Alan Perlis


In reply to Re^4: Pair-wise list access - without temp hash by NetWallah
in thread Pair-wise list access - without temp hash by NetWallah

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.