On Friday 15 April 2005 11:57 am, Juerd wrote:
> Paul Seamons skribis 2005-04-15 11:50 (-0600):
> > my %h = <a 1 b 2 c 3>;
> > {
> >   temp %h{$_} ++ for %h.keys;
> Just make that two lines. Is that so bad?
>     temp %h;
>     %h.values ++;

For the given example, your code fits perfectly.  A more common case I have 
had to deal with is more like this:

my %h = <a 1 b 2 c 3>
my %other = <a one b two>;
  temp %h{$_} = %other{$_} for %other.keys;

Ideally that example would print
a    one
b    two
c    3

It isn't possible any more to do something like
  temp %h = (%h, %other);
because that second %h is now hidden from scope (I forget which Apocalypse or 
mail thread I saw it in).  Plus for huge hashes it just isn't very efficient.

I'd like to temporarily put the values of one hash into another (without 
wiping out all of the modfied hashes values like "temp %h" would do), run 
some code, leave scope and have the modified hash go back to normal.  In 
perl5 I've had to implement that programatically by saving existing values 
into yet another hash - running the code - putting them back.  It works but 
there is all sorts of issues with defined vs exists.

So yes - your code fits the limited example I gave.  But I'd still like the 
other item to work.


Reply via email to