Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^3: hash parameter question

by jarich (Curate)
on Dec 13, 2005 at 02:43 UTC ( #516217=note: print w/replies, xml ) Need Help??

in reply to Re^2: hash parameter question
in thread hash parameter question

Nope. $_ contains a string. A key from %users; which is presumably a username. Your suggestion will therefore not work.

Had PerlHeathen written:

foreach(values %users) { my %user=$_; my $pw=getpwnam($user{uname}); my $homedir=$pw->dir; }

(note the use of values) then $_ would be a reference to a hash and then your solution would make the code work.

For example:

foreach(values %users) { my %user=%$_; my $pw=getpwnam($user{uname}); my $homedir=$pw->dir; }

It is likely that this is what PerlHeathen was trying to write in the first place.


Replies are listed 'Best First'.
Re^4: hash parameter question
by PerlHeathen (Initiate) on Dec 14, 2005 at 19:12 UTC
    Thank you all. This is what I was looking for; I need both suggestions -- pass by reference & use values(%users) instead.

    thanks again!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://516217]
[Corion]: Meh. I think I have now the parts down that I want from a simple Javascript frontend for single-page- applications with a aPerl backend. But it seems that all Javascript templating modules either don't support two-way binding (which would be nice) or ...
[Corion]: ... don't support server-side precompilation (which means the client has to compile all templates to Javascript themselves), or are giant frameworks that expect to do everything (which is not what I want)
[Corion]: I feel that there is a talk somewhere in there, either about the structure and parts, or how I used several parts to get a complete whole.
[Corion]: Maybe I can still find something that is compatible with handlebars.js (which has JS precompilation) but allows for two-way data binding (which is great for the UI)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2017-03-30 07:47 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (355 votes). Check out past polls.