Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

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


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 20, 2003 at 03: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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found