in reply to Re: (jeffa) Re: When I try to create different objects i end up getting the same one over and over...
in thread When I try to create different objects i end up getting the same one over and over...

I thought about why you chose a hash and didn't see the benefit. I guess i need to see your requirements first before making that judgement, but again, my point was to show you how to get the most out of Perl - how to break away from C-style coding.

The resulting data structure is an array reference. This may not be what you want, however. Check this out (assuming your data file):

$_->dump_os for @agents; # yields: $VAR1 = [ 'SUN', 'Solaris 8' ]; $VAR1 = [ 'IBM', 'AIX 4.3.3' ]; # etc.
Again, since i really do not know what your target is, i had to improvise. Now is the time when i wish i could be at your computer ... but alas ... if you want to continue this disussion, let's work via /msg and scratchpad's - no need to waste database space. ;)

UPDATE:
After some discussion via /msg's, i feel that storing the os's in a hash is not necessary at all. If you store them in an array reference as i have done, you can test for a particular OS by using grep. Here is an example:

foreach (@agents) { $_->dump_os if grep /AIX/, @{$_->{os}}; }
Of course, you could also grep a hash, but that seems a bit like using a square on a round hole to me. ;) Good luck!

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
  • Comment on (jeffa) 3Re: When I try to create different objects i end up getting the same one over and over...
  • Select or Download Code

Replies are listed 'Best First'.
Re: (jeffa) 3Re: When I try to create different objects i end up getting the same one over and over...
by krujos (Curate) on Apr 26, 2002 at 20:17 UTC
    jeffa thank you so much for your help, you have been great. I have been playing around with this a little more this afternoon, there is one thing I cant figure out. How do I refrence a specific element in os now? thanks Josh
      So much for not wasting database space! :D

      Easy, let's say that i want to print the third object's second 'os' element. Piece of cake:

      print $agents[2]->{os}->[1], "\n"; # or more succinctly print $agents[2]{os}[1], "\n";
      Read up on perlreftut and perlref for more info.

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)