It can look inconvinient, but it really helps to prevent some stupid bugs.use warnings; use strict;
can be rewritten as:$src_filename = $ARGV[0]; $var_filename = $ARGV[1]; $tgt_filename = $ARGV[2]; $mac_filename = $ARGV[2];
die "Usage: four arguments\n" unless $#ARGV == 3; my ($src_filename,$var_filename,$tgt_filename,$mac_filename) = @ARGV;
while (defined my $line = <IFILE>) { chomp; # remove \n from the end of the line ... }
Are you sure you are working with fixed-length strings? Anyway, $line = substr($line,0,72); is easier and faster.#Read only 1 - 72 columns data $Line =~ /.{72}/; $Line = $&; $Line = $Line."\n";
This also can be done easier: ($line,$description) = ($line=~/^(.{40})(.*)\s+$/);$Temp = $Line; #Remove evrything after column 40 fromt he code $Line =~ /.{40}/; $description = $'; $Line = $&; chomp($description); $description =~s/\s+$//g;
Oops. Perhaps this logic can be optimised:$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]); } } }
Note: this piece of code was untested. To my mind, it needs to be completely rewritten.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]); } }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |