Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: substitution using hash issue

by choroba (Cardinal)
on Nov 12, 2012 at 15:17 UTC ( [id://1003458]=note: print w/replies, xml ) Need Help??


in reply to [SOLVED]substitution using hash issue

No substitution is required, a hash is all you need:
#!/usr/bin/perl use warnings; use strict; print "Enter date: "; chomp(my $date = <STDIN>); my ($day, $month, $year) = split '/', $date; print "$day $month $year\n"; my $m; my %dates = map { $_, sprintf '%02d', ++$m } qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; my $month_n = $dates{$month}; print "$day $month_n $year\n";
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: substitution using hash issue
by jaffinito34 (Acolyte) on Nov 12, 2012 at 15:21 UTC

    The program seemed to run but got some errors after entering the date, not sure what they mean though.

    Enter date: 23 Oct 2222 Use of uninitialized value $month in concatenation (.) or string at ./ +dateWork line 9, <STDIN> line 1. Use of uninitialized value $year in concatenation (.) or string at ./d +ateWork line 9, <STDIN> line 1. 23 Oct 2222 Use of uninitialized value $month in hash element at ./dateWork line 1 +5, <STDIN> line 1. Use of uninitialized value $month_n in concatenation (.) or string at +./dateWork line 16, <STDIN> line 1. Use of uninitialized value $year in concatenation (.) or string at ./d +ateWork line 16, <STDIN> line 1. 23 Oct 2222
      You should enter the date in the specified format.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        HAHA WHOOPS

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 13:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found