LanX has asked for the wisdom of the Perl Monks concerning the following question:
The following code is surprising me in two ways:
use strict; use warnings; use feature 'say'; use constant FL => 17,3,16; use constant FL2 => 22,4,13; my @row= "a".."z"; my @a = (" ") x 26; @a[17,3,16] = @row[22,4,13]; say "@a"; @a = (" ") x 26; @a[FL()] = @row[FL2]; say "@a";
It seems like constant folding isn't happening at all!!!
- I get a warning for FL2
Scalar value @row[FL2] better written as $row[FL2] (ignoring that its a constant _list_) - Deparsing the code shows that FL and FL2 are called as functions
@a[FL()] = @row[FL2()];
(This is perl 5, version 16,)
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Constants lists in array slices
by kcott (Archbishop) on Jul 20, 2018 at 13:03 UTC | |
by LanX (Saint) on Jul 20, 2018 at 13:12 UTC | |
Re: Constants lists in array slices
by haukex (Archbishop) on Jul 20, 2018 at 13:04 UTC | |
by LanX (Saint) on Jul 20, 2018 at 13:22 UTC | |
by haukex (Archbishop) on Jul 20, 2018 at 13:29 UTC | |
Re: Constants lists in array slices
by hippo (Bishop) on Jul 20, 2018 at 12:31 UTC | |
by LanX (Saint) on Jul 20, 2018 at 12:35 UTC | |
by hippo (Bishop) on Jul 20, 2018 at 13:14 UTC | |
Re: Constants lists in array slices
by LanX (Saint) on Jul 20, 2018 at 12:25 UTC |
Back to
Seekers of Perl Wisdom