Re: How to use a textfile for filenames??
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 14 Feb 2006 05:44:08 -0800
Dan wrote:
I would like to take each line of the file (one URL per line) and
remove the Http://
Use the substitution operator ( s/// ) for that. The s/// operator
is documented in:
Would using substr() be an even more efficient method of doing this?
According to the following benchmark, it depends on which substr() form
you use:
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw/cmpthese/;
sub gen_lines {
qw{
Http://www.yahoo.com
Http://gmail.google.com
Http://disney.go.com
Http://www.perldoc.com
Http://search.cpan.org
Http://www.oreilly.com
Http://www.ge.com
Http://www.stratus.com
Http://www.es11.com
Http://www.bankofamerica.com
};
}
cmpthese(-10, {
'substr_3arg' => sub {
my @lines = gen_lines();
substr($_, 0, 7) = q{} for @lines;
},
'substr_4arg' => sub {
my @lines = gen_lines();
substr($_, 0, 7, q{}) for @lines;
},
's///' => sub {
my @lines = gen_lines();
s{^Http://}{} for @lines;
}
}
);
__END__
Benchmark: running s///, substr_3arg, substr_4arg, each for at least 10
CPU seconds...
s///: 10 wallclock secs (10.52 usr + 0.01 sys = 10.53 CPU) @
10956.03/s (n=115367)
substr_3arg: 11 wallclock secs (10.22 usr + 0.01 sys = 10.23 CPU) @
10105.96/s (n=103384)
substr_4arg: 10 wallclock secs (10.54 usr + 0.00 sys = 10.54 CPU) @
12353.89/s (n=130210)
Rate substr_3arg s/// substr_4arg
substr_3arg 10106/s -- -8% -18%
s/// 10956/s 8% -- -11%
substr_4arg 12354/s 22% 13% --
(If I've done something that renders this test invalid, I'd appreciate
hearing about it... I'm rather a novice when it comes to Benchmarking)
Paul Lalli
.
- Follow-Ups:
- Re: How to use a textfile for filenames??
- From: Anno Siegel
- Re: How to use a textfile for filenames??
- From: A. Sinan Unur
- Re: How to use a textfile for filenames??
- References:
- How to use a textfile for filenames??
- From: Jake
- Re: How to use a textfile for filenames??
- From: Tad McClellan
- Re: How to use a textfile for filenames??
- From: Dan
- How to use a textfile for filenames??
- Prev by Date: Re: How to use a textfile for filenames??
- Next by Date: Re: using command line switches
- Previous by thread: Re: How to use a textfile for filenames??
- Next by thread: Re: How to use a textfile for filenames??
- Index(es):
Relevant Pages
|