in reply to Re^3: Access a global variable from a subroutine when used as "for" iterator
in thread Access a global variable from a subroutine when used as "for" iterator

my @array = (1, 2, 3, 4, 5); my $count = (1, 2, 3, 4, 5); say "$count: @array";

That's very confusing. It breaks two rules:

  1. Don't use lying variable names.
  2. Don't use numbers that correspond to counts.

The correct example should have been

my @array = (11, 12, 13, 14, 15); my $last = (11, 12, 13, 14, 15); my $count = @array; say "$last, $count, @array";

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^5: Access a global variable from a subroutine when used as "for" iterator
by LanX (Saint) on Dec 22, 2023 at 17:53 UTC
    > It breaks two rules:

    Whose rules?

    The rules of Miss Understanding? ;p

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      Choroba's Unwritten Rules of Good Example Code ™.

      But I have a feeling we discussed not using trivial sequences in examples with haukex years ago. I can't find the posts now.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        While I agree with your rules...

        > Choroba's Unwritten Rules of Good Example Code ™.

        I expected a more authoritative source, like a burning Xmas tree talking to you, or encountering an old bearded woman on a mountain tip, bestowing you with a T-shirt with those ten golden rules written on it.

        > But I have a feeling we discussed not using trivial sequences in examples with haukex years ago

        Or something like that! ;)

        Tell me if you find the other 8 commandments.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        see Wikisyntax for the Monastery