Avatar of dwcronin
dwcronin
Flag for United States of America asked on

hopefully a simple hash error

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.
Perl

Avatar of undefined
Last Comment
kaufmed

8/22/2022 - Mon
dwcronin

ASKER
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";

~                                                                                                                                                                        
~                                                                                                                                                                        
~                                                                                                                                                                        
~                                                                                                                                                                        
~                                                                                                                                                                        
~
ASKER CERTIFIED SOLUTION
kaufmed

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
kaufmed

Alternatively, you can initialize the variable inline:

use warnings;
use strict;
use 5.010;

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

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23