convenientstore has asked for the wisdom of the Perl Monks concerning the following question:
So, I wanted to test it by creating below simple file,ttys = ( ); open(WHO, "who|") or die "can't open who: $!"; while (<WHO>) { ($user, $tty) = split; push( @{$ttys{$user}}, $tty ); } foreach $user (sort keys %ttys) { print "$user: @{$ttys{$user}}\n"; } The heart
But when I run it, I get below? is perl cook book wrong ?#!/usr/bin/perl -w use strict; open FH, 'sipfile.m' or die "can't open file $!"; my ($call1, $sipm); my %data1 = ( ); while (<FH>) { if (($call1,$sipm) = /(SIP[0-9]).+ (\d\d\d).+$/) { push ( @{data1{$call1}}, $sipm ); } } foreach $call1 (sort keys %data1) { print "$data1{$call1}\n"; } close FH;
Scalar value @{data1{$call1} better written as ${data1{$call1} at ./pe +rl.m line 12.<br> Type of arg 1 to push must be array (not hash slice) at ./perl.m line +12, near "$sipm )" Execution of ./perl.m aborted due to compilation errors.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: multiple values per key
by GrandFather (Saint) on Jul 20, 2007 at 02:51 UTC | |
by convenientstore (Pilgrim) on Jul 20, 2007 at 13:22 UTC | |
by convenientstore (Pilgrim) on Jul 22, 2007 at 18:44 UTC | |
by GrandFather (Saint) on Jul 22, 2007 at 23:53 UTC | |
by convenientstore (Pilgrim) on Jul 23, 2007 at 01:18 UTC | |
by convenientstore (Pilgrim) on Jul 22, 2007 at 23:18 UTC | |
by convenientstore (Pilgrim) on Jul 24, 2007 at 02:39 UTC | |
by GrandFather (Saint) on Jul 24, 2007 at 03:37 UTC | |
|