Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^5: Using Variables in Path Names

by tadman (Prior)
on Nov 28, 2001 at 20:48 UTC ( [id://128092]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: {3} Using Variables in Path Names
in thread Using Variables in Path Names

I suppose my rationale behind using join over string interpolation was that when working with directories, it is often advantageous to use an array instead of a string. This way you can resolve path components like '..' using pop instead of a regex. The other idea was that each piece supplied to the join would represent a single path component, which could be validated using a quick map for the extra paranoid. Of course, then $HOME would have to be split into something like @HOME.

Anyway, Benchmark says:
Benchmark: timing 1000000 iterations of interpolator, joiner... interpolator: 5 wallclock secs ( 5.13 usr + 0.00 sys = 5.13 CPU) @ +194931.77/s (n=1000000) joiner: 4 wallclock secs ( 4.53 usr + 0.00 sys = 4.53 CPU) @ 22 +0750.55/s (n=1000000) Rate interpolator joiner interpolator 194932/s -- -12% joiner 220751/s 13% --
From:
#!/usr/bin/perl my ($the,$fastest,$donut,$youve,$ever,$seen) = qw [ the fastest donut +you've ever seen ]; sub joiner { my $x = join ('/', $the,$fastest,$donut,$youve,$ever,$seen); } sub interpolator { my $x = "$the/$fastest/$donut/$youve/$ever/$seen"; } use Benchmark qw [ cmpthese ]; cmpthese ( 1000000, { joiner => \&joiner, interpolator => \&interpolator, } );

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2024-04-16 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found