Created
November 20, 2013 20:13
-
-
Save AndrewRussellHayes/7570191 to your computer and use it in GitHub Desktop.
Add Dashes to date in file name. Takes: "part_part_20120513_part_part.ext" and makes: "part_part_2012-05-13_part_part.ext".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub addDashes | |
{ | |
my $originalFileName = shift; | |
#split along uscores into array | |
my @parts = split('_',$originalFileName); | |
# take the third index of the array and add dashes in this pattern ####-##-## and put it back in the array | |
$parts[2] = join('-', unpack('A4A2A2', $parts[2])); | |
# put the whole thing back together | |
my $formattedFileName = join('_', @parts); | |
return $formattedFileName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment