"A. Pagaltzis" <[EMAIL PROTECTED]> wrote:
> * John Douglas Porter <[EMAIL PROTECTED]> [2003-02-07 14:15]:
> > @lines = split /\n/, $x, -1;  pop @lines;
> 
> $/ can be different from \n though. 

Yes, but his example data was text in a here document.

But you can always do

  split m,$/, $x, -1;



> And popping the last field is dangerous - you don't know if
> the file ends with a newline.

You DO know it does, if the text came from a here document.


> Also, you now have no chance
> to reconstruct the exact equivalent of your input using
> 
> $line = join $/, @lines;
> 
> because that will never attach a record separator to the
> last line even if there was one before.

Well, I didn't address this part of the problem, but others
have, giving

  join $/, @lines, '';

which is sufficient.  If you're paranoid, you can do

  @lines = split ...;
  $tail = pop @lines;

and then later

  join "\n", @lines, $tail;

-- 
John Douglas Porter


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

Reply via email to