Here are some comments to your program:
  1. Always
    use warnings; use strict;
    It can look inconvinient, but it really helps to prevent some stupid bugs.
  2. This:
    $src_filename = $ARGV[0]; $var_filename = $ARGV[1]; $tgt_filename = $ARGV[2]; $mac_filename = $ARGV[2];
    can be rewritten as:
    die "Usage: four arguments\n" unless $#ARGV == 3; my ($src_filename,$var_filename,$tgt_filename,$mac_filename) = @ARGV;
  3. You can process the file line-by-line, without any need to read the whole file into memory:
    while (defined my $line = <IFILE>) { chomp; # remove \n from the end of the line ... }
  4. #Read only 1 - 72 columns data $Line =~ /.{72}/; $Line = $&; $Line = $Line."\n";
    Are you sure you are working with fixed-length strings? Anyway, $line = substr($line,0,72); is easier and faster.
  5. $Temp = $Line; #Remove evrything after column 40 fromt he code $Line =~ /.{40}/; $description = $'; $Line = $&; chomp($description); $description =~s/\s+$//g;
    This also can be done easier: ($line,$description) = ($line=~/^(.{40})(.*)\s+$/);
    I suspect, there is a more right way to do it (perhaps, using split), but I can't figure it out now.
  6. $Line =~s/\(/\'/g; $Line =~s/\)/\'/g; if($Line =~/([^\s]+)\s+(DC|DS|EQU)\s+(A|X|C|H|F|D|0X|0D|0C)+(L)* +([^\'\(\s]+)*(\'(.+)\')*\s*/i) { $Print_Line = " "; $Print_Line = $1.",".$3.",".$5.",".$7.",".$description."\n"; push(@Var_File_Array,$Print_Line); } else { if($Temp!~/^\s*\*/ and $Temp!~/^\s+$/) #lines other than comment +s and line spaces { push(@Tgt_File_Array,$Temp); if($Temp=~/\s+(EQU)\s+(\*)/i) #remove EQU * from the state +ments { $Temp = $`; $Temp = $Temp."\n"; pop @Tgt_File_Array; push(@Tgt_File_Array,$Temp); if(length($Temp)>1) { @split_words = split(' ',$Temp); #to remove line co +mments #pop @Tgt_File_Array; push(@Tgt_File_Array,@split_words[0],' ',@split_words[1]); } } }
    Oops. Perhaps this logic can be optimised:
    if($line =~/([^\s]+)\s+(DC|DS|EQU)\s+(A|X|C|H|F|D|0X|0D|0C)+(L)*([^\'\ +(\s]+)*(\'(.+)\')*\s*/i) { ($line,my $description) = ($line=~/^(.{40})(.*)\s+$/); # do the actua +l $line modification only there $line =~ tr/\(\)/''/g; push(@Var_File_Array,$1.",".$3.",".$5.",".$7.",".$description."\n"); } elsif (!($line=~/^\s*\*|^\s*$/)) { push(@Tgt_File_Array,$line); if ($line =~ s/\s+EQU\s+\*.*$/i) { pop @Tgt_File_Array; push(@Tgt_File_Array,$line."\n"); length $line > 0 && push @Tgt_File_Array,(join " ",(split ' ',$line) +[0,1]); } }
    Note: this piece of code was untested. To my mind, it needs to be completely rewritten.
Your script seems rather complicated. Are you doing such complex work? Perhaps everything can be done a lot easier if you tell us your original task with more small source and expected data samples.
EDIT: minor code changes
Sorry if my advice was wrong.

In reply to Re: please help me to resolve the Line comments and appending issue by aitap
in thread please help me to resolve the Line comments and appending issue by suno

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.