jynx has asked for the wisdom of the Perl Monks concerning the following question:
In Perl 5.6.1, writing out a little test script i got my error to one little line. Here's the entire script to start with:
#!/usr/bin/perl -w use strict; my @one = qw( one two three ); my $two = sub { print "we were passed @_\n" }; # here's the problem line: $two->( map { anda => $_ } @one ); # But this would work fine: #$two->( map { 1 && anda => $_ } @one );
When compiling that as is Perl bails on a syntax error. The second (more ugly) version works fine, as well as using a variable instead of a hard-coded string. That's fine and good, but why is it happening that way?
i would think one would be able to code as i have above, but (on a Solaris 9 machine running the standard Perl 5.6.1 Sun install) apparently not. If i add parentheses i find out that apparently Perl is viewing { anda => $_ } as a hash reference, but map is expecting a code reference, so that's probably where the discrepency comes from.
Questions:
- Is there some nuance in the code i'm missing that will make it be short and readable instead of adding ugly hacks to get map to read that as a code block instead of a hash reference?
- Is anyone else having this problem? Or is it just me?
- Assuming it's standard behavior from 5.6.1, is it fixed in 5.8?
jynx
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (5.6.1) map mayhem? (+{ {;)
by tye (Sage) on Oct 07, 2003 at 20:02 UTC | |
by bart (Canon) on Oct 07, 2003 at 21:26 UTC | |
by merlyn (Sage) on Oct 07, 2003 at 21:42 UTC | |
by Abigail-II (Bishop) on Oct 08, 2003 at 11:24 UTC | |
by diotalevi (Canon) on Oct 08, 2003 at 01:03 UTC | |
Re: (5.6.1) map mayhem?
by jasonk (Parson) on Oct 07, 2003 at 19:54 UTC | |
Re: (5.6.1) map mayhem?
by eric256 (Parson) on Oct 08, 2003 at 15:40 UTC |
Back to
Seekers of Perl Wisdom