G'day ed3rick,

Welcome to the Monastery.

This annotated code should get you started:

#!/usr/bin/env perl -l use strict; use warnings; # Set these constant values my %month_num_for = qw{ January 1 February 2 March 3 April 4 May 5 June 6 July 7 August 8 September 9 October 10 November 11 December 12 }; my $format = '%4d%02d%02d-%s'; # Get this data from file my $old_filename = 'abc001'; my $long_date = 'January 5, 2002'; # Split up the long format date my ($month, $day, $year) = split /\,?\s+/, $long_date; # Generate the new filename my $new_filename = sprintf $format, $year, $month_num_for{$month}, $day, $old_filen +ame; # For testing print "New filename: $new_filename"; # When you're happy with the testing # rename $old_filename => $new_filename

Output:

New filename: 20020105-abc001

If you're unfamiliar with any of those functions, you'll find their documentation via "Perl functions A-Z".

For any other parts of the code you don't understand, refer initially to "perlintro -- a brief introduction and overview of Perl". Each section in there has links to more detailed information: follow as required.

-- Ken


In reply to Re: Converting Date to String by kcott
in thread Converting Date to String by ed3rick

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.