[sf-perl] randomize particular lines

Quinn Weaver qw at sf.pm.org
Mon Mar 6 17:03:30 PST 2006

I forgot to say, $. is the current line number if you are reading
lines from a file, e.g.:

while (<$fh>) {
    if ($. % 3 == 0) {
        # We're on a third line (counting from line zero, which
        # counts as a third line in this case).

Again, perlvar covers $. and other "global special variables"
(a.k.a. "punctuation variables").

You can, and probably should, use more readable names for variables
like $.  Get them via 'use English qw( -no_match_vars )'.  man English
for details.

When you're ready, Damian's _Perl Best Practices_ is a wonderful book
full of helpful suggestions like 'use English qw( -no_match_vars )'.
It teaches you how to write Perl that's easy maintain and, in
particular, how to shy away from language features that can shoot you
in the foot.

Why does this whole thread make me feel like becoming a Python advocate?

qw (Quinn Weaver); #President, San Francisco Perl Mongers
=for information, visit http://sf.pm.org/weblog =cut

More information about the SanFrancisco-pm mailing list