Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: Re: Re: appending a unique marker to each url in a file

by chipmunk (Parson)
on Aug 08, 2001 at 17:59 UTC ( [id://103039]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: appending a unique marker to each url in a file
in thread appending a unique marker to each url in a file

Using $content = join '', <FILE>; rather than local $/; $content = <FILE> is fine, as long as you don't care that the latter is roughly an order of magnitude faster.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: appending a unique marker to each url in a file
by tachyon (Chancellor) on Aug 08, 2001 at 18:32 UTC

    An order of magnitude is not actually correct although the point is *of course* {sigh} valid. For small files the difference is negligible. The gains increase with file size. Nonetheless faster is faster is better.

    #!/usr/bin/perl -w use strict; my $file = shift; my $iter = shift; my $size = -s $file; print "File size $size Bytes\n"; my $start = time; for (1..$iter) { open FILE, $file or die $!; my $stuff = join'',<FILE>; close FILE; } printf "Join took %d seconds for %d iterations\n", (time-$start), $ite +r; $start = time; for (1..$iter) { { local $/; open FILE, $file or die $!; my $stuff = <FILE>; close FILE; } } printf "Undef \$/ took %d seconds for %d iterations\n", (time-$start), + $iter; __END__ C:\>perl test.pl bigfile.txt 2000 File size 47753 Bytes Join took 72 seconds for 2000 iterations Undef $/ took 21 seconds for 2000 iterations C:\>perl test.pl test.pl 2000 File size 878 Bytes Join took 8 seconds for 2000 iterations Undef $/ took 7 seconds for 2000 iterations C:\>

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://103039]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (1)
As of 2024-04-25 01:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found