Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: hash referencing...best approach?

by tcf22 (Priest)
on Nov 24, 2003 at 20:04 UTC ( [id://309658]=note: print w/replies, xml ) Need Help??


in reply to hash referencing...best approach?

You are referencing the hash to $s, which is local.
You could pass in a ref to $sid, or return the hash ref. I prefer the later.

Also you are assigning a hash ref to a hash, which is probably what you don't want. {} creates a hash reference, () are used to define a hash.

One of these 2 options should work:
#Passing scalar ref sub make_session { my ($u,$a,$s)=@_; my $session_hash={ user=>$u, dept=>$a }; $$s=$session_hash; } &make_session($user,$dept,\$sid);
or
#Returning hash ref sub make_session { my ($u,$a)=@_; $session_hash={ user=>$u, dept=>$a }; return $session_hash; } $sid = &make_session($user,$dept);
Update: Changed %session_hash to $session_hash after realizing that you are creating a hash ref by using {}.

- Tom

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://309658]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-03-19 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found