Hi Monks, I'm a perl newbie and need help from the experts to extract the value from the text file-1 based on value from text file-2 which is tab separated. The script is to automate my monthly internet usage report. Each customer will have separate report output similar like below.

Sample Output will be:

CUSTOMER NAME: ABC
Device_Code Port Traf_Dir Data_Usage
SWITCH Fa1_0_33 OUT 1.311
SWITCH Fa1_0_33 IN 10.716
SWITCH Fa1_0_35 OUT 50.796
SWITCH Fa1_0_35 IN 7.882

Contents of Text File 1:
200612:ABC
200905:DEF
200212:GHI

Contents of Text File 2:
200612 200612 SWITCH FastEthernet1_0_33 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 4.336 1.311
200612 200612 SWITCH FastEthernet1_0_33 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 35.435 10.716
200612 200612 SWITCH FastEthernet1_0_35 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 167.976 50.796
200612 200612 SWITCH FastEthernet1_0_35 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 26.064 7.882
200612 200612 SWITCH FastEthernet2_0_33 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200612 200612 SWITCH FastEthernet2_0_33 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200612 200612 SWITCH FastEthernet2_0_35 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200612 200612 SWITCH FastEthernet2_0_35 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200905 200905 SWITCH FastEthernet1_0_48 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 3.193 0.965
200905 200905 SWITCH FastEthernet1_0_48 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 41.499 12.549
200905 200905 SWITCH FastEthernet2_0_48 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200905 200905 SWITCH FastEthernet2_0_48 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200212 200212 SWITCH FastEthernet1_0_19 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 3.877 1.172
200212 200212 SWITCH FastEthernet1_0_19 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 0.837 0.253
200212 200212 SWITCH FastEthernet2_0_19 OUT 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000
200212 200212 SWITCH FastEthernet2_0_19 IN 01-Feb-2010_02:00 01-Mar-2010_02:00 -0.000 -0.000

Here's my current code:
#!/usr/bin/perl #use strict; #use warnings; my $cust_file="customer.txt"; my $billing_file="2010.bill"; # '<' means read only open(CUST_DATA,'<', $cust_file) || die("Could not open file!"); #@raw_data=<CUST_DATA>; #Done reading the file - close it while (<CUST_DATA>) { ($CUST_ID,$CUST_NAME) = split(':',$_); $CUST_NAME{$CUST_ID}=$CUST_NAME; if (length($CUST_NAME)>$maxCUST_NAMElength) { $maxCUST_NAMElength=length($CUST_NAME); } } close(CUST_DATA); # '<' means read only open(BILL_DATA,'<', $billing_file) || die("Could not open file!"); @rawbill_data=<BILL_DATA>; close(BILL_DATA);
Im stuck how to extract the data based on the value from first text file. :)
Thanks in advance for your help.

In reply to How to Extract Data from Text file 1 based on the Value from Text file 2 by roborat

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.