koaps has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys,
I'm trying to figure out how to dereference something and I can't get the syntax right.
I have a hash reference I'm filling up with username => @logins basically.

my $matches = {}; $matches->{$user} = [grep {/$user/} @logins];
What I can't seem to get right:
foreach my $user (keys %$matches) { print "$user: ". @{$matches->{$user}} . "\n"; }
Gives me:
user1: 1 user2: 0 user3: 0
It should be more like:
user1: Thu Nov 5 18:49:39 2009 [pid x] [user1] OK LOGIN: Client "127. +0.0.1"
How can I get at the array values in the hashref?

Replies are listed 'Best First'.
Re: Help with a dereference
by Anonymous Monk on Nov 06, 2009 at 19:39 UTC
    scalar context, see perlop
    my @stuff = 1 .. 10; print "dot aka period ". @stuff ."\n"; print "comma ", @stuff ,"\n"; __END__ dot aka period 10 comma 12345678910
      Or even direct string interpolation:
      >perl -wMstrict -le "my @stuff = 1 .. 10; print qq{interpolate @stuff here}; " interpolate 1 2 3 4 5 6 7 8 9 10 here
      Update: Using something closer to the code of the OP:
      >perl -wMstrict -le "my $stuff = {}; my $this = 'here'; $stuff->{$this} = [ qw(foo bar baz) ]; print qq{interpolate @{ $stuff->{$this} } here}; " interpolate foo bar baz here

        Thanks guys,

        I mainly was checking that @{$matches->{$user}} was correct, because I actually was using it in an if statement then iterating through it to print to a filehandle.

        I was using print to test that the array looked right and the periods were hanging me up.

        Thanks again.

      thanks