jaffinito34 has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks, I'm writing a script that will simply take in a given date in the format of (DD/Mon/YYYY) where the month is entered as a 3 letters. I'm trying to convert the letters into its corresponding number using a hash but I'm having some difficulty and I know this is a simple fix but I can't seem to figure it out. Check out the code below.
#! /usr/bin/perl print "Enter date: "; chomp($date = <STDIN>); ($day,$month,$year) = split '/', $date; print "$day $month $year\n"; %dates = ( 'Jan' => 01,'Feb' => 02,'Mar' => 03,'Apr' => 04,'May' => 05,'Jun' +=> 06, 'Jul' => 07,'Aug' => 08,'Sep' => 09,'Oct' => 10,'Nov' => 11,'Dec' +=> 12, ); foreach $char ($month){ $char =~ s/.../$dates{$month}/; }
I keep getting compilation errors, not sure why though. Any help is appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: substitution using hash issue
by brx (Pilgrim) on Nov 12, 2012 at 15:50 UTC | |
|
Re: substitution using hash issue
by choroba (Cardinal) on Nov 12, 2012 at 15:17 UTC | |
by jaffinito34 (Acolyte) on Nov 12, 2012 at 15:21 UTC | |
by choroba (Cardinal) on Nov 12, 2012 at 15:25 UTC | |
by jaffinito34 (Acolyte) on Nov 12, 2012 at 15:26 UTC | |
|
Re: substitution using hash issue
by brap (Pilgrim) on Nov 12, 2012 at 15:16 UTC | |
by jaffinito34 (Acolyte) on Nov 12, 2012 at 15:22 UTC | |
by jaffinito34 (Acolyte) on Nov 12, 2012 at 15:25 UTC | |
|
Re: substitution using hash issue
by Anonymous Monk on Nov 12, 2012 at 15:10 UTC | |
by jaffinito34 (Acolyte) on Nov 12, 2012 at 15:16 UTC |