Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#!/usr/bin/perl
my $x = qx { string1 *.txt | grep -v string2 };
chomp $x;
print $x;
use File::Slurp qw(read_file);
my @lines = grep {/string1/ && ! /string2/} map {read_file($_)} glob('*.txt');
my @lines = grep (/string1/ && ! /string2/, @buffer);
# @buffer is the contents of a source file to be parsed
my $srce = "./sourcefile.txt";
open(FH, $srce);
my @buf = <FH>;
close(FH);
my @lines = grep (/string1/ && ! /string2/, @buffer);
my $srce = "./sourcefile.txt";
my @lines = grep {/string1/ && ! /string2/} map {read_file($_)} glob($srce);
lcs01 said:A follow-up question:
Compare the following two implementations:
...
Which one is more efficient and why?
use File::Slurp qw(read_file);
my @lines = grep {/string1/ && ! /string2/} read_file("./sourcefile.txt");
Compare the following two implementations:
KevinADC said:Without testing I would guess the first implementaton is a little bit more efficient.
[/CODE]
Come on Kevin. Use a little imagination
The difference between IO operations, and IO operations hidden behind a function call are infinitesimal. The only additional time involved is that which takes to install the module using cpan.
lcs01 said:The actual source file is huge ~50 mbytes.
my $srce = "./sourcefile.txt";
open(FH, $srce);
my @lines = ();
while (<FH>) {
push @lines, $_ if /string1/ && ! /string2/;
}
close(FH);