Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

by dada (Chaplain)
on Dec 19, 2003 at 17:12 UTC ( #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 :-)


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?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2022-01-26 04:40 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (69 votes). Check out past polls.