Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^5: String Search

by Anonymous Monk
on Aug 31, 2009 at 11:01 UTC ( [id://792345]=note: print w/replies, xml ) Need Help??


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

I was saying that if it were JSON or YAML it would have been broken, but since it is neither JSON nor YAML, you are correct that it isn't broken.

Here you go

#!/usr/bin/perl -- use strict; use warnings; my $root_stack = []; my $curr_stack = $root_stack; my @prev_stack; my $data = ""; while(<DATA>){ $data .= $_; next if /^\s*$/; chomp; s/^\s+//; if(/^\s*{\s*$/){ # push @$curr_stack, $_; push @$curr_stack, '{'; push @$curr_stack,[]; push @prev_stack, $curr_stack; $curr_stack = $curr_stack->[-1]; } elsif( /^\s*}\s*$/ ){ $curr_stack = pop @prev_stack; # push @$curr_stack, $_; push @$curr_stack, '}'; } else { if( /:/ ){ if( /^\s*(.+?)(\s\:\s)(.+?)\s*$/ ){ push @$curr_stack, [ $1, $2, $3 ]; } else { push @$curr_stack, [ split /(:)/, $_ ]; } } else { push @$curr_stack, $_; } } # warn "$_\n", Dump($root_stack)," "; # debug } use DDS; print Dump($root_stack); __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 } } }
$ARRAY1 = [ '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' ] ], '}' ], '}' ], '}' ];
Its easy to turn this pattern into hash based object.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2025-07-18 14:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.