space in variable referencing



Question from a newbie: how to properly use space
when reference to variables, array, hash etc.

please see the code below:
why the first line, second, and third line all output differiently.
thanks.
ciwei

========code below ======
#!/usr/bin/perl

my %ttys =();
open ( WHO, "who|") or die "can;t \n";

while ( <WHO> ){

( $user, $tty ) = split ;
push @{$ttys{ $user}} , $tty;

}

foreach $user ( sort keys %ttys ){

print "first line : $user => @{$ttys {$user}} \n";
print "second line: $user => @ {$ttys { $user}} \n";
print "third line: $user => @{$ttys{$user}} \n";

}

__OUTPUT__
first line : root =>
second line: root => @ { { root}}
third line: root => pts/1 pts/4 pts/6 pts/7 pts/8

.



Relevant Pages

  • RE: Array de-referencing problem
    ... But I guess it's better to use an array reference? ... Conversation: Array de-referencing problem ... The values of a hash can only be scalars! ...
    (perl.beginners)
  • Re: Complex Objects in Perl
    ... > sub-object is made up of a number of different objects and an array of an ... Objects in Perl are implemented as a reference to an anonymous hash. ...
    (comp.lang.perl)
  • Re: complex data structure
    ... reference to an anonymous one-key hash. ... store, just put them in the array: ... stores a reference to an anonymous 4-element array into scalar variable ...
    (comp.lang.perl)
  • Re: Accessing hash of arrays?
    ... I want to archive to hash indexed by the target folder: ... I am not trying to slice an array. ... to be a reference to an array. ...
    (perl.beginners)
  • Re: complex data structure
    ... reference to an anonymous one-key hash. ... store, just put them in the array: ... stores a reference to an anonymous 4-element array into scalar variable ...
    (comp.lang.perl.misc)