Buckaroo Buddha has asked for the wisdom of the Perl Monks concerning the following question:
# 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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: something about improving code...
by btrott (Parson) on Jun 28, 2000 at 00:56 UTC | |
Re: something about improving code...
by merlyn (Sage) on Jun 28, 2000 at 01:12 UTC | |
by cwest (Friar) on Jun 28, 2000 at 01:54 UTC | |
by merlyn (Sage) on Jun 28, 2000 at 03:27 UTC | |
by jcwren (Prior) on Jun 28, 2000 at 03:51 UTC | |
by merlyn (Sage) on Jun 28, 2000 at 03:57 UTC | |
| |
Benchmarking
by Aighearach (Initiate) on Jun 28, 2000 at 08:57 UTC | |
by Adam (Vicar) on Jun 29, 2000 at 00:34 UTC | |
by Aighearach (Initiate) on Jun 29, 2000 at 02:56 UTC | |
Re: something about improving code...
by reptile (Monk) on Jun 28, 2000 at 02:30 UTC | |
Re: something about improving code...
by ncw (Friar) on Jun 28, 2000 at 01:12 UTC | |
RE: something about improving code...
by Adam (Vicar) on Jun 28, 2000 at 00:57 UTC | |
Re: something about improving code...
by raflach (Pilgrim) on Jun 28, 2000 at 01:34 UTC |
Back to
Seekers of Perl Wisdom