[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Dereferencing hashes



At 12:47 AM 10/12/00, Sveinbjorn Thordarson wrote:
>Hi there
>
>I'm working with Net::Hotline, and I need to know how to dereference
>hashes.
>
>$hlc->userlist returns a reference to a hash.  How would I go about
>printing every element of the hash?
>

# De-reference to a new hash:
%new_hash = %{ $hlc->userlist };

# The canonical way to print out the keys and values of a hash:
foreach $key (keys %new_hash) {
    print "$key: $new_hash{$key}\n";
}

# Or do without the new hash variable
for ( ($key, $value) = each %{ $hlc->userlist } )
    print "$key: $value\n";
}

>I have no idea how dereferencing in Perl works, and from what I read in
>programming perl, it's very, very silly....and accessing actual values
>is hard work.

Start simply. Avoid thinking you need to use complex data structures, 
just because they're possible.

Programming Perl is very densely packed. The third edition has better 
explanations and examples than previous editions. But to learn about 
something like references from it, take it a page at a time, try lots 
of experiments, try explaining it to someone else, but go slowly! 
Perl has great depth, and you won't get the complex stuff unless 
you've really worked with the simpler constructs. Don't read the 
whole chapter and expect to start doing what's discussed at the end.

HTH

1;



- Bruce

__Bruce_Van_Allen____831__429_1688__
__PO_Box_839__Santa_Cruz_CA__95061__


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org