in reply to Tring to write script to add and get employee detials to hash
Have a look at "hashes of arrays" in perldsc, that gives lots of code examples on how to access data structures like that, and see also perlreftut. For example:
my %database; my $employee_id = 961; my $employee_name = "Anonymous Monk"; my $employee_salary = "fun"; my $employee_ph = 5.5; my @employee_details = ($employee_name,$employee_salary,$employee_ph); $database{$employee_id} = \@employee_details; print "$database{961}[0]: $database{961}[1]\n"; __END__ Anonymous Monk: fun
(Why is "\n" part of the employee's details in your code?)
But then again, this kind of data seems more appropriately stored in a hash of hashes (also described in perldsc):
my %database; my $employee_id = 961; $database{$employee_id} = { name => "Anonymous Monk", salary => "fun", ph=> 5.5 }; print "$database{961}{name}: $database{961}{ph}\n"; __END__ Anonymous Monk: 5.5
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Tring to write script to add and get employee detials to hash
by yedukondalu (Acolyte) on Mar 27, 2015 at 13:58 UTC | |
by Anonymous Monk on Mar 27, 2015 at 14:51 UTC | |
by jeffa (Bishop) on Mar 27, 2015 at 16:30 UTC | |
by Anonymous Monk on Mar 27, 2015 at 17:31 UTC | |
by Anonymous Monk on Mar 29, 2015 at 19:44 UTC |