hopefully a simple hash error

dwcronin
dwcronin used Ask the Experts™
on
i'm new to perl so this is hopefully simple.  i keep getting the following error:

------------------------------------------------------------------------------------------------------------
syntax error at /home/dwcronin/programs/ex4_1 line 7, near "$family_name{"
Execution of /home/dwcronin/programs/ex4_1 aborted due to compilation errors.
--------------------------------------------------------------------------------------------------------------

specifically. i'm trying to learn hashes by following the o'reilly book 'learning perl" by randal schwartz.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
here is the code that would not upload:
#!/usr/bin/perl;                                           # ex5_1
######################################################################################
use warnings;
use strict;
use 5.010;

my $family_name{"fred"} = "flintstone";

~                                                                                                                                                                        
~                                                                                                                                                                        
~                                                                                                                                                                        
~                                                                                                                                                                        
~                                                                                                                                                                        
~
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Create the hash first:

use warnings;
use strict;
use 5.010;

my %family_name;

$family_name{"fred"} = "flintstone";

Open in new window

ǩa̹̼͍̓̂ͪͤͭ̓u͈̳̟͕̬ͩ͂̌͌̾̀ͪf̭̤͉̅̋͛͂̓͛̈m̩̘̱̃e͙̳͊̑̂ͦ̌ͯ̚d͋̋ͧ̑ͯ͛̉Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
Alternatively, you can initialize the variable inline:

use warnings;
use strict;
use 5.010;

my %family_name = ("fred", "flintstone");

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial