Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub buildList
- {
- my ($name,$gender,$father,$mother,$age);
- my %bear_ref=();
- open IN, "<input.txt" or die "can't open file";
- while(<IN>) {
- ($name, $gender, $father, $mother, $age ) = split(/:/);
- $bear_ref{ $name } { 'gender' } = $gender;
- $bear_ref{ $name } { 'mother' } = $father;
- $bear_ref{ $name } { 'father' } = $mother;
- $bear_ref{ $name } { 'age' } = $age;
- }
- close IN;
- return %bear_ref;
- }
- for my $name (keys %$ref) {
- $father= $ref->{ $name }->{ 'father'}; # works
- $mother= $ref->{ $name }->{ 'mother'}; # works
- getTree($name, $ref);
- }
- sub getTree
- {
- my $bear = shift;
- my $ref = shift;
- my ($father, $mother);
- $father= $ref->{ $name }->{ 'father'}; # doesn't work...have also tried with %$ref->
- $mother= $ref->{ $name }->{ 'mother'}; # doesn't work...have also tried with %$ref->
- print "$father : $mothern";
- }
- sub getTree
- {
- my $bear = shift;
- my $ref = shift;
- my ($father, $mother);
- ## note that I am using $bear instead of $name since $name is not defined
- $father= $ref->{ $bear }->{ 'father'};
- $mother= $ref->{ $bear }->{ 'mother'};
- print "$father : $mothern";
- }
Add Comment
Please, Sign In to add comment