Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Fun with Prototypes

by haukex (Canon)
on Jul 19, 2017 at 11:54 UTC ( #1195441=perlmeditation: print w/replies, xml ) Need Help??

Can you tell me:

  1. How does this get parsed? (e.g. try adding parentheses to show precedence)
  2. Given that the body of each of the four subs is { print Dumper(\@_) }, what is the output?
$_ = "#x"; my @a = qw/b c/; foo /#(\w+)/, @a; bar /#(\w+)/, @a; quz /#(\w+)/, @a; baz /#(\w+)/, @a;

Hint:

Solution:

Replies are listed 'Best First'.
Re: Fun with Prototypes
by LanX (Bishop) on Jul 19, 2017 at 21:37 UTC
    I think you shouldn't hide the "hint", or at least rename it to "missing info".

    Hint implies that it's already solvable.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      Thanks for the comments, and I did think about it - but I think I want to keep the "trick question" aspect of the node for now ;-)

      Also thank you for your other replies, that's certainly getting pretty tricky with the parsing!

Re: Fun with Prototypes
by LanX (Bishop) on Jul 19, 2017 at 21:45 UTC
    More fun for you: ;)

    Some people want debug functions to disappear without footprint in production.

    Like with Smart::Comments but without source filter.

    Try to find a way where changing the prototype of a function &dmp will turn the call to a no op.

    Your bar /#(\w+)/, @a; is already quite close, but it's still involving a division. :)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      Isn't this sufficiently clear?

      use constant DEBUG => 0; use Data::Dumper; # ... warn Dumper($myvar) if DEBUG;

      Or PerX::Assert.

        > Isn't this sufficiently clear?

        > ...

        > warn Dumper($myvar) if DEBUG;

        clear but unnecessarily verbose.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

      an example avoiding a sub-call, unfortunately the division in void context is not optimized away.

      and the warning will create runtime overhead, too :/

      update
      But I think a little overhead is acceptable when debugging.

      another edge case are empty arrays causing a division by zero...

      update:

      fixed minor bug

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

Re: Fun with Prototypes
by Laurent_R (Canon) on Jul 19, 2017 at 14:16 UTC
    I don't quite understand what you're after, but you can check this module: B::Deparse

    Update: Sorry haukex, the spoilers did not work when I first tried to click on them. Now that I can see them, I understand your point.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1195441]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2018-10-22 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (119 votes). Check out past polls.

    Notices?