1s44c has asked for the wisdom of the Perl Monks concerning the following question:
Perl Monks,
I'm confused about what use version actually does. According to 'perldoc -f each' In Perl 5.12 and later only, it will also return the index and value for the next element of an array so that you can iterate over it; older Perls consider this a syntax error. On a system using perl 5.10.1:
#!/usr/bin/perl -w use v5.10.1; my @array = qw/one two three/; while (my ( $index, $line ) = each @array) { print "$index: $line\n"; } Result: Type of arg 1 to each must be hash (not private array) at ./t8 line 7, + near "@array) " Execution of ./t8 aborted due to compilation errors.
That's exactly as expected. What I don't get is why does that same code execute on Perl 5.18.2? It works like I never specified 'use v5.10.1'. Shouldn't 'use version' disable syntax that doesn't work on the given version?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use version confusion
by AppleFritter (Vicar) on Jul 06, 2014 at 12:29 UTC | |
by 1s44c (Scribe) on Jul 06, 2014 at 12:35 UTC | |
by Anonymous Monk on Jul 06, 2014 at 12:56 UTC | |
by AppleFritter (Vicar) on Jul 06, 2014 at 12:37 UTC | |
by perlfan (Parson) on Jul 07, 2014 at 11:56 UTC | |
by jellisii2 (Hermit) on May 12, 2016 at 17:33 UTC | |
|
Re: use version confusion
by Anonymous Monk on Jul 06, 2014 at 13:06 UTC | |
|
Re: use version confusion
by Anonymous Monk on Jul 06, 2014 at 12:41 UTC |