473,388 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Accessing Hash Elements

Would anyone happen to know why i'm getting an error with the following code?

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/perl
  3. use strict;
  4. use warnings;
  5.  
  6. $family_name{"fred"} = "astaire"; 
I get the following error

syntax error at filename.plx, near "$family_name{"
Execution of filename.plx aborted due to compilation errors.

and when i try

Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/perl
  3. use strict;
  4. use warnings;
  5.  
  6. @family_name{"fred"} = "astaire"; 
It says Scalar value @family_name{"fred"} better written as $family_name{"fred"} at filename.plx syntax error at filename.plx, near @family_name{"

Why is Perl Contradicting itself?

Thanks In Advance!
Jan 7 '08 #1
2 1329
eWish
971 Expert 512MB
You first need the hash. Then you can add elements to it.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my %family_name = ();
  7.  
  8. $family_name{'fred'} = 'astaire';
  9. print $family_name{'fred'};
Jan 7 '08 #2
You first need the hash. Then you can add elements to it.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my %family_name = ();
  7.  
  8. $family_name{'fred'} = 'astaire';
  9. print $family_name{'fred'};
Thanks!! Sometime programming just gets me riled up when i discover silly mistakes
Jan 7 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
4
by: Simone Battagliero | last post by:
I wrote a program which inserts and finds elements in an hash table. Each element of the table is a dinamic list, which holds all elements having the same hash value (calculated by an int...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
9
by: Whybother | last post by:
I have 82,160 3 number combinations (non repeating, like one set of 1,2,3 ; not like 1,2,2) that I'd like create hash keys for with out collision, if possible. I tried SuperFastHash and when I...
38
by: djhulme | last post by:
Hi, I'm using GCC. Please could you tell me, what is the maximum number of array elements that I can create in C, i.e. char* anArray = (char*) calloc( ??MAX?? , sizeof(char) ) ; I've...
21
by: Hallvard B Furuseth | last post by:
Is the code below valid? Generally a value must be accessed through the same type it was stored as, but there is an exception for data stored through a character type. I'm not sure if that...
13
by: Iris83 | last post by:
Hi, I have a question about converting some of the data in my dataset but leave some data the way it is. I have a hash and if the key is present and the Value of the Hash equals B it should...
11
by: xz | last post by:
>From the reference of MSDN about hash map: operator Inserts an element into a hash_map with a specified key value. And such example is given: hash_map <int, inthm1; hm1 = 40;
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.