patgas has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Foreach-ing an OLE Collection object
by cacharbe (Curate) on Aug 09, 2001 at 16:42 UTC | |
|
Re: Foreach-ing an OLE Collection object
by John M. Dlugosz (Monsignor) on Aug 09, 2001 at 07:28 UTC | |
|
Re: Foreach-ing an OLE Collection object
by patgas (Friar) on Aug 09, 2001 at 21:31 UTC | |
by cacharbe (Curate) on Aug 09, 2001 at 23:12 UTC |