While refactoring some code with the usual desire to improve/simplify, I came by this interesting example on S.O. that uses the dispatch table structure:
ref _ https://stackoverflow.com/questions/844616/obtain-a-switch-case-behaviour-in-perl-5
my $switch = { 'case1' => sub { print "case1"; }, 'case2' => sub { print "case2"; }, 'default' => sub { print "unrecognized"; } }; $switch->{$case} ? $switch->{$case}->() : $switch->{'default'}->(); #($switch->{$case} || $switch->{default})->() # ephemient's alternative
Dispatch tables are powerful and I use them often.
Gabor Szabo offered a post with an example of given/when, but in the end he suggests just using the if/else construct.
given ($num) { when ($_ > 0.7) { say "$_ is larger than 0.7"; } when ($_ > 0.4) { say "$_ is larger than 0.4"; } default { say "$_ is something else"; } }
ref _ https://perlmaven.com/switch-case-statement-in-perl5
= = =
Which approach do you prefer? Or do you prefer some other solution? Saying no to all the above is a viable response too.
submitted by /u/singe
[link] [comments]
Obtain a switch/case behaviour in Perl 5
Is there a neat way of making a case or switch statement in Perl 5?. It seems to me they should include a switch on version 6. I need this control structure in a script, and I've heard you can impo...Stack Overflow
Why? (It is on Linux and with utf-8)
submitted by /u/appomsk
[link] [comments]
perl -CADS -le 'print $ARGV[0]' -- -v=αβγ -v=αβγ perl -CADS -sle 'print $v' -- -v=αβγ αβγ
submitted by /u/appomsk
[link] [comments]
submitted by /u/niceperl
[link] [comments]
[link] [comments]
(dviii) 11 great CPAN modules released last week
Updates for great CPAN modules released last week. A module is considered great if its favorites count is greater or equal than 12. App...niceperl.blogspot.com
Are there new modern alternatives to PerlNET? I am using a Perl game automation library whose ui is built with Wx using Perl bindings. I want to create my own UI using C#(WPF) so wanted to kno if there are existing solutions to this?
submitted by /u/vizim
[link] [comments]
submitted by /u/briandfoy [link] [comments] |
- YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.www.youtube.com