I also did some testing with ActiveState Perl 5.6.1
If you use the flipflopped var in a string, and if there is a space (any whitespace) immediately following the flipflop variable, then it will be flipped twice.
I also tested if concatenating a space causes the same problem (not shown in test code below) and it did not.
Examples:
$f="$flipflop "; doesn't work.
$f="$flipflop\n"; doesn't work.
$f="$flipflop"; works
$f="{$flipflop}_xxx "; works
$f="\n$flipflop"; works
To test this, I modified the tie::flipflop module to print Doing a fetch, with state... everytime the state is flipped.
Note: I used readmore tags around the code and results, but I can't see if they are really working until I create my post. so if they are not, I apologize.
My test script is below
use myFlipFlop;
# original OP code
tie my $flipflop => Tie::FlipFlop => ( 'white', 'black' );
print "="x10,"\n";
print "Original OP Code\n";
print "="x10,"\n";
print qq|$flipflop\n|;
print qq|$flipflop\n|;
print qq|$flipflop\n|;
print qq|$flipflop\n|;
# my tests.
# Thought #1, perl optimizes 'print "$a$b"' by concatenating $a.$b.
# First, remove the 'printing part' and see what happens
# is it related to concatenating strings?
print "\n\n","="x10,"\n";
print "Non-White space after flipflop var\n",
"but white space at end of string\n";
print "="x10,"\n";
print "Setting \$start\n";
my $start = "$flipflop";
print "Setting \$one\n";
my $one = "{$flipflop}_one ";
print "Setting \$two\n";
my $two = "($flipflop}_two_two ";
print "Setting \$three\n";
my $three = "{$flipflop}_three_three_three ";
print "\n\nstart:\t$start\n",
"one:\t$one\n",
"two:\t$two\n",
"three:\t$three\n";
# Result: all of the aboved worked.
# is it related to concatenating strings?
print "\n\n","="x10,"\n";
print "White space immediately after flipflop var\n";
print "="x10,"\n";
print "Setting \$start\n";
my $start = "$flipflop";
print "Setting \$one\n";
my $one = "$flipflop one ";
print "Setting \$two\n";
my $two = "$flipflop two two ";
print "Setting \$three\n";
my $three = "$flipflop three three three ";
print "\n\nstart:\t$start\n",
"one:\t$one\n",
"two:\t$two\n",
"three:\t$three\n";
# Result: all of the aboved worked.
# try multiple \n
# i.e. does each \n cause it to flip?
print "\n\n","="x10,"\n";
print "Using multiple '\\n' immediately after var \n";
print "="x10,"\n";
print "Setting \$start\n";
$start = "$flipflop";
print "Setting \$one\n";
$one = "$flipflop\n";
print "Setting \$two\n";
$two = "$flipflop\n\n";
print "Setting \$three\n";
$three = "$flipflop\n\n\n";
print "\n\nstart:\t$start\n",
"one:\t$one",
"two:\t$two",
"three:\t$three";
# RESULT: Each flipped twice.
# try multiple \n
# i.e. does each \n cause it to flip?
print "\n\n","="x10,"\n";
print "Using multiple '\\n', but not immedieately after flipflop\n";
print "="x10,"\n";
print "Setting \$start\n";
$start = "$flipflop";
print "Setting \$one\n";
$one = "{$flipflop}_one\n";
print "Setting \$two\n";
$two = "{$flipflop}_two_two\n\n";
print "Setting \$three\n";
$three = "{$flipflop}_three_three_three\n\n\n";
print "\n\nstart:\t$start\n",
"one:\t$one",
"two:\t$two",
"three:\t$three";
# RESULT: Each flipped twice.
# try multiple \t
# i.e. does each \t cause it to flip?
print "\n\n","="x10,"\n";
print "Using multiple '\\t' (one on one, two on two, etc)\n";
print "="x10,"\n";
print "Setting \$start\n";
$start = "$flipflop";
print "Setting \$one\n";
$one = "$flipflop\t";
print "Setting \$two\n";
$two = "$flipflop\t\t";
print "Setting \$three\n";
$three = "$flipflop\t\t\t";
print "\n\nstart:\t$start\n",
"one:\t$one\n",
"two:\t$two\n",
"three:\t$three\n";
# RESULT: Each flipped twice.
# RESULT: Same as above.
# How about at the beginning of the var?
# i.e. does each something at begining cause it to flip?
print "\n\n","="x10,"\n";
print "Using something a beginning of var\n";
print "="x10,"\n";
print "Setting \$start\n";
$start = "$flipflop";
print "Setting \$one\n";
$one = "one $flipflop";
print "Setting \$two\n";
$two = "two two $flipflop";
print "Setting \$three\n";
$three = "three three three $flipflop";
print "\n\nstart:\t$start\n",
"one:\t$one\n",
"two:\t$two\n",
"three:\t$three\n";
# How about at the beginning of the var?
# i.e. does each \n cause it to flip?
print "\n\n","="x10,"\n";
print "Using multiple '\\n' at beginning of var\n",
" (one on one, two on two, etc)\n";
print "="x10,"\n";
print "Setting \$start\n";
$start = "$flipflop";
print "Setting \$one\n";
$one = "\n$flipflop";
print "Setting \$two\n";
$two = "\n\n$flipflop";
print "Setting \$three\n";
$three = "\n\n\n$flipflop";
print "\n\nstart:\t$start\n",
"one:\t$one\n",
"two:\t$two\n",
"three:\t$three\n";
#RESULT: Works fine
exit;
and the results are below
Using Sandy's version
==========
Original OP Code
==========
Doing a fetch, with state black white
Doing a fetch, with state white black
black
Doing a fetch, with state black white
Doing a fetch, with state white black
black
Doing a fetch, with state black white
Doing a fetch, with state white black
black
Doing a fetch, with state black white
Doing a fetch, with state white black
black
==========
Non-White space after flipflop var
but white space at end of string
==========
Setting $start
Doing a fetch, with state black white
Setting $one
Doing a fetch, with state white black
Setting $two
Doing a fetch, with state black white
Setting $three
Doing a fetch, with state white black
start: white
one: {black}_one
two: (white}_two_two
three: {black}_three_three_three
==========
White space immediately after flipflop var
==========
Setting $start
Doing a fetch, with state black white
Setting $one
Doing a fetch, with state white black
Doing a fetch, with state black white
Setting $two
Doing a fetch, with state white black
Doing a fetch, with state black white
Setting $three
Doing a fetch, with state white black
Doing a fetch, with state black white
start: white
one: white one
two: white two two
three: white three three three
==========
Using multiple '\n' immediately after var
==========
Setting $start
Doing a fetch, with state white black
Setting $one
Doing a fetch, with state black white
Doing a fetch, with state white black
Setting $two
Doing a fetch, with state black white
Doing a fetch, with state white black
Setting $three
Doing a fetch, with state black white
Doing a fetch, with state white black
start: black
one: black
two: black
three: black
==========
Using multiple '\n', but not immedieately after flipflop
==========
Setting $start
Doing a fetch, with state black white
Setting $one
Doing a fetch, with state white black
Setting $two
Doing a fetch, with state black white
Setting $three
Doing a fetch, with state white black
start: white
one: {black}_one
two: {white}_two_two
three: {black}_three_three_three
==========
Using multiple '\t' (one on one, two on two, etc)
==========
Setting $start
Doing a fetch, with state black white
Setting $one
Doing a fetch, with state white black
Doing a fetch, with state black white
Setting $two
Doing a fetch, with state white black
Doing a fetch, with state black white
Setting $three
Doing a fetch, with state white black
Doing a fetch, with state black white
start: white
one: white
two: white
three: white
==========
Using something a beginning of var
==========
Setting $start
Doing a fetch, with state white black
Setting $one
Doing a fetch, with state black white
Setting $two
Doing a fetch, with state white black
Setting $three
Doing a fetch, with state black white
start: black
one: one white
two: two two black
three: three three three white
==========
Using multiple '\n' at beginning of var
(one on one, two on two, etc)
==========
Setting $start
Doing a fetch, with state white black
Setting $one
Doing a fetch, with state black white
Setting $two
Doing a fetch, with state white black
Setting $three
Doing a fetch, with state black white
start: black
one:
white
two:
black
three:
white
UPDATE: Just added a little example at beginning of post.
QUESTION:
Is the FETCH method called twice for all tied objects, in the conditions noted above?
My curiosity is truly peaked. Since I have no real experience 'tieing' anything, it would take some time for me to test. Maybe someone else would be willing?...