in reply to Re: Text Analysis: given(){when(){}} block throws a 'useless use of private variable...etc' error
in thread Text Analysis: given(){when(){}} block throws a 'useless use of private variable...etc' error
I'm quessing $_ is the private variable which is not used.If given takes a single variable or value and yet quite interesting still, it actually works with two values, even with three values as I tried it in the following demo, that means it is a very strong function that we probably need to develop more for us to avail of its full capacity in Perl 5.
Thinking about if we can have an embedded given(){when(){}} to make it accept two arguments is out of the question since that may lead to a labyrinth of brain-damaging curlies but maybe just keeping track of the arguments passed to given in @_ may provide a path to beat if that can be possible...
Notice that the last 2 when blocks are both true however, the first one in order which evaluates to true is the one that gets its print statement executed and the second one is totally ignored, perambulation of the when blocks can testify to that...use strict; use warnings; use feature qw(switch); my $foo = 'foo'; my $bar = 'bar'; my $baz = 'baz'; given($foo, $bar, $baz){ when($foo eq 'check' and $bar eq 'treck'){print "nei +ther is standard\n";} when($foo eq 'foo' and $bar eq 'treck'){print "$foo +is standard\n";} when($foo eq 'check' and $bar eq 'bar'){print "$bar +is standard\n";} when($foo eq 'foo' and $bar eq 'bar' and $baz eq 'ba +z'){print "All are standard\n";} when($foo eq 'foo' and $bar eq 'bar'){print "both ar +e standard\n";} }
The reason I used a switch statement is because I wanted to clean up my code from the if else pollution in a quick way and the switch is a very neat way to do so, also, the values assigned to '' are going to be needed in another extension to the original code ergo the $var ||= '' statement.
Checking perlsyn for clues..
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Text Analysis: given(){when(){}} block throws a 'useless use of private variable...etc' error
by TomDLux (Vicar) on Oct 18, 2010 at 19:05 UTC |