Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw


by mbayer (Novice)
on Apr 11, 2005 at 14:28 UTC ( [id://446614]=perlquestion: print w/replies, xml ) Need Help??

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

Bascially I want to know if there is an operator that I can use to make the following conditional true. Can I take the Win32::OLE->LastError() and just check it to be true, kinda like a boolean? Or do i have to assign it to a $variable and build my conditional off of that?? Please take it easy on me, new to programming.
if(Win32::OLE->LastError()=="true"){ #In case of error print Win32::OLE->LastError()."\n"if(Win32::OLE->LastError()); } else{ print "Virtual Directory Create successfully with out Errors!\n"; }

20050411 Edit by ysth: code tags

Replies are listed 'Best First'.
Re: Boolean??
by Taulmarill (Deacon) on Apr 11, 2005 at 14:33 UTC
    let perl do that for you:
    if ( Win32::OLE->LastError() ) { print Win32::OLE->LastError(), "\n"; } else { print "Virtual Directory Create successfully with out Errors!\n"; }
Re: Boolean??
by cog (Parson) on Apr 11, 2005 at 14:36 UTC
    Judging from the documentation on Win32::Ole:

    The LastError() class method returns the last recorded OLE error.


    The last OLE error is automatically reset by a successful OLE call.

    I'd say that LastError returns a true value if there was an error. If that is true, you can write:

    if (Win32::OLE->LastError()) { print "Virtual directory was not created ($!).\n"; } else { print "Virtual directory created successfully.\n"; }

    I might be wrong, because I've never used Win32::Ole, but if I am, I'm sure somebody will correct me.

      That did it, thank you very much. Perl is very generous off the bat with alot of functionality that you would have to build/call like with Java/C/C++... Thanks.
Re: Boolean??
by ysth (Canon) on Apr 11, 2005 at 16:20 UTC
    A Boolean context doesn't have to take only a comparison (==, !=, <, >=, etc.). Any value (including the value returned by LastError()) can be tested for truth. perldoc perldata says:
    A scalar value is interpreted as TRUE in the Boolean sense if it is not the null string or the number 0 (or its string equivalent, "0"). The Boolean context is just a special kind of scalar context where no conversion to a string or a number is ever performed.
    See What is true and false in Perl? for a longer discussion.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://446614]
Approved by Corion
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2024-04-19 08:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found