OldMonkRum has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

In Getopt I have "tlef:s@" => \$optsHash->{tlef}, which could be single or array. I moved to 5.20.2

if($self->{tlef}){ if(@{$self->{tlef}}) {

If tlef is defined once then I want to check if its an array. Previously if if(defined @{$self->{tlef}}) { was working. Now its deprecated, so if I remove define, I get the cant use string as ref issue. Is there an easy way to check if the command line option from GetOpt is array or single element?

Regards.

Replies are listed 'Best First'.
Re: Can't use string as an ARRAY ref
by kcott (Archbishop) on Oct 07, 2015 at 06:24 UTC

    G'day OldMonkRum,

    Welcome to the Monastery.

    The builtin ref() function is what you want here.

    — Ken

      Hi Ken,

      Thanks a bunch, ref($self->{tlef}) eq "ARRAY" worked like a charm

      Regards

        You're welcome.

        You somehow submitted your thanks twice. Don't worry. Nothing for you to do. I've requested for the second one to be removed. It will disappear in due course.

        — Ken