in reply to Show different text based on random number

my $rand = int(rand(4)); if ( 0 == $rand ) {} elsif ( 1 == $rand ) {} … etc

Don’t use perl4 style unless you know why you’re doing it, c.f. &subname (carries @_ context) instead of subname(). Always use strict and warnings. This seems XY and maybe solved elsewhere: Data::Random.

Replies are listed 'Best First'.
Re^2: Show different text based on random number
by Discipulus (Canon) on Apr 22, 2016 at 06:55 UTC
    &sub is a perfectly valid Perl5 syntax. Is true that the author must be aware of side effects.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

      I didn't say it was invalid, I said it was perl4 style with gotchas. I don't think I've ever seen a Seeker of Perl Wisdom who uses it and is aware of its side-effects. :P It whispers cargo-cult and cgi-lib.pl to me.

        I'm not for sure a model for others perl programmers, but i still use it, and i'm aware of what i'm doing (disable prototypes and pass current @_ to the sub, but just in case of ⊂ ), to visually tell at glance locally (same file) defined subroutines from others imported by used modules.

        perlsub states:

        The & is optional in modern Perl, as are parentheses if the subroutine has been predeclared. The & is not optional..

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.