Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: question about variables from new perl user

by Apero (Scribe)
on Dec 01, 2015 at 01:38 UTC ( [id://1148985]=note: print w/replies, xml ) Need Help??


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
    Thank you everybody,
    choroba, it takes a little bit of time to wrap my mind around the idea that an array with with numerical indices and one with alphanumeric indices are different. None of C/C++ and PHP are like that. I will have to get used to that.
    Apero and Grandfather, thank you for the explanation of what is going on , the right way to do things, and the warnings.
    Cristoforo, thank you for your insight. sometimes you learn a lot from breaking the rules. (and sometimes you learn fire is hot and it can burn ;) )
    Thanks again,
    Ray

      Actually C only has indexed arrays. PHP only has associative arrays. C++ has both with indexed arrays as first class citizens (inherited from C) and associative arrays supplied as part of the standard template library. Perl has both as first class citizens.

      Premature optimization is the root of all job security

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1148985]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-18 10:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found