I'm just learning Perl (I felt the lure of the dark side after starting with Python :P). Anyways, I'm having a problem with the following short script. I believe the problem is because the value of an associative array must be a scalar (right?), but I want to store a list. Here's the script: --
my %user_dict; #stores {user : info} of all system users my @user_info; #temp list of data from USER_LIST my @online_list; #list of users currently logged in my $user; my $online; my $user_online; open (USER_LIST, 'users') or open(USER_LIST, '/etc/passwd') or die "Couldn't open: $!"; while (<USER_LIST>) { @user_info = split /:/, $_; $user_dict{$user_info[0]} = \@user_info[4,5]; } @online_list = split(' ', `/usr/bin/users`); foreach $user (keys %user_dict) { $online = 0; foreach $user_online (@online_list) { if ($user_online eq $user) { $online = 1; last; } } if ($online) { print "Online text box\n"; } else { print "Offline text box\n"; } print "User Info on $user: $user_dict{$user}\n"; } --
Instead of printing the 5th and 6th
fields of /etc/passwd (homedir + shell), 
it prints "User Info on root: SCALAR(0x8056d08)".

Could someone:
1) Tell me what I'm doing wrong
2) PLEASE comment on *how* I've coded this. 
I want to learn to code Perl write, and shed all the Python-esque techniques I've learned. If you were going to write the above, how would you do it? Should I be declaring all my variables at the top, or should I declare them throughout the program? TIA

In reply to newbie - hash - array? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.