Fellow Monks

Got the green light to convert everything (i.e. scripts) that I can and is possible into Perl :-)

The first batch I have started with are mainly FSO/Wsh based scripts. Below is my code:
#! c:/perl/bin/perl.exe -slw $|++; AUTOLOAD; require 5.008; use strict; use warnings 'all'; use Win32; use Win32::OLE; my $fso = Win32::OLE->new( 'Scripting.FileSystemObject' ); Win32::OLE->Option( Warn => 0 ); my $file = $fso->GetFile("c:\\perl\\bin\\perl.exe"); for my $key (keys %{$file}) { print "$key : $file->{$key}\n"; }
And this was the output I got back:
C:\Perl\FSO>archive.pl Path : C:\Perl\bin\perl.exe Name : perl.exe ShortPath : C:\perl\bin\perl.exe ShortName : perl.exe Drive : Win32::OLE=HASH(0x1a4a3d0) ParentFolder : Win32::OLE=HASH(0x1a4a3ac) Attributes : 32 DateCreated : Win32::OLE::Variant=SCALAR(0x1a4a3dc) DateLastModified : Win32::OLE::Variant=SCALAR(0x1a4a358) DateLastAccessed : Win32::OLE::Variant=SCALAR(0x1a4a40c) Size : 41033 Type : Application C:\Perl\FSO>
What I am after are the date attributes, however I wondering is there away I can decode those variant (i.e. print out the human readble dates) on the same line or on the fly as per say?

Thanks alot.

########### UPDate #########

I just added this
use Win32::OLE::Variant;
And got the human readable date format. Thanks for listening

########### Update 2 ##########

sorry chaps, still have some issues

This is what I changed the code to:
#! c:/perl/bin/perl.exe -slw $|++; AUTOLOAD; require 5.008; use strict; use warnings 'all'; use Win32; use Win32::OLE; use Win32::OLE::Variant; my $fso = Win32::OLE->new( 'Scripting.FileSystemObject' ); Win32::OLE->Option( Warn => 0 ); my $file = $fso->GetFile("c:\\perl\\bin\\perl.exe"); for my $key (keys %{$file}) { if ( $key eq 'Drive') { for (keys %{$key->{'Drive'}}) { print "$_ \n"; } } elsif ($key eq 'ParentFolder') { for (keys %{$key->{ParentFolder}}) { print "$_ \n"; } } else { print "$key : $file->{$key}\n"; } }
and this is the error I got back:
C:\Perl\FSO>archive.pl Path : C:\Perl\bin\perl.exe Name : perl.exe ShortPath : C:\perl\bin\perl.exe ShortName : perl.exe Can't use string ("Drive") as a HASH ref while "strict refs" in use at + C:\Perl\F SO\archive.pl line 22. C:\Perl\FSO>
So I am having problems decoding and OLE hash!

Can I get some enlightment here please on how can decod, on the fly again if poss, this OLE hash?

Thanks for the Help

Blackadder

In reply to Decoding OLE::Variant by blackadder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.