in reply to Re^3: String Search
in thread String Search

Hi, I am giving you the original data and programme.

data: ----- CME20CP6.CallDataRecord.uMTSGSMPLMNCallDataRecord { sCFChargingOutput { callIdentificationNumber : '6CBFD7'H exchangeIdentity : "DWLCCN6" gSMCallReferenceNumber : '9103770001'H switchIdentity : '0001'H recordSequenceNumber : '39D42E'H date : '1409071F'H } eventModule { iNServiceDataEventModule { chargePartySingle : 'aPartyToBeCharged (0)' genericChargingDigits { [0] : '2000'H [1] : '011351'H [2] : '223A941400'H [3] : '233A940209'H [4] : '043A2000'H [5] : '0542'H [6] : '2600'H [7] : '2700'H [8] : '080290701391620122'H [9] : '2A02'H [10] : '72000000000000000000000000'H [11] : '730000000000000000041F'H [12] : '7400000000'H [13] : '3502'H } genericChargingNumbers { [0] : '0003136985138324'H [1] : '010413198935930920'H [2] : '0203136985138324'H [3] : '038290905893701402'H [4] : '0B000002000000'H } serviceFeatureCode : '0002'H timeForEvent : '131A01'H } } } CME20CP6.CallDataRecord.uMTSGSMPLMNCallDataRecord { sCFChargingOutput { callIdentificationNumber : '6CC99C'H exchangeIdentity : "DWLCCN6" switchIdentity : '0001'H recordSequenceNumber : '39D42F'H date : '1409071F'H } eventModule { iNServiceDataEventModule { chargePartySingle : 'bPartyToBeCharged (1)' genericChargingDigits { [0] : '2002'H [1] : '010359'H [2] : '023A8207'H [3] : '033A8207'H [4] : '043A0000'H [5] : '0506'H [6] : '2600'H [7] : '2704'H [8] : '080290701391622322'H [9] : '2A02'H [10] : '72000000000000000000000000'H [11] : '730000000000000000001F'H [12] : '3500'H } genericChargingNumbers { [0] : '0003138935167173'H [1] : '028210850000'H [2] : '0303138935167173'H [3] : '06041319'H } serviceFeatureCode : '0002'H timeForEvent : '131A20'H } } } .......... The code I had written : ------------------------- #use strict; use IO::File; open (INPUT_FILE, $ARGV[0]) || die "cant open file\n"; my @body = <INPUT_FILE>; my $count= 0; my $output_file_name="Decoded_cdr.txt"; my $restartDuringCall = ","; open(OUT_FILE,">$output_file_name"); #print $body[6]; $no_of_lines=scalar(@body); $cntr = 1; $no_of_cdrs = 0; for ($i=0; $i < $no_of_lines; $i++) { $variable = $body[$i]; if ($variable =~ "CME20CP6") { $no_of_cdrs = $cntr + 1; } } #print "No of CDRS : $no_of_cdrs \n"; for ( $i = 0 ; $i < $no_of_lines ; $i++) { $variable = $body[$i]; if ( $variable =~ /callIdentificationNumber/) { @tmp_var = split(/([:\'])/,$variable); $callIdentificationNumber = $tmp_var[4]; #print "$callIdentificationNumber,"; } if ($variable =~ m/exchangeIdentity/ ) { @tmp_var = split(/([:\"])/,$variable); $exchangeIdentity = $tmp_var[4]; #print "$exchangeIdentity,"; } if ($variable =~ m/gSMCallReferenceNumber/ ) { @tmp_var = split(/([:\'])/,$variable); $gSMCallReferenceNumber = $tmp_var[4]; #print "$gSMCallReferenceNumber,"; } if ($variable =~ m/restartDuringCall/ ) { @tmp_var = split(/([:\'])/,$variable); my $restartDuringCall = $tmp_var[4]; #print "$restartDuringCall,"; } if ($variable =~ m/restartDuringOutputIndicator/ ) { @tmp_var = split(/([:\'])/,$variable); $restartDuringOutputIndicator = $tmp_var[4]; } if ($variable =~ m/lastPartialOutput/ ) { @tmp_var = split(/([:\'])/,$variable); $lastPartialOutput = $tmp_var[4]; } if ($variable =~ m/partialOutputRecNum/ ) { @tmp_var = split(/([:\'])/,$variable); $partialOutputRecNum = $tmp_var[4]; } if ($variable =~ m/switchIdentity/ ) { @tmp_var = split(/([:\'])/,$variable); $switchIdentity = $tmp_var[4]; } if ($variable =~ m/disconnectionDueToSystemRecovery/ ) { @tmp_var = split(/([:\'])/,$variable); $disconnectionDueToSystemRecovery = $tmp_var[4]; } if ($variable =~ m/forloppDuringOutputIndicator/ ) { @tmp_var = split(/([:\'])/,$variable); $forloppDuringOutputIndicator = $tmp_var[4]; } if ($variable =~ m/forloppReleaseDuringCall/ ) { @tmp_var = split(/([:\'])/,$variable); $forloppReleaseDuringCall = $tmp_var[4]; } if ($variable =~ m/recordSequenceNumber/ ) { @tmp_var = split(/([:\'])/,$variable); $recordSequenceNumber = $tmp_var[4]; } if ($variable =~ m/incompleteCallDataIndicator/ ) { @tmp_var = split(/([:\'])/,$variable); $incompleteCallDataIndicator = $tmp_var[4]; } if ($variable =~ m/mSCAddress/ ) { @tmp_var = split(/([:\'])/,$variable); $mSCAddress = $tmp_var[4]; } if ($variable =~ m/date/ ) { @tmp_var = split(/([:\'])/,$variable); $date = $tmp_var[4]; } if ($variable =~ m/outputType/ ) { @tmp_var = split(/([:\'])/,$variable); $outputType = $tmp_var[4]; } #print "$callIdentificationNumber,$exchangeIdentity,$gSMCallRefere +nceNumber"; } print "\n"; close (INPUT_FILE); close OUT_FILE; ---------------------------------------------

