Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Converting output from numeric values to text

by PrimeLord (Pilgrim)
on Mar 28, 2002 at 22:09 UTC ( [id://155133]=note: print w/replies, xml ) Need Help??


in reply to Converting output from numeric values to text

In the spirit of TIMTOWTDI you could also just build a hash with your info.

my %months = qw( 0 => Jan 1 => Feb 2 => Mar );


Then is $Month was 0

print "$months{$month}\n"; Output = Jan

Replies are listed 'Best First'.
(jeffa) 2Re: Converting output from numeric values to text
by jeffa (Bishop) on Mar 29, 2002 at 00:44 UTC
    Couldn't .... resist .... temptation:
    my %month = map { $_ => 1 } qw(jan feb mar apr may jun jul aug sep oct + nov dec);
    Or a hash slice:
    my %month; my @month = qw(jan feb mar apr may jun jul aug sep oct nov dec); @month{@month} = (1) x @month;
    UDPATE:
    sorry about that - please allow me to fix it:
    my @month = qw(jan feb mar apr may jun jul aug sep oct nov dec); my %month = map { $_ => $month[$_] } (0..$#month); ... $m_name = $month{$m_number};

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      I don't think your code produces what the original poster OnTheEdge wanted. Yours would result in a hash with the month names as keys and 1 as values for each.

      He wants to convert month numbers into month names.

      $m_name = qw(jan feb mar apr may jun jul aug sep oct nov dec)[$m_numbe +r];
      /prakash

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-26 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found