1847883 Members
5325 Online
104021 Solutions
New Discussion

Re: PERL QUESTION

 
Scott_130
Occasional Advisor

PERL QUESTION

I am stumped and would really appreciate some help from a Perl expert. Any Thoughts?

I am trying to delete not a whole record from a hash but a value in an array inside a hash. I keep getting a "Too Many arguments error"

delete (@{$Expired{$year}->{$lastmon}}, $lastperiod)
3 REPLIES 3
Ron Kinner
Honored Contributor

Re: PERL QUESTION

delete @{$ref->[$x][$y]}{$key1, $key2, @morekeys};

is the example given at:

http://www.perl.com/doc/manual/html/pod/perlfunc/delete.html

so I would try:

delete @{$Expired->[$year][$lastmon]}{$lastperiod};

If that doesn't work try breaking up the expression into smaller parts (and printing them afterwards to verify that they give you what you want). Perhaps a for loop through the array might be easier to handle.

Ron
Rodney Hills
Honored Contributor

Re: PERL QUESTION

Scott,

delete is used to remove hash entries.

You can use "undef" to undefine an array entry.

example-
undef @{$Expired{$year}->{$lastmon}}[$lastperiod]

assuming $lastperiod is an offset into the array.

HTH

-- Rod Hills
There be dragons...
Scott_130
Occasional Advisor

Re: PERL QUESTION

Thanks a lot. I actually solved the problem before you responded however, both seem like they would work fine.

I actaully sorted the hash and used the pop feature:

pop(@{$Expired{$year}->{$lastmon}});