http://www.perlmonks.org?node_id=1057123


in reply to Iterator to parse multiline string with \\n terminator

No need for recursion. Just change the anonymous sub as follows (untested):

my $fh_iterator = sub { my $fh = shift; my $line = $fh->getline(); $line .= $fh->getline() while $line =~ m{\\$}; return $line; }

Update: Here is a tested script which eliminates the Use of uninitialized value warning reported in the post below:

use strict; use warnings; use IO::File; my $filename = shift @ARGV; my $fh = IO::File->new($filename, 'r'); sub fh_iterator { my $fh = shift; my $line = $fh->getline(); if (defined $line) { $line .= $fh->getline() while $line =~ m{\\$}; } return $line; } while (my $line = fh_iterator($fh)) { print $line; }

Output:

16:29 >perl 738_SoPW.pl test.file foo \ bar \ baz single line 16:29 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,