Replacing deprecated “defined(@array)” in a ternary operation

后端 未结 3 1217
南笙
南笙 2021-01-28 01:07

I have the following code which needs to be corrected, as defined(@array) is deprecated in the latest Perl.

my @inputs = (
    ( defined @{$padSrc-         


        
3条回答
  •  情歌与酒
    2021-01-28 01:39

    You do not say what Perl version you use, so the following may work (if using Perl 5.10 or later) or not (if you are stuck with older versions), and since it is not very clear why you used defined in the first place:

     my @inputs = (
        @{$padSrc->{inouts} // []},
        @{$padSrc->{inputs} // []}
    );
    

    or even simpler:

    my @inputs = map { @{$padSrc->{$_} // []} } qw/inouts inputs/;
    

提交回复
热议问题