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

Re: Easy hash question (uninitialized value)

by james28909 (Deacon)
on May 16, 2018 at 19:02 UTC ( #1214686=note: print w/replies, xml ) Need Help??


in reply to Easy hash question (uninitialized value)

here is a great way to keep it neat and listed in numerical order as well
#!/usr/bin/env perl use strict; use warnings; use utf8; use feature 'say'; use File::Copy; my %j = ( 1 => 'vimplugins', 2 => "vimwiki", 3 => "vim", 4 => "bash", 5 => "latex", 6 => "perl", 7 => "regex", 8 => "git", 9 => "gnupg", 10 => "nmap", 11 => "tmux", 12 => "csssnippets", 13 => "htmlsnippets", 14 => "latexsnippets", 15 => "markdownsnippets", 16 => "perlsnippets", 17 => "vimsnippets", ); ### PRINT THE SORTED HASH ### say "$_ - $j{$_}" for sort { $a <=> $b } keys(%j); ### GET USER SELECTION ### my $number = <STDIN>; chomp($number); ### PRINT OUT $j{$number} DIRECTLY INSTEAD OF COPYING IT TO ANOTHER BU +FFER ### say "\r\b\ryou picked -> $j{$number}\n" if exists $j{$number} or die " +selection <$number> does not exist in the list!\n";

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2018-11-13 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (149 votes). Check out past polls.

    Notices?