premal has asked for the wisdom of the Perl Monks concerning the following question:

Hi I have written following code to read the data from .ism file. Similar way I will write a code to write data in .ism file but my code is failing with an error saying "Can't call method "OpenProject" on an undefined value at C:\Test\Update_ism.pl line 15." Following is the code. Can you please suggest how do I get rid of this.
use Win32::Guidgen; use Win32::OLE; my $guid = Win32::Guidgen::generate(); #Generate GUID for Product code +. # instantiate the Developer Automation interface $dev = Win32::OLE->new("ISWiAutomation.ISWiProject"); # open a project file. $dev->OpenProject("C:\\InstallShield 2010 Projects\\Test.ism") or die +"Can not open project file:$!"; print "ProductName: " , $dev->ProductName, "\n", "ProductVersion: ", $dev->ProductVersion, "\n"; # close the project $dev->CloseProject( );

Replies are listed 'Best First'.
Re: Code to write data to installshield project (.ism) file
by BioLion (Curate) on Sep 25, 2009 at 10:38 UTC

    Somebody will say it - use strict and use warnings!

    I would also test for success on lines like :

    $dev = Win32::OLE->new("ISWiAutomation.ISWiProject");

    i.e. :

    $dev = Win32::OLE->new("ISWiAutomation.ISWiProject") || die "Failed to instantiate : Win32::OLE::LastError()";

    It sounds like this is failing, hence $dev is not defined when you come to use it later.

    I could be wrong though, I haven't tested this theory...

    Update: See AM below

    Just a something something...
      Nice, but for Win32::OLE you want $^E or Win32::OLE::LastError();