Now, below program works.. but I still see some uninitialized values
Here's what I mean. I am running a below code against file that has SIP message, which has various format according to what message and what situation. When I run below code against entire file, it works but exception of some areas where I don't get my value initialized and I suspect that when it goes through line (14-16), it doesn't find the match? and it skips out as I see error message
Use of uninitialized value at ./perl.m line 32, <FH> chunk 1. Use of uninitialized value at ./perl.m line 32, <FH> chunk 1. Use of uninitialized value at ./perl.m line 32, <FH> chunk 894. Use of uninitialized value at ./perl.m line 32, <FH> chunk 896. Use of uninitialized value at ./perl.m line 32, <FH> chunk 898.
but line 17 through 38, it recognize as entire record and process what it needs to.. What am I missing in line 14 through 16 that my regular expression is not matching(I want it to match so that it skips out(next record).
#!/usr/bin/perl -w use strict; my $ncb = $/; my $cbn = $"; $/ = "\n\n"; $" = "\n"; open FH, 'file1' or die "can't open file $!"; my $callid; my $sipm; my %data1 = (); while (<FH>) { chomp; if (m/^###|^\s*$/s) { next ; } m{(^SIP\/2\.0 \d\d\d|^[A-Z]{3,6} ).*(Call-ID: [\S]{25,80})[^ ]+: .*}s; ($sipm,$callid) = ($1,$2); #print "\$sipm is $sipm and \$callid is $callid\n"; push (@{$data1{$callid}}, $sipm); } $/ = $ncb; $" = $cbn; foreach $callid (sort keys %data1) { print "$callid \n", " @{$data1{$callid}}\n"; } close FH;
top portion of file1 with line number printed out for identification
14 $ 15 ### sendto xxx.xxx.xxx.xxx7:5060 679 bytes @ Wed Feb 7 14:22: +22 2007$ 16 $ 17 SIP/2.0 200 OK^M$ 18 Via: SIP/2.0/UDP xxx.xxx.xxx.xxx7:5060;branch=xxxxxxxxxxxxxxxx +xxxxxxx;received=xxx.xxx.xxx.xxx7^M$ 19 From: sip:1223456679@xxx.xxx.xxx.xxx7;tag=xxxxxxxxx--116851850 +4^M$ 20 To: sip:18000003333@xxx.xxx.xxx.xxx;tag=ccid-306500088-1-2020^ +M$ 21 Allow: ACK,BYE,CANCEL,INVITE,OPTIONS^M$ 22 Call-ID: Something--662631336@xxx.xxx.xxx.xxx7^M$ 23 CSeq: 1 INVITE^M$ 24 Contact: <sip:xxx.xxx.xxx.xxx:5130>^M$ 25 26 Content-Length: 201^M$ 27 Content-Type: application/sdp^M$ 28 ^M$ 29 v=0^M$ 30 o=50053 306500088 306500088 IN IP4 xx.xx.xx.xx^M$ 31 s=SIP Call^M$ 32 c=IN IP4 xx.xx.xx.xx^M$ 33 t=0 0^M$ 34 m=audio 53776 RTP/AVP 0 11^M$ 35 a=rtpmap:0 PCMU/8000^M$ 36 a=rtpmap:101 telephone-event/8000^M$ 37 a=fmtp:101 0-11^M$ 38 $

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

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.