View Full Version : File slurping in Perl
archy22
06-03-2011, 01:09 AM
The following code slurps the STDIN file, then splits it into lines, then reassembles the lines into a single string, and prints the string
#!/usr/bin/perl -w
use strict;
my $holdTerminator = $/;
undef $/;
my $buf = <STDIN>;
$/ = $holdTerminator;
my @lines = split /$holdTerminator/, $buf;
$buf = "init";
$buf = join $holdTerminator, @lines;
print $buf;
print "\n";
benmoriz
09-09-2012, 06:24 PM
my $holdTerminator = $/;
undef $/;
my $buf = <STDIN>;
$/ = $holdTerminator;
my @lines = split /$holdTerminator/, $buf;
$buf = "init";
$buf = join $holdTerminator, @lines;
print $buf;
njtboy
09-14-2012, 12:30 AM
#!/usr/bin/perl -w
use strict;
my $holdTerminator = $/;
undef $/;
my $buf = <STDIN>;
$/ = $holdTerminator;
my @lines = split /$holdTerminator/, $buf;
$buf = "init";
$buf = join $holdTerminator, @lines;
print $buf;
print "\n";
paudelsonu88
12-03-2012, 12:16 PM
File slurping in Perl is the simple and efficient reading or writing or modifying a complete file. It is related to file handling where we use the file for different purposes like reading, writing and modifying if needed to update the existing contents of the file or change some stored data in the file using Perl.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.