<?xml version="1.0" encoding="windows-1252"?>
<node id="793163" title="Re: String Search" created="2009-09-03 08:18:20" updated="2009-09-03 08:18:20">
<type id="11">
note</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
code , creates an array of hashrefs
&lt;readmore&gt;&lt;C&gt;
#!/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(&lt;DATA&gt;){
        next if /^\s*$/;

        s/\s+$//g;
        s/^\s+//g;

DEBUG&amp;&amp; warn "&gt;&gt; $_ \n";

        if(/^{$/){
            push @$curr_stack,[];
            push @prev_stack, $curr_stack;
            $curr_stack = $curr_stack-&gt;[-1];

DEBUG&amp;&amp; warn '{{{ @prev_stack == ' , 0 + @prev_stack;

        } elsif( /^}$/ ){

            $curr_stack = pop @prev_stack;
DEBUG&amp;&amp; warn '}}} @prev_stack == ' , 0 + @prev_stack;

            if( not @prev_stack ){
# ['CME20CP6.CallDataRecord.uMTSGSMPLMNCallDataRecord' =&gt; [...] ]
# push @obj, hashbytwo($curr_stack);
                push @obj, hashbytwo($curr_stack-&gt;[-1]); #[...]
            }

        } else {
            if( / : /  and /^\s*(.+?)(\s\:\s)(.+?)\s*$/ ){
                push @$curr_stack, $1, $3 ;
            } else {
                push @$curr_stack, $_;
            }
        }
    }

    use Data::Dumper;
    print "\n",Data::Dumper-&gt;new([@obj])
    -&gt;Indent(1)-&gt;Sortkeys(1)-&gt;Dump,"\n";

    
    print "Number of CDRs ", scalar(@obj),"\n";

    printf "%s,%s,%s\n",#&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;#
$_-&gt;{sCFChargingOutput}{callIdentificationNumber},#&lt;#
$_-&gt;{sCFChargingOutput}{exchangeIdentity},#&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;#
$_-&gt;{sCFChargingOutput}{gSMCallReferenceNumber},#&lt;&lt;&lt;#
        for @obj;#&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;#

    seek DATA, $tell,0;
}


sub hashbytwo {
    my $h = shift;
    my %n;
    for( my $ix = 0; $ix &lt; $#$h; $ix += 2 ){
#DEBUG&amp;&amp; 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
        }
    }
}
&lt;/c&gt;&lt;/readmore&gt;

output
&lt;readmore &gt;
&lt;C&gt;
$VAR1 = {
  'eventModule' =&gt; {
    'iNServiceDataEventModule' =&gt; {
      'chargePartySingle' =&gt; '\'aPartyToBeCharged (0)\'',
      'genericChargingDigits' =&gt; {
        '[0]' =&gt; '\'2000\'H',
        '[10]' =&gt; '\'72000000000000000000000000\'H',
        '[11]' =&gt; '\'730000000000000000041F\'H',
        '[12]' =&gt; '\'7400000000\'H',
        '[13]' =&gt; '\'3502\'H',
        '[1]' =&gt; '\'011351\'H',
        '[2]' =&gt; '\'223A941400\'H',
        '[3]' =&gt; '\'233A940209\'H',
        '[4]' =&gt; '\'043A2000\'H',
        '[5]' =&gt; '\'0542\'H',
        '[6]' =&gt; '\'2600\'H',
        '[7]' =&gt; '\'2700\'H',
        '[8]' =&gt; '\'080290701391620122\'H',
        '[9]' =&gt; '\'2A02\'H'
      },
      'genericChargingNumbers' =&gt; {
        '[0]' =&gt; '\'0003136985138324\'H',
        '[1]' =&gt; '\'010413198935930920\'H',
        '[2]' =&gt; '\'0203136985138324\'H',
        '[3]' =&gt; '\'038290905893701402\'H',
        '[4]' =&gt; '\'0B000002000000\'H'
      },
      'serviceFeatureCode' =&gt; '\'0002\'H',
      'timeForEvent' =&gt; '\'131A01\'H'
    }
  },
  'sCFChargingOutput' =&gt; {
    'callIdentificationNumber' =&gt; '\'6CBFD7\'H',
    'date' =&gt; '\'1409071F\'H',
    'exchangeIdentity' =&gt; '"DWLCCN6"',
    'gSMCallReferenceNumber' =&gt; '\'9103770001\'H',
    'recordSequenceNumber' =&gt; '\'39D42E\'H',
    'switchIdentity' =&gt; '\'0001\'H'
  }
};
$VAR2 = {
  'eventModule' =&gt; {
    'iNServiceDataEventModule' =&gt; {
      'chargePartySingle' =&gt; '\'bPartyToBeCharged (1)\'',
      'genericChargingDigits' =&gt; {
        '[0]' =&gt; '\'2002\'H',
        '[10]' =&gt; '\'72000000000000000000000000\'H',
        '[11]' =&gt; '\'730000000000000000001F\'H',
        '[12]' =&gt; '\'3500\'H',
        '[1]' =&gt; '\'010359\'H',
        '[2]' =&gt; '\'023A8207\'H',
        '[3]' =&gt; '\'033A8207\'H',
        '[4]' =&gt; '\'043A0000\'H',
        '[5]' =&gt; '\'0506\'H',
        '[6]' =&gt; '\'2600\'H',
        '[7]' =&gt; '\'2704\'H',
        '[8]' =&gt; '\'080290701391622322\'H',
        '[9]' =&gt; '\'2A02\'H'
      },
      'genericChargingNumbers' =&gt; {
        '[0]' =&gt; '\'0003138935167173\'H',
        '[1]' =&gt; '\'028210850000\'H',
        '[2]' =&gt; '\'0303138935167173\'H',
        '[3]' =&gt; '\'06041319\'H'
      },
      'serviceFeatureCode' =&gt; '\'0002\'H',
      'timeForEvent' =&gt; '\'131A20\'H'
    }
  },
  'sCFChargingOutput' =&gt; {
    'callIdentificationNumber' =&gt; '\'6CC99C\'H',
    'date' =&gt; '\'1409071F\'H',
    'exchangeIdentity' =&gt; '"DWLCCN6"',
    'recordSequenceNumber' =&gt; '\'39D42F\'H',
    'switchIdentity' =&gt; '\'0001\'H'
  }
};

Number of CDRs 2
'6CBFD7'H,"DWLCCN6",'9103770001'H
Use of uninitialized value in printf at test.pl line 65, &lt;DATA&gt; line 89.
'6CC99C'H,"DWLCCN6",
&lt;/c&gt;&lt;/readmore&gt;</field>
<field name="root_node">
792326</field>
<field name="parent_node">
792326</field>
<field name="reputation">
1</field>
</data>
</node>
