title: Substitute Array Elements with Hash Values
body: <p>I am trying to code a Perl Script which will take the date in Pattern, October 24, 2011 and convert this to 10,24,2011.</p>
  
  <p>In order to do this I have prepared a Hash which will have the Month Name as a Key and a Numerical value representing Month's position as a Value.</p>
  
  <p>I will read the input string, use a regular expression to extract the month name from above format.</p>
  
  <p>Replace this month name with a value which corresponds to the month as a key.</p>
  
  <p>Here's the script I have coded so far, but it's not working for me.</p>
  
  <p>@dates array will have every element in this format -> October 24, 2011.</p>
  
  <pre><code>%days=("January",01,"February",02,"March",03,"April",04,"May",05,"June",06,"July",07,"August",08,"September",09,"October",10,"November",11,"December",12);
  
  @output = map{
  $pattern=$_;
  $pattern =~ s/(.*)\s/$days{$1};
  } @dates;
  
  foreach $output (@output)
  {
  print $output."\n";
  }
  </code></pre>
  
  <p>Here's a little explanation of what I am trying to do with this code.</p>
  
  <p>@output will have the new formatted array with the Month Name replaced by the corresponding Numerical representing it as defined in the Hash.</p>
  
  <p>map function is used to transform the elements of the array on the fly.</p>
  
  <p>a sequence of characters followed by space is the regular expression used to extract the Month Name from pattern, October 24, 2011.</p>
  
  <p>This will be referenced by $1.</p>
  
  <p>I look up the corresponding value for $1 in the hash using, $days{$1} </p>