Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: how to append 2 lines

by philiprbrenan (Monk)
on Sep 01, 2012 at 17:23 UTC ( [id://991175]=note: print w/replies, xml ) Need Help??


in reply to how to append 2 lines

Something along the lines of:

use feature ":5.14"; use warnings FATAL => qw(all); use strict; my ($c, $s) = (0, ''); for(split /\n/, << 'END') LABEL#00001 MVC SYMBOL+2(4),X.PDES_KEY+2 + MVC SYMB_ART,=C'XSEQ' //line comments + + F$SFH SELECT,LISTING, + * DESKART=SYMB_ART, + * DESKWERT=SYMBOL, + * MARKTCODE=L#MACF + BNE F03#000 //line comments END {if (length > 71 and substr($_, 71, 1) eq '*') # Detect continuation {s/\A\s*// if $c == 1; # Strip leading space +in continuation s/\s*\*\s*\Z//; # Strip trailing space ($s, $c) = (($c ? $s : '').$_, 1); # Concatenate or resta +rt depending on continuation state } else {s/\A\s*// if $c == 1; # Strip leading spaces + in continuation say "$s$_"; # Write completed stat +ement ($s, $c) = ('', 0); # Restart } }

Produces

LABEL#00001 MVC SYMBOL+2(4),X.PDES_KEY+2 + MVC SYMB_ART,=C'XSEQ' //line comments + + F$SFH SELECT,LISTING,DESKART=SYMB_ART,DESKWERT=SYMBOL,MARKTCO +DE=L#MACF BNE F03#000 //line comments

Replies are listed 'Best First'.
Re^2: how to append 2 lines
by suno (Acolyte) on Sep 05, 2012 at 12:18 UTC
    Hi,....

    Thanks for the advice....

    but another doubt....This is fine if i give the input then and there... but i want to give my input in a file... i want to perform this action for the above lines in a file.. please help me in this also...

    Thanks in advance...

      May I suggest something like this to read your lines of text:

      use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); sub readFile($) {my ($f) = @_; $f or die "readFile: No file specified"; open my $F, "<$f" or die "Cannot open $f for input"; local $/ = undef; <$F> } print readFile("readFile.pm");

      Produces:

      use feature ":5.14"; use warnings FATAL => qw(all); use strict; use Data::Dump qw(dump pp); sub readFile($) {my ($f) = @_; $f or die "readFile: No file specified"; open my $F, "<$f" or die "Cannot open $f for input"; local $/ = undef; <$F> } print readFile("readFile.pm");
        Hi,

        Thanks for the help...i was successfully able to finish it...

        i have one more doubt..

        say my code is          F$SFH FIRST,SC==H'160',        COMMENTS                    * i need to replace ',*' instead of ", K.160 LESEN *" so that my code looks like F$SFH FIRST,SC==H'160',*

        I tried using substitution function.. but i dont know where i am going wrong,. please help me in this... my code looks somewhat like

        $a = F$SFH FIRST,SC==H'160', K.160 LESEN +* $a =~ s/\,[\s]*\*/\,\*/;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://991175]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-19 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found