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