On Tue, Jan 20, 2015 at 4:10 PM, Harry Putnam <rea...@newsguy.com> wrote:
> Randal responded: > > I just go: > > my $contents = do { local $/; <HANDLE> }; > I think you misunderstood what "slurping" is here and, maybe, the potential for multiline scalars. perldoc perlvar has: You should be very careful when modifying the default values of most special variables described in this document. In most cases you want to localize these variables before changing them, since if you don't, the change may affect other modules which rely on the default values of the special variables that you have changed. This is one of the correct ways to read the whole file at once: open my $fh, "<", "foo" or die $!; local $/; # enable localized slurp mode my $content = <$fh>; close $fh; but the trick here is "$/" (aka "use english" $INPUT_RECORD_SEPARATOR) is the input separator, that just means "slurp" in everything as there's no undef separate vars seen until the handle is closed. But the new lines in the input stay as new lines, saved in the now multi-line string in $contents. The output separator variable ($\ aka $OUTPUT_RECORD_SEPARATOR) will change what print appends to the end of each print stmt. Default is undef (which is where the v6 "say" comes in). You'll have to do the work yourself $contents =~ s/\n+/ /g; # change all into one line - single spaced. or something odd my $contents = do { local $/; map { chomp } <HANDLE> }; sorry, untested. -- a Andy Bach, afb...@gmail.com 608 658-1890 cell 608 261-5738 wk