K
Ken Sington
criticism is good.
here's my function to wrap really long lines:
very basic.
# wrap long lines ###################################
sub wrapLine {
my ($line) = @_;
$line =~ s/.{70}/$&\n/g;
return "$line"; #(yeah, I know, last value is returned automatically)
}
using standards:
#!/usr/bin/perl
use strict;
use warnings;
of course.
PROG 1
my $longline="blah, " x 300;
print &wrapLine($longline);
--- OR ---
PROG 2
open READ, "twoMB_bigFile.txt;
while (<READ>){
print &wrapLine($_);
}
close READ;
--- OR ---
PROG 3
open READ, "twoMB_bigFile.txt";
my @big = <READ>;
close READ;
foreach (@big) {
print &wrapLine($_);
}
--- OR ---
PROG 4
open READ, "twoMB_bigFile.txt";
my @big = <READ>;
close READ;
while (@big) {
print &wrapLine($_);
}
Anyone think there's a better way to wrap a long line?
I notice that in PROG.4, with the while loop, the script seems to just
hang. however, the foreach in PROG 3 seems to run just fine.
I was told by some "expert" that while handles large input better than
foreach.
PROG 1 and PROG 2 work as expected.
here's my function to wrap really long lines:
very basic.
# wrap long lines ###################################
sub wrapLine {
my ($line) = @_;
$line =~ s/.{70}/$&\n/g;
return "$line"; #(yeah, I know, last value is returned automatically)
}
using standards:
#!/usr/bin/perl
use strict;
use warnings;
of course.
PROG 1
my $longline="blah, " x 300;
print &wrapLine($longline);
--- OR ---
PROG 2
open READ, "twoMB_bigFile.txt;
while (<READ>){
print &wrapLine($_);
}
close READ;
--- OR ---
PROG 3
open READ, "twoMB_bigFile.txt";
my @big = <READ>;
close READ;
foreach (@big) {
print &wrapLine($_);
}
--- OR ---
PROG 4
open READ, "twoMB_bigFile.txt";
my @big = <READ>;
close READ;
while (@big) {
print &wrapLine($_);
}
Anyone think there's a better way to wrap a long line?
I notice that in PROG.4, with the while loop, the script seems to just
hang. however, the foreach in PROG 3 seems to run just fine.
I was told by some "expert" that while handles large input better than
foreach.
PROG 1 and PROG 2 work as expected.