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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |