Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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, } );

In reply to Re^5: Using Variables in Path Names by tadman
in thread Using Variables in Path Names by lfindle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-18 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found