# this program reads through a file # line by line and prints "PRINTING" # for every line between $START & $STOP # i'm intersted in improving my function &flip(\$flop) $START = 'START'; $STOP = 'STOP'; $flop = 0; while(<>) { my @record = split /,/; chomp($record[0]); if (($flop) && ($record[0] ne $STOP)){ print "PRINTING"; } else { print "not printing"; } if (($record[0] eq $START) || ($record[0] eq $STOP)) { &flip(\$flop); } } sub flip {$ref = @_[0]; $$ref = !($$ref)}
as you can see, the function &flip(\$flop) is doing alright and working ... there's absolutly no reason to improve it... in fact, if i just wrote
$flop = !($flop)
i wouldn't need a function at all (i also wouldn't get to have the word 'flipflop' actually working in my code ... i think on some level it's like the poetry to me) for some reason i'd really like to optimize the function a step further to only ONE statement i tried
sub flip { $@_[0] = !($@_[0] };
figuring that it would be like saying: "de-reference the variable in position zero of the 'magic' array and toggle it" unfortunately it's more like saying: "don't compile" why is that?
In reply to something about improving code... by Buckaroo Buddha
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |