Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Perl Newline Help

by ww (Archbishop)
on Nov 14, 2014 at 02:01 UTC ( [id://1107175]=note: print w/replies, xml ) Need Help??


in reply to Perl Newline Help

Just another (ugly) way to tackle this (omitting print of unchanged "FILE..." lines and all data:)

#!/usr/bin/Perl use strict; use warnings; use 5.018; # 1106853.pl # assumes that the number to be moved up has > 1 digit and that # un-movable lines begin with not_more_than 0 or 1 digits before a non +-digit char. my ($line, @newlines, $linw, $line_may_need_a_fix); my @arr = <DATA>; START: for (my $i=0; $i < @arr; $i++) { $line = $arr[$i]; if ( $line =~ /\d{4} \\$/ ) { $line_may_need_a_fix = $line; next START; } elsif ( $line_may_need_a_fix && ($line =~ /^([0123456789]{2,4})/ +) ) { my $nums = $1; chomp $line_may_need_a_fix; $line_may_need_a_fix =~ s/\\$//; my $fixedLine = $line_may_need_a_fix . $nums; # Left as an ex +ercise: # removing $num +s from $line push(@newlines,$fixedLine); # Likewise, capture of $line an +d un-movables } $line_may_need_a_fix = ''; } foreach $linw(@newlines){ if ($linw =~ m/^FILE /) { print $linw,"\n"; next; } } __DATA__ FILE TEXT VAL 9999.999 08-jul-2014 \ 270 3E4497B6B8482ADED734 HDNDFLHWLEJHFL LKSNFLKN \ WKENFLWHFELHN UIEKEFJBKJFN FILE TEXT2 VAL 9999.999 16-may-2014 60 \ 8EC4B7367989D54F6D6C HSHFGFLALKHF KJAHEFKHAH\ YRNBFLJNELFN LQJFLKJWEF LKJFLKWJF FILE TEXT3 VAL 000.01 06-apr-2014 \ 1313 ABC3DEF XY77ZZ FILE TEXT4 VAL 213.7 05-feb-1013 95 \ 74nbfljaxlon lgggkjaxor blosqr4

Output:

FILE TEXT VAL 9999.999 08-jul-2014 270 FILE TEXT3 VAL 000.01 06-apr-2014 1313

++$anecdote ne $data


Log In?
Username:
Password:

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

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

    No recent polls found