Re: dereferencing



Playing around with this, indeed, proves it can be done:

#!/usr/bin/perl
use strict;
use warnings;
use Data::Alias;
my $hashref = { a => 5, b => 8};
alias my %hash = %{$hashref};
print $hash{a} , "\n";

prints 5. (And \%hash == $hashref evaluates true.)

I knew that Data::Alias existed -- it's mentioned in Perl Best Practices -- but at least to me, the documentation seemed to imply that it couldn't do this, or that it would act like "many scalar assignments in parallel".

Thanks!

On Oct 29, 2007, at 5:33 PM, Paul Johnson wrote:
Perhaps something like Data::Alias, for example, might do the trick.

--
Aaron Priven, aaron@xxxxxxxxxx, http://www.priven.com/aaron


.



Relevant Pages

  • Re: passing array reference from one perl script to another perl scirpt
    ... use strict; ... use warnings; ... Program2: (receiving hash reference) ... passing array reference from one perl script to another ...
    (perl.beginners)
  • Re: counting words in a file
    ... > No warnings? ... fast as the program runs on the pda (400mhz x-scale 32mb ram), ... you have a hash of words and their count now. ... > that there appears to be only one word Melville used exactly once? ...
    (comp.lang.perl.misc)
  • Re: counting words in a file
    ... > No warnings? ... fast as the program runs on the pda (400mhz x-scale 32mb ram), ... you have a hash of words and their count now. ... > that there appears to be only one word Melville used exactly once? ...
    (comp.lang.perl.misc)
  • Re: comparing a 2 hash of hashes
    ... My problem is that I would like to compare 2 hash of hashes. ... it seems that each cell has ... $ cat gold-standard.txt ... that I misunderstood why you expected the warnings. ...
    (comp.lang.perl.misc)
  • Re: Printing an Array: Formatting Problem
    ... as key for the hash. ... use strict; ... use warnings; ... Do you care at all about invalid IP addresses? ...
    (comp.lang.perl.misc)