Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
P is for Practical
 
PerlMonks  

Re: Is "ref $date eq 'ARRAY'" wrong?

by dada (Chaplain)
on Dec 19, 2003 at 12:12 UTC ( [id://315843]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Is "ref $date eq 'ARRAY'" wrong?

maybe I'm totally out of track (it's been a long and hard week :-), but I would go with something like:
$date = (ref $date =~ /ARRAY/) ? $date : [ split(/\D+/, $date) ];
it is safe enough, I think, to treat the reference as an array if it "implements" an array (eg. if it's something like Foo::Bar=ARRAY(0xdeadbeef)) the same way it is safe enough to call $object->{property} when $object is something like Foo::Bar=HASH(0xdeadbeef).

don't know, however (I don't have time to check now), if this works for tied arrays.

someone correct me please if I'm wrong :-)

cheers,
Aldo

King of Laziness, Wizard of Impatience, Lord of Hubris

Replies are listed 'Best First'.
Re: Re: Is "ref $date eq 'ARRAY'" wrong?
by gmpassos (Priest) on Dec 19, 2003 at 22:24 UTC
    Humm, you are making 2 things wrong!

    Take a look in this code:

    package foo ; my $bless = bless({},foo); print "AS STRING: $bless\n" ; print "AS REF: ". ref($bless) ."\n" ; __END__ ## OUTPUT: AS STRING: foo=HASH(0x1a7f04c) AS REF: foo
    ref just return in what package the object is blessed or the data type of the reference. If you want to know if the blessed reference is an ARRAY, HASH, SCALAR... you can use:
    if ( UNIVERSAL::isa($bless , 'HASH') ) { print "mohhh\n" ; }
    And forget the REGEXP for that!

    Graciliano M. P.
    "Creativity is the expression of the liberty".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://315843]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.