Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: map syntax error -- weird

by hdb (Prior)
on Mar 22, 2013 at 10:38 UTC ( #1024915=note: print w/replies, xml ) Need Help??


in reply to Re: map syntax error -- weird
in thread map syntax error -- weird

Why does this work? (same result as your proposals)

my %opt; my @vals = qw(title artist album); my @opts = map { "$_"."=s" => \$opt{$_} } @vals; print @opts;

UPDATE: Guess: Because there is some statement in there that needs to be executed rather than a static string only?

Replies are listed 'Best First'.
Re^3: map syntax error -- weird
by LanX (Chancellor) on Mar 22, 2013 at 10:54 UTC
    > Why does this work? (same result as your proposals)

    There is no clear rule to distinguish between code-block and hash-ref!!!

    The parser uses DWIM heuristics to guess if it looks more like a hash-ref or not. (Furthermore "w/o look-ahead")

    So in complicated cases you need to give hints for what you mean.

    This ambiguity should be one reason why Perl6 switched from {} to <> to indicate hashes.

    > UPDATE: Guess: Because there is some statement in there that needs to be executed rather than a static string only?

    well it's a perfect hash-ref!

    DB<112> $hr={ "$_"."=s" => \$opt{$_} } => { "=s" => \undef }

    But I think the used heuristic must be quite simple, something like

      (bareword || variable) (comma || fatcomma) (expr)

    So "$_"."=s" is already to complex to fit this rule of thumb.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re^3: map syntax error -- weird
by BrowserUk (Pope) on Mar 22, 2013 at 10:54 UTC
    Guess: Because there is some statement in there that needs to be executed rather than a static string only?

    Indeed.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024915]
help
Chatterbox?
[marto]: oddly the last time I was there I saw a zeppelin in flight for the first time
[Corion]: ambrus: I don't know how far the budget estimate has been overrun yet
[Corion]: marto: Heh ;) No, you were likely at Tegel or Schönefeld, the new one ("BER") will be somewhat outside of Berlin ;)
[marto]: Corion Schoenfeld, but my friend has been telling me about this new airport for about 7-8 years now :P
[marto]: I doubt it even exists as a building site :P
[ambrus]: Corion: does building airports "somewhat outside of" a city ever work? cities always grow around the airport quickly, because it's practical to be close to it, and after that, people start to complain that the airplanes land so close to their house and sh
[ambrus]: ould keep down the noise

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-02-23 12:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (346 votes). Check out past polls.