Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
This is great example of how not to get people to help you. No info about what you're doing with this, and no script.

The line of code you did send works for me:

#!perl-w $day=22; $month=7; $year=104; print "$day\-".($month+1)."-".($year+1900)."\n";

Without the rest of the script, it's impossible to tell where it's breaking exactly, though my guess is the variables don't contain what you think.

But I'd like to take the opportunity to suggest a couple of optimisations:

Using a '.' to join strings in a print() statement is expensive - you are doing 2 operations when 1 is enough. print() expects a comma separated list, so:

print $day,"\-",($month+1),"-",($year+1900),"\n"; # less expensive

looks the same on output but behind the scenes is less expensive to use, just how much less expensive?

#! perl-w $day=22; $month=7; $year=104; $count=-5; use Benchmark qw(:all) ; $results = timethese($count, { 'Concatinated' => sub { print $day."\-".($month+1)."-" +.($year+1900)."\n";}, 'Commafied' => sub { print $day,"\-",($month+1),"-",($ +year+1900),"\n"; }, }, 'none' ); cmpthese( $results ) ;

running the above code I got this

Rate Commafied Concatinated Commafied 74894/s -- -71% Concatinated 260000/s 247% --

that's means print()ing with commas is over 300% faster.

Using quotes (") on a variable with a print() statement is likewise usually a bad idea because perl has to convert the same information to a string twice, once because of the quotes, the second time to print it.

print $day."\-".($month+1)."-".($year+1900)."\n"; # less expensive

Benchmarking this is less dramatic than the concatination Vs commas test - it shows an improvement of 6%. However if you're looking to speed up an script these are the kinds of things you should check for first.

You spend twenty years learning the spell that makes nude virgins appear in your bedroom, and then you're so poisoned by quicksilver fumes and half-blind from reading old grimoires that you can't remember what happens next.

In reply to Re: Answer: How do I find today's date? by Sol-Invictus
in thread QandASection: dates and times by vroom

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 or How to display code and escape characters are good places to start.
Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2022-01-21 11:56 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (57 votes). Check out past polls.