Markham, Richard wrote:
> Kester, I used your suggestions. The following code:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> #! /usr/local/bin/perl
What on earth do you have against a 'use strict;' placed right here in your code ?
Having one would have produced:
Global symbol "%people" requires explicit package name at ...
Global symbol "%people" requires explicit package name at ...
Global symbol "%people" requires explicit package name at ...
Which would have taken you to the 3 changes below to correct
your de-referencing of $people :
> use Data::Dumper;
> my @PERSON;
>
> push @PERSON,
> new_person(name => "JOE",
> nums => [ "25","30","1" ],
> weight => "150"),
> new_person(name => "DAVE",
> nums => [ "29","52","46" ],
> weight => "190"),
> new_person(name => "CAROL",
> nums => [ "22","32" ],
> weight => '120');
>
>
> if (grep { $_->{name} eq "DAVE" } @PERSON) {
> print "DAVE exists\n";
> }
> else {
> print "DAVE does not exist\n";
> }
>
> foreach my $people (@PERSON) {
> print "52 exists" if grep { $_ eq '52' } @{$people{nums}};
print "52 exists\n" if grep { $_ eq '52' } @{$people->{nums}};
> print "Im looping.\n";
> print join (' ',@{$people{nums}});
print join (' ', @{$people->{nums}}), "\n";
> print @{$people{nums}};
print @{$people->{nums}}, "\n";
> }
>
> print Dumper(@PERSON);
>
> sub new_person {
> my %p = @_;
> my %r_person;
> my @fields = qw/name nums weight/;
> @r_person{ @fields } = @p{ @fields };
> return \ %r_person;
> }
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> produces the following output:
>
> DAVE exists
> Im looping.
> Im looping.
> Im looping.
> $VAR1 = {
> 'weight' => '150',
> 'name' => 'JOE',
> 'nums' => [
> '25',
> '30',
> '1'
> ]
> };
> $VAR2 = {
> 'weight' => '190',
> 'name' => 'DAVE',
> 'nums' => [
> '29',
> '52',
> '46'
> ]
> };
> $VAR3 = {
> 'weight' => '120',
> 'name' => 'CAROL',
> 'nums' => [
> '22',
> '32'
> ]
> };
>
> Im still stuck on why neither logic against the values or trying to print
> the array values is working. I'm reading over perltoot as we speak,
> but I'm curious if OO is going to be required to solve this baseline
> issue that I have here. Sorry to drag this out so long, but this seems
> like it should work.
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (Free site for Perl/Lakers)
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs