in reply to Re^3: multiple values per key
in thread multiple values per key

One more question, why can't I do this??
38 foreach $callid (sort keys %data1) { 39 # print " @{$data1{$callid}}\n"; 40 my $fields = join (/\s*/, @{$data1{$callid}}); 41 print "$fields\n"; 42 } 43 close FH;
With print statement alone(which is commented out), it works as designed(with next two lines commented out)
~/script/perl/temp@myserver1 >./program file1 There were 0 which could not detect INVITE 100 180 200 ACK BYE 200 INVITE 100 180 200 180 200 ACK BYE 200
but when I run as above (with print statement # out with next two open with join), I get below
There were 0 which could not detect Use of uninitialized value at ./perl.m2 line 40, <FH> chunk 32. INVITE 1100118012001ACK 1BYE 1200 Use of uninitialized value at ./perl.m2 line 40, <FH> chunk 32. INVITE 110011801200 Use of uninitialized value at ./perl.m2 line 40, <FH> chunk 32. 18012001ACK 1BYE 1200

Replies are listed 'Best First'.
Re^5: multiple values per key
by GrandFather (Saint) on Jul 24, 2007 at 03:37 UTC

    Read the join docs.


    DWIM is Perl's answer to Gödel
      I still do not get it, @{$data1{$callid}} contains something like
      INVITE 100 180 200 INVITE 503 ACK
      so when I do below I expected results to be
      INVITE100180200
      INVITE503ACK
      But instead I get scalar values in return.. why??
      foreach $callid (sort keys %data1) { my @fields = join('', split(/[ +\t]/, @{$data1{$callid}})); print "@fields\n"; }
        I was able to get it done using below.. Is this because reference is scalar?
        foreach $callid (sort keys %data1) { my @fields = @{$data1{$callid}}; for my $element (@fields) { $element =~ s/\s+//g; print "$element"; } print "\n"; }