The output generates : The output not generating the required output.. This is like : value1,value2... Please help..

Replies are listed 'Best First'.
Re^5: String Search
by Marshall (Canon) on Aug 31, 2009 at 11:33 UTC
    So you have a "sort of human readable" text dump of a CDR Database (telephone call records, or Call Data Recording). You are trying to generate a report from this text dump.

    First, I would say: WRONG approach. This CDR database is extremely likely to be a pretty darn fancy thing that understands SQL queries (probability approaches 1.0).

    Perl is fantastic at DB and SQL stuff. That is the right approach for what you need. Forget this text dump of a complex OO DB! Start thinking about how to connect to this server with the CDR records and what questions you would like to ask it. Perl can connect to SQL DB's and get that job done extremely well!

    Go do some homework about (a) what you want to know, (b) simple SQL syntax, (c) run some queries from your terminal at the UI level, then come back and ask about how Perl can make magic happen with that process.

    Summary:
    WRONG: using text dump of OO DB.
    RIGHT: talk to the DB server.

      Hi Marshall, Thanks a lot for your king help. But I have already thouht that approach also. The logic I had thought as Find the data and insert the data into table But some problem will arise for that. 1. The database we are using as Oracle Database. 2. The table where I will insert the data is very big table and there will lacs of files where every file may be have 1000 records , so it will take hugh time to load into database. 3. Better approach I think SQL*Loader. Because perl is very useful to format the data into "," separated file and SQL*Loader always very fast to load data into table. Your Help is reqired here

        Great! We are making some progress!
        1. You do have a professional grade Database.
        2. It can definitely do SQL stuff.

        From your description of "lots of files with up to 1,000 records", I figure we are talking about a lot less than 1 million records.

        I don't understand the "problem". You are getting this stuff from an Oracle DB and it is going into another Oracle DB. Oracle has tools that can do this very efficiently. One thing to think about is that: what the heck, even if this takes 12 hours, you would already be done in the time its taken to discuss this on Monks!

        As far as generating a CSV, Comma Separated Value file goes, your Oracle DB can do that itself. The command for this report will probably be complex, but the DB can do it. But even more efficient will be the merging tools that Oracle provides, or so I suspect. And I think there are some very good reasons for suspecting that.

        At this point, I would ask any Monk who knows about Oracle to give advice. Perl may play a role in this DB merge, but I don't think that it will be the "star" player.

Re^5: String Search
by Anonymous Monk on Aug 31, 2009 at 10:38 UTC
Re^5: String Search
by kallol.chakra (Initiate) on Aug 31, 2009 at 10:20 UTC

    The print part I have commented..

      I think you're having problems with the way you're parsing it, instead of putting all contents in a huge array that will crash your memory if crd logs are big enough. the standar approach is
      my $number_of_crds = 0; while(<INPUT_FILE>) { if ( $_ =~ /CME20CP6/) { $number_of_crds++; } ... ... }
      close(INPUT_FILE); and you should be able to use one while to do all parsing and extract the values with regular expressions for example, inside the first while
      if ( $_ =~ /callIdentificationNumber\s+:\s+\'(.+)\') { print "callIndentificationNumber: $1\n"; }
      In this case the regular expression is extended to extract the values inside quote symbols You're using global variables, I'd recomend you to use strict mode "use strict;" it will force you to define the scope of the variables, having global variables creates lots of parsing errors, i.e.: first record has a gSMCallReferenceNumber node so it loads variable $callIdentificationNumber with that value, if the following record ( or any of the following cdr records) don't have gSMCallReferenceNumber node and as $callIndentificationNumber is global you will have variable loaded with previous value.

        Hi,

        This is ok. I will surely use it. But main problem is that I can not use else for any "if". If I use else then it will work for every row in the data. Please help me..

        Regards