There are several reasons why this script is slow and Tie::Array is only one of them.

By keeping a bit of state and storing field values in a hash as you find them, you can completely eliminate the need to use an array and most of the internal if/else statements and loops as well. Here is much simplified version of your parser:

use strict; use warnings; sub printRecord; #-------------------------------------------------- # Parsing loop #-------------------------------------------------- my $fhOut = \*STDOUT; my $iLevel=0; my %hFields; while (my $sLine = <DATA>) { #if line defines the level, set level if ($sLine =~ /^\s*(?:Level|Record|Sub Record)\s+\(\d+\)/) { $iLevel++; } elsif ($sLine =~ /^\s*End of/) { $iLevel--; } else { my ($k, $v) = $sLine =~ /\s+\"(\w+)\"\s+=\s+\"([^"]*)\"/; $hFields{$k}=$v; } #if level back to 0, dump record if ($iLevel == 0) { printRecord($fhOut, \%hFields); %hFields=(); } } #-------------------------------------------------- # SUBROUTINE DEFINITIONS #-------------------------------------------------- sub printRecord { my ($fhOut, $hFields) = @_; my $sIOType = $hFields->{MSC_CDR_TYPE}; print $fhOut "RECORD\n"; print $fhOut "#addkey\n"; print $fhOut "#filename FF\n"; print $fhOut "#input_id 001\n"; print $fhOut "#input_type $sIOType\n"; print $fhOut "#output_id\n"; print $fhOut "#output_type $sIOType\n"; print $fhOut "#source_id SRC\n"; foreach my $k (sort keys %$hFields) { my $v = $hFields->{$k}; print $fhOut "F $k $v\n"; } print $fhOut ".\n"; } #cut and paste sample data from above __DATA__

In reply to Re: Improving dismal performance - Part 1 by ELISHEVA
in thread Improving dismal performance - Part 1 by PoorLuzer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.