in reply to User defined function in while loop
Note that, in this case, $_[0] is an alias for $count, so that decrementing $_[0] does decrement $count. Not necessarily a best practice in general, but OK IMHO for a one-liner.$ perl -E 'my $count = 5; say $count while decr($count); sub decr {-- +$_[0];}' 4 3 2 1
Or a variation of the same not using aliases:
$ perl -E 'my $count = 5; say $count while $count = decr($count); sub + decr {return -1 + shift;}' 4 3 2 1
|
|---|