I've got the following code that loops through my Outlook inbox and saves out the attachments (shortened for brevity's sake:
my $namespace = $outlook->GetNameSpace("MAPI"); my $folder = $namespace->GetDefaultFolder(olFolderInbox); for ( my $i = 1; $i <= $folder->Items->Count; $i++ ) { for ( my $j = 1; $j <= $folder->Items($i)->Attachments->Count; $j+ ++ ) { print "Saving " . $folder->Items($i)->Attachments($j)->FileNam +e . " from \"" . $folder->Items($i)->Subject . "\"\n"; $folder->Items($i)->Attachments($j)->SaveAsFile( "C:\\Download +\\" . $folder->Items($i)->Attachments($j)->FileName ); } }
Now, this works and all, but it seems like it could be cleaned up using foreach loops instead of those nasty index variables. I attempted various things like this:
foreach my $item ( $folder->Items ) { foreach my $attachment ( $item->Attachments ) { print "Saving " . $attachment->FileName . " from \"" . $item-> +Subject . "\"\n"; $attachment->SaveAsFile( "C:\\Download\\" . $attachment->FileN +ame ) ; } }
I tried saving out the collections to other variables, to lists, I tried using curly brackets around the various properties, I even tried using this mysterious "in" operator that showed up in Win32::OLE, and that didn't work either. Anyone have suggestions?
-- More than perfect! Let us engage the Concord!In reply to Foreach-ing an OLE Collection object by patgas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |