misterperl has asked for the wisdom of the Perl Monks concerning the following question:
(Perl 5.16 on linux).. I often prefer postfix expressions, like say $_ for 1..10;
As a natural extension, I'd like to use nested postfix loops. ChatGPT suggested:
say $_ for 1..5 for 1..10;
which seemed a strange proposition, because how could the scalar $_ contain both $i and $j? I tried it, thinking: "I gotta SEE this!". I thought perhaps Perl was clever enough to make $_ a reference to a list, but say or print of that would only be the reference, which was even more perplexing why it was suggested.But it only throws a syntax error on the second "for".
TY
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: postfix "for" question?
by SankoR (Prior) on Sep 11, 2023 at 14:31 UTC | |
by misterperl (Friar) on Sep 11, 2023 at 16:11 UTC | |
by hippo (Archbishop) on Sep 11, 2023 at 18:13 UTC | |
by tybalt89 (Monsignor) on Sep 11, 2023 at 19:11 UTC | |
by Fletch (Bishop) on Sep 11, 2023 at 20:27 UTC | |
by tybalt89 (Monsignor) on Sep 11, 2023 at 22:13 UTC | |
Re: postfix "for" question?
by LanX (Saint) on Sep 11, 2023 at 16:40 UTC | |
by soonix (Chancellor) on Sep 11, 2023 at 17:37 UTC | |
by eyepopslikeamosquito (Archbishop) on Sep 11, 2023 at 17:54 UTC | |
by Bod (Parson) on Sep 11, 2023 at 22:37 UTC | |
by LanX (Saint) on Sep 11, 2023 at 18:41 UTC | |
Re: postfix "for" question?
by karlgoethebier (Abbot) on Sep 12, 2023 at 10:59 UTC | |
by ikegami (Patriarch) on Sep 14, 2023 at 12:50 UTC | |
by karlgoethebier (Abbot) on Sep 14, 2023 at 21:44 UTC | |
by ikegami (Patriarch) on Sep 16, 2023 at 22:24 UTC |