Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: substitution using hash issue

by brx (Pilgrim)
on Nov 12, 2012 at 15:50 UTC ( [id://1003469]=note: print w/replies, xml ) Need Help??


in reply to [SOLVED]substitution using hash issue

  1. use strict; This is a good friend.
  2. Declare your variables:  my %dates = ...
  3. 01 is an octal number (one). 08 is an illegal number representation. What you want is text, so write text with quotes: my %dates = ( 'Jan' => '01', #...
  4. $dates{'Dec'} contains "12". So, forget regex substitution: print "$day $dates{$month} $year\n";
  5. There is a lot of caveats with dates. Consider well known CPAN modules like DateTime...

#!/usr/bin/perl use strict; my %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', ); my $date = "30/Feb/2013"; my ($day,$month,$year) = split '/', $date; print "$day $dates{$month} $year\n";

English is not my mother tongue.
Les tongues de ma mère sont "made in France".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1003469]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-28 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found