Here is the code based on your example:
#!/usr/bin/perl use warnings; use strict; use Getopt::Std; my %options; getopt("ivcm",\%options); do { die "Usage: $0 -i <input file> -v <variable file> -c <code file> -m < +macro file>\n" unless defined $options{$_} } for qw/i v c m/; open my $input, "<", $options{i} || die "$options{i}: $!\n"; open my $code, ">", $options{c} || die "$options{c}: $!\n"; open my $var, ">", $options{v} || die "$options{v}: $!\n"; open my $macro, ">", $options{m} || die "$options{m}: $!\n"; while (defined(my $line = <$input>)) { chomp $line; next if $line=~/^\s*$/; next if $line=~/^\s*\*/; $line=~s/EQU\s+\*//; $line=~s/\s*$//; my @fields = split /\s+/,$line,4; shift @fields until $fields[0] ne ''; if ($fields[0] eq 'BEGIN') { print $code join ("\t",@fields),"\n"; } elsif ($fields[0] =~ /^(BEGIN|L|CLI|BNE|LTR)$/) { #code pop @fields; print $code (join "\t",@fields),($fields[0] eq 'CLI' ? "" : "\ +n"); } elsif ($fields[0] =~ /^@/) { # macro print $macro (join "\t",@fields),"\n"; pop @fields; print $code (join "\t",@fields),"\n"; } elsif ($fields[1] =~ /^D[CS]$/) { #variable? my ($len) = ($fields[2] =~ /L(\d+)/); #??? my ($type) = $fields[2] =~ /^(.)/; # ??? my ($value) = ($fields[2] =~ /'(\d+)'$/); #??? print $var (join "\t",$fields[0],$len,$type,$value,$fields[3]) +,"\n"; } else { warn "Don't know what to do with line\n$line\n"; } } close $_ || die $! for ($input,$code,$var,$macro);
It sure contains some mistakes because I had to guess some things about CLI, BNE and variables. Feel free to fix it. If you would state more clearly how to distinguish between code and variables, it will be easier to write the proper code.
See split, join, shift, pop for more info on this script.
Sorry if my advice was wrong.

In reply to Re^3: 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.