Wizards,
I have several subs that have a common foreach loop in the code. What I'd like to do is pull the loop out into a separate subroutine to save typing. What's hanging me up is that I don't know how to pass a WMI thingy as a subroutine argument. Here's the code with some comments illustrating what I need to do...
sub get_stuff {
my %args = ( -this_stuff => undef,
@_
);
my (@inner_ary, @outer_ary, $idx);
$idx = 0;
# $colItems is what I'd like to pass to the new sub
my $colItems = $objWMICodec->ExecQuery( "Select *
From Win32_CodecFile" );
# begin code to replace with sub call
foreach my $objItem (in $colItems) {
# create date strings and Yes/No values for variables (omitted)
push( @inner_ary, uc( $objItem->Name ) ); # $inner_ary[0]
push( @inner_ary, $objItem->Manufacturer ); # $inner_ary[1]
push( @inner_ary, $objItem->Version ); # $inner_ary[2]
push( @inner_ary, $objItem->Description ); # ...
push( @inner_ary, $objItem->FileType );
push( @inner_ary, $objItem->FileSize );
push( @inner_ary, $objItem->Group );
push( @inner_ary, $strCreationDate );
push( @inner_ary, $strInstallDate );
push( @inner_ary, $strLastModified );
push( @inner_ary, $strCompressed );
push( @inner_ary, $strEncrypted );
push( @inner_ary, $strHidden ); # $inner_ary[12]
$outer_ary[$idx++] = [ @inner_ary ];
@inner_ary = ();
}
# end code to replace with sub call
return( @outer_ary );
}
I know this is probably an elementary question, but some parts of my Perl knowledge are still a bit, er, weak.
TIA!
Deane Rothenmaier
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
