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

Hi all,

by chance i stumbled over this:

#!/usr/bin/env perl # http://perlmonks.org/?node_id=1196297 # $Id: wantarray.pl,v 1.4 2017/07/30 10:03:17 karl Exp karl $ use strict; use warnings; use Try::Tiny; use Getopt::Long; use feature qw(say); my $flag; GetOptions( "flag" => \$flag ) or die(qq(Fubar\n)); my $array = [ 1 .. 10 ]; say join "|", @$array; say join "|", nose($array); try { ($flag) ? say join "|", nose() : nose(); } catch { warn $_; }; sub nose { my $array = shift; map { --$_ } @$array; die "Jackass!" unless defined wantarray; (wantarray) ? @$array : $array; } __END__

I tried to reduce the problem as much as i could.

And perhaps i have one these famous mental blocks again.

Thanks for any hint and best regards, Karl

«The Crux of the Biscuit is the Apostrophe»

perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Replies are listed 'Best First'.
Re: "Try join say" or why is this exception not caught?
by shmem (Chancellor) on Jul 30, 2017 at 11:24 UTC

    I can't see where the exception is not caught. If $flag is not defined, I am told being a jackass (which might otherwise be true) because nose() is called in void context. What exception condition am I overlooking? Which isn't caught? The try block outputs an empty string when $flag is set, because nose is called without argument. Where is the problem? am I having one these famous mental blocks again?

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      "I can't see...condition am I overlooking..."

      Yes. I was a bit blind this morning. Probably too much paella last night...

      Thank you very much and best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: "Try join say" or why is this exception not caught?
by haukex (Archbishop) on Jul 30, 2017 at 10:43 UTC
    why is this exception not caught?

    If I change warn $_; to warn "Caught: $_";, it seems to show that the exception is caught?

      Hi haukex, unfortunately this isn't the case... Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

      perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

        When I make the above modification, and change the two calls of nose() to nose($array) (to see it get called), I get this output:

        $ perl 1196297.pl 1|2|3|4|5|6|7|8|9|10 0|1|2|3|4|5|6|7|8|9 Caught: Jackass! at 1196297.pl line 32. $ perl 1196297.pl --flag 1|2|3|4|5|6|7|8|9|10 0|1|2|3|4|5|6|7|8|9 -1|0|1|2|3|4|5|6|7|8

        Are you expecting something else, or are you getting different output?