Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

(MeowChow) Re2: Look ahead and join if the line begins with a +

by MeowChow (Vicar)
on Apr 11, 2002 at 06:33 UTC ( #158234=note: print w/ replies, xml ) Need Help??


in reply to Re: Look ahead and join if the line begins with a +
in thread Look ahead and join if the line begins with a +

# vulgar my @lines; $lines[@lines - s/^\+//] .= $_ while <FILE>;
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print


Comment on (MeowChow) Re2: Look ahead and join if the line begins with a +
Download Code
Re: (MeowChow) Re2: Look ahead and join if the line begins with a +
by tachyon (Chancellor) on Apr 11, 2002 at 09:11 UTC

    Ahmm

    # vulgar AND broken my @lines; $lines[@lines - s/^\+//] .= $_ while <DATA>; print @lines __DATA__ This +is +supposed +to +be +one +line! Oops

    I'm sure that this is what you meant, but even this is broken as it will possibly remove the last char in the file if their is no trailing newline.

    $lines[@lines - s/^\+//] .= substr $_,0,-1 while <DATA>;

    This will work:

    $lines[ @lines + 1 - s -^\053|\012--g ] .= $_ while <DATA>;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      I based my code on japhy's solutions, none of which were stripping newlines, probably because Rhodium didn't specify if he wanted them removed, or the lines to be simply concatenated as-is into single list items.
      $lines[ @lines + 1 - s -^\053|\012--g ] .= $_  while <DATA>;
      This fails by adding an undef element to the array if a newline is not the final character in the file. Changing my original easy enough though, without any regex or substr nastiness:
      chomp, $lines[@lines - s/^\+//] .= $_ while <DATA>;
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print

        Touche. But.....

        chomp, $lines[@lines - s/^\+//] .= $_ while <DATA>; __DATA__ + Oops, Just another Edge case

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2014-12-27 15:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls