Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Perl File Parsing - My Code Works, but it's Ugly!

by Anonymous Monk
on Jun 01, 2015 at 10:22 UTC ( [id://1128540]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl File Parsing - My Code Works, but it's Ugly!
in thread Perl File Parsing - My Code Works, but it's Ugly!

TIMTOWTDI:

$outfolder = sprintf "REPORT_output_%d_%d_%d__%d_%d_%d", $year, $mon, $mday, $hour, $min, $sec;

With the advantage that you could do something like:

$outfolder = sprintf "REPORT_output_%04d_%02d_%02d__%02d_%02d_%02d", $year, $mon, $mday, $hour, $min, $sec;

giving

REPORT_output_2015_06_01__00_19_42

Replies are listed 'Best First'.
Re^3: Perl File Parsing - My Code Works, but it's Ugly!
by BillKSmith (Monsignor) on Jun 01, 2015 at 14:08 UTC
    I prefer the function strftime in POSIX for formatting dates. The only downside is that documentation for the format codes is "borrowed" from "C" and not included in perl's documentation.
    use strict; use warnings; use POSIX 'strftime'; my $outfolder = strftime "Report_Output_%Y_%m_%d__%H_%M_%S", localtime(); print $outfolder;
    Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 21:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found