Guest User

Untitled

a guest
Jan 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. sub buildList
  2. {
  3. my ($name,$gender,$father,$mother,$age);
  4. my %bear_ref=();
  5.  
  6. open IN, "<input.txt" or die "can't open file";
  7.  
  8. while(<IN>) {
  9. ($name, $gender, $father, $mother, $age ) = split(/:/);
  10. $bear_ref{ $name } { 'gender' } = $gender;
  11. $bear_ref{ $name } { 'mother' } = $father;
  12. $bear_ref{ $name } { 'father' } = $mother;
  13. $bear_ref{ $name } { 'age' } = $age;
  14. }
  15. close IN;
  16. return %bear_ref;
  17. }
  18.  
  19. for my $name (keys %$ref) {
  20. $father= $ref->{ $name }->{ 'father'}; # works
  21. $mother= $ref->{ $name }->{ 'mother'}; # works
  22. getTree($name, $ref);
  23. }
  24.  
  25. sub getTree
  26. {
  27. my $bear = shift;
  28. my $ref = shift;
  29. my ($father, $mother);
  30. $father= $ref->{ $name }->{ 'father'}; # doesn't work...have also tried with %$ref->
  31. $mother= $ref->{ $name }->{ 'mother'}; # doesn't work...have also tried with %$ref->
  32. print "$father : $mothern";
  33.  
  34. }
  35.  
  36. sub getTree
  37. {
  38. my $bear = shift;
  39. my $ref = shift;
  40. my ($father, $mother);
  41. ## note that I am using $bear instead of $name since $name is not defined
  42. $father= $ref->{ $bear }->{ 'father'};
  43. $mother= $ref->{ $bear }->{ 'mother'};
  44. print "$father : $mothern";
  45. }
Add Comment
Please, Sign In to add comment