Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: String Search

by Anonymous Monk
on Sep 03, 2009 at 12:18 UTC ( #793163=note: print w/ replies, xml ) Need Help??


in reply to String Search

code , creates an array of hashrefs

#!/usr/bin/perl -- use strict; use warnings; use constant qw{ DEBUG 0 }; { my $tell = tell DATA; my $curr_stack = []; my @prev_stack; my @obj; while(<DATA>){ next if /^\s*$/; s/\s+$//g; s/^\s+//g; DEBUG&& warn ">> $_ \n"; if(/^{$/){ push @$curr_stack,[]; push @prev_stack, $curr_stack; $curr_stack = $curr_stack->[-1]; DEBUG&& warn '{{{ @prev_stack == ' , 0 + @prev_stack; } elsif( /^}$/ ){ $curr_stack = pop @prev_stack; DEBUG&& warn '}}} @prev_stack == ' , 0 + @prev_stack; if( not @prev_stack ){ # ['CME20CP6.CallDataRecord.uMTSGSMPLMNCallDataRecord' => [...] ] # push @obj, hashbytwo($curr_stack); push @obj, hashbytwo($curr_stack->[-1]); #[...] } } else { if( / : / and /^\s*(.+?)(\s\:\s)(.+?)\s*$/ ){ push @$curr_stack, $1, $3 ; } else { push @$curr_stack, $_; } } } use Data::Dumper; print "\n",Data::Dumper->new([@obj]) ->Indent(1)->Sortkeys(1)->Dump,"\n"; print "Number of CDRs ", scalar(@obj),"\n"; printf "%s,%s,%s\n",#<<<<<<<<<<<<<<<<<<<<<<<<<<<# $_->{sCFChargingOutput}{callIdentificationNumber},#<# $_->{sCFChargingOutput}{exchangeIdentity},#<<<<<<<<<# $_->{sCFChargingOutput}{gSMCallReferenceNumber},#<<<# for @obj;#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<# seek DATA, $tell,0; } sub hashbytwo { my $h = shift; my %n; for( my $ix = 0; $ix < $#$h; $ix += 2 ){ #DEBUG&& warn " ref(", ref($$h[$ix+1] ), ") ", $$h[$ix+1] , " "; $n{$$h[$ix]}= ref $$h[$ix+1] ? hashbytwo($$h[$ix+1]): $$h[$ix+ +1] ; } return \%n; } __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 } } }
output
$VAR1 = { 'eventModule' => { 'iNServiceDataEventModule' => { 'chargePartySingle' => '\'aPartyToBeCharged (0)\'', 'genericChargingDigits' => { '[0]' => '\'2000\'H', '[10]' => '\'72000000000000000000000000\'H', '[11]' => '\'730000000000000000041F\'H', '[12]' => '\'7400000000\'H', '[13]' => '\'3502\'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' }, 'genericChargingNumbers' => { '[0]' => '\'0003136985138324\'H', '[1]' => '\'010413198935930920\'H', '[2]' => '\'0203136985138324\'H', '[3]' => '\'038290905893701402\'H', '[4]' => '\'0B000002000000\'H' }, 'serviceFeatureCode' => '\'0002\'H', 'timeForEvent' => '\'131A01\'H' } }, 'sCFChargingOutput' => { 'callIdentificationNumber' => '\'6CBFD7\'H', 'date' => '\'1409071F\'H', 'exchangeIdentity' => '"DWLCCN6"', 'gSMCallReferenceNumber' => '\'9103770001\'H', 'recordSequenceNumber' => '\'39D42E\'H', 'switchIdentity' => '\'0001\'H' } }; $VAR2 = { 'eventModule' => { 'iNServiceDataEventModule' => { 'chargePartySingle' => '\'bPartyToBeCharged (1)\'', 'genericChargingDigits' => { '[0]' => '\'2002\'H', '[10]' => '\'72000000000000000000000000\'H', '[11]' => '\'730000000000000000001F\'H', '[12]' => '\'3500\'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' }, 'genericChargingNumbers' => { '[0]' => '\'0003138935167173\'H', '[1]' => '\'028210850000\'H', '[2]' => '\'0303138935167173\'H', '[3]' => '\'06041319\'H' }, 'serviceFeatureCode' => '\'0002\'H', 'timeForEvent' => '\'131A20\'H' } }, 'sCFChargingOutput' => { 'callIdentificationNumber' => '\'6CC99C\'H', 'date' => '\'1409071F\'H', 'exchangeIdentity' => '"DWLCCN6"', 'recordSequenceNumber' => '\'39D42F\'H', 'switchIdentity' => '\'0001\'H' } }; Number of CDRs 2 '6CBFD7'H,"DWLCCN6",'9103770001'H Use of uninitialized value in printf at test.pl line 65, <DATA> line 8 +9. '6CC99C'H,"DWLCCN6",


Comment on Re: String Search
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://793163]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2015-07-02 01:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls