Skip to content

Instantly share code, notes, and snippets.

@AndrewRussellHayes
Created November 20, 2013 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRussellHayes/7570191 to your computer and use it in GitHub Desktop.
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".
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