Kadjo

SoftDev Journal

About This Journal

24 June 2007 by Jojo Makiling

Technical concerns tend to find a solution as long as there are good people working on them. And Linux has the very best. - Linus Torvalds

Perl: Appending array in a hash element

December 31st, 2008 by pepesmith

My code :
push($parentmenu{$parentkey}{childlist},[$childmenu{$childid}{name},$childmenu{$childid}{link}]);

Gives me this error.

Type of arg 1 to push must be array (not hash element) at ./test.cgi line 34, near “])”
Execution of ./test.cgi aborted due to compilation errors.

And it was just resolved by adding the @ and enclose it with {} – see the code below. I need an explanation though, but I’ll have to find the explanation later, for the meantime the solution just worked for my task.

push(@{$parentmenu{$parentkey}{childlist}},[$childmenu{$childid}{name},$childmenu{$childid}{link}]);

Posted in Miscellaneous | No Comments »