For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > October 2006 > add array element to hash...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author add array element to hash...
onlineviewer

2006-10-21, 9:57 pm

Hello All,

I am not sure what the problem is here. I am trying to add the elements
of an array to a hash. But i keep getting only the first array element
into the hash
Any suggestions? Thanks,,.

my @newfiles = `find /tmp -type f -mmin -10`;
my $size = @newfiles;
my %hash;
my $var;
my $newfiles;

if($size > 0){
foreach $var(@newfiles){
chomp $var;
unless(defined($hash{$newfiles[$var]})){

$hash{$newfiles[$var]} = 1;
}
}
}

while (my ($key, $value) = each %hash ) {
print "$key => $value\n";
}

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com