in reply to Re: question about variables from new perl user
in thread question about variables from new perl user
I couldn't find documentation on accessor methods
Right, because a True/False boolean value does not have methods. The fact that LWP::Simple::head() returns an object is an undocumented side-effect as the API is described. Do not rely on this to be an object (and thus do not rely on any data in the object, object methods, accessors, and so on.)
As I commented on earlier, I ventured a guess this class returned an object out of simplicity or convenience. The LWP::Simple class docs, however, are very clear that you get a "TRUE" (sic) value back from the function call. It's highly unwise to use it as a constructor.
If you want to know what type an object is (and can't otherwise tell from documentation, which is where you should go to look for that fact,) you can do so with the ref() built-in call, like so:
require LWP::Simple; my $fake_boolean = LWP::Simple::head( "http://google.com" ); printf "fake_boolean variable is a reference to: %s\n", ref($fake_boolean) || "<not-a-reference>";
Big fat warning: do not use this function's return as an object! This is merely a demonstration of how to determine an object's type. Please refer to the LWP documentation on how the object-oriented class is designed and what constructors return what types of objects to avoid unpleasant surprises later.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: question about variables from new perl user
by rst (Initiate) on Dec 01, 2015 at 02:04 UTC | |
by GrandFather (Saint) on Dec 01, 2015 at 04:06 UTC |