On Oct 3, 10:03 am, [EMAIL PROTECTED] (Matej Cepl) wrote: > I have a script for archiving email messages on IMAP (whole code > is available athttp://mcepl.fedorapeople.org/tmp/archiveIMAP.pl). I go through > all messages in one source folder and put all of those which > I want to archive to hash indexed by the target folder: > > ... > $targetFolder = getTargetFolder($folder,$msgYear); > push ( @{ $targetedMessages{$folder} } , $msg); > ... > > and then just go through the hash and actually move all messages > which should go to one target folder: > > foreach my $tFolder (keys %targetedMessages) { > if (!($imap->exists($tFolder))) { > $imap->create($tFolder) > or die "Could not create $tFolder: [EMAIL PROTECTED]"; > } > $imap->move($tFolder,[EMAIL PROTECTED]); > } > > EPIC complains about the @-sign in the last line of this snippet > -- that I should use $-sign when trying to slice the array. But > I am not trying to slice an array (at least I hope). Just > following perldsc(1) I am trying to get whole array and use it as > a parameter of the method move. > > Who's wrong? Me or EPIC?
You. %targetedMessages is a hash $targetedMessages{$tFolder} is an element of that hash, that happens to be a reference to an array. @{$targetedMessaages{$tFolder}} would be the array that $targetedMessages{$tFolder} references. if you were to put a slash in front of that, you'd have yet another reference to this same array. But of course there is no need to do that, as $targetedMessages{$tFolder} is already a reference to the array. @targetedMessages{$tFolder} is a one-element slices of the hash %targetedMessages. It is the list containing ( $targetedMessages{$tFolder} ). Since you can't take a reference to a slice, the \ instead does the same thing it does to any other list - returns a list of references to the list elements. You are therefore getting back a reference to $targetedMessages{$tFolder}, which is itself already a reference. And you are trying to pass that array-reference-reference as a parameter. If you want to pass a reference to the array, use $targetdMessages{$tFolder} If you want to dereference the reference and pass the array elements, use @{$targetdMessages{$tFolder}} Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/