in reply to hash problems
The first problem is you used braces {} instead of parens () to define your hash. So you're making a hash reference and putting it into the hash as a single element. Then you're using double quotes without escaping them "within" double quotes. E.g., "This won't "work"." You can use the quote operators like qq and q, you can escape them like \"work\", or you can omit them since they aren't needed for simple hash keys.
Here is your code with the parens and strict and warnings on + general Perl idiom/style changes.
use warnings; use strict; my %passwords = ( Matt => "s1k1d52", scuzzy => "2ab928", Marky => "s8291s", Jeb => "jeb23" ); delete $passwords{jeb}; # <-- Update, MidLifeXis notes the casing in " +jeb" is wrong. if( exists $passwords{Matt} ) { print "$passwords{Matt} is my password.\n"; } if( defined $passwords{scuzzy} ) { print $passwords{scuzzy} . " IS defined!\n"; } print join(", ", values %passwords), " are everyone's passwords!\n";
|
|---|