File Parsing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sukiu47
    New Member
    • Jul 2007
    • 5

    File Parsing

    I have one text file . I having a problem to read multiple lines in text file

    my Text file
    Code:
    A
    {
    A20 = { { 11, 32, 96, 33, 28 },
    
    { 22, 23, 45, 23, 22 },
    
    { 36, 25, 46, 36, 78 }}
    
    
    
    A25= 100
    
    
    }
    Code I am using ::

    [CODE=perl]
    my @AOH;
    open F,"<$Data" or die $!;

    while(<F>){
    push @AOH, {} if /^A/;
    $AOH[-1]{$1}=$2 if /\s*(\w*)\s*=\s* (.*)\s*/;
    }

    close F;
    print Dumper \@AOH;
    [/CODE]

    Output I am getting

    [CODE=perl]
    $VAR1 = [
    {
    'A20' => '{ { 11, 32, 96, 33, 28 },
    ',
    'A25' => '100'
    }
    ];
    [/CODE]

    Question
    How I can fix "A20" ? Because A20 has 3 string but it is displaying only one
    Last edited by miller; Jul 4 '07, 06:43 AM. Reason: Code Tag and ReFormatting
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    this does not appear to be very useful data:

    'A20' => '{ { 11, 32, 96, 33, 28 },

    a hash of hashes but there is an odd number of elements in the hash. Should that really be an array of hashes of arrays?

    Comment

    • sukiu47
      New Member
      • Jul 2007
      • 5

      #3
      yes in the text file entries, but how u can handle A20 multiple lines inputs

      Comment

      • sukiu47
        New Member
        • Jul 2007
        • 5

        #4
        hash of hashes will also fine

        Comment

        • KevinADC
          Recognized Expert Specialist
          • Jan 2007
          • 4092

          #5
          can you control the content of the text file? Can it just be written as a perl data construct to begin with so you don't have to try parsing it line by line into a data construct?

          Comment

          • sukiu47
            New Member
            • Jul 2007
            • 5

            #6
            how to read and store the blocks separetly .

            Comment

            • miller
              Recognized Expert Top Contributor
              • Oct 2006
              • 1086

              #7
              sukiu,

              What exactly are you really trying to accomplish? This data file looks like the output of a perl data structure, but it only partially follows the spec. Did you create the output to this file, and now are trying to reinput it to recreate the data structure? If this is the case, then they are more direct and simplier methods to accomplish this.

              - Miller

              Comment

              Working...