foreach $1 (@array)
Interestingly, you can use it under strict and warnings and Perl doesn't protest. But $1 is aliased to the elements of the array and loses its magic behaviour:
#!/usr/bin/perl use warnings; use strict; for $1 ('a' .. 'h') { print $1 if "A" =~ /(.)/; }
Can you guess what the output is?
So, if you ever get the idea of using special variables for something else than what they were designed to, stop.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: foreach $1
by LanX (Saint) on Jun 06, 2020 at 12:29 UTC | |
by kcott (Archbishop) on Jun 06, 2020 at 17:50 UTC | |
by LanX (Saint) on Jun 06, 2020 at 21:52 UTC | |
by choroba (Cardinal) on Jun 06, 2020 at 23:47 UTC | |
by Discipulus (Canon) on Jun 07, 2020 at 19:36 UTC | |
| |
by LanX (Saint) on Jun 07, 2020 at 02:19 UTC | |
| |
by ikegami (Patriarch) on Jun 08, 2020 at 22:25 UTC | |
by LanX (Saint) on Jun 08, 2020 at 23:55 UTC |