Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Perl oddities

by Joost (Canon)
on Mar 01, 2005 at 14:42 UTC ( #435452=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl oddities
in thread Perl oddities

Sure you can, but you need the dreaded +:
print map +{$_}, qw/foo bar/

Replies are listed 'Best First'.
Re^4: Perl oddities
by Anonymous Monk on Mar 01, 2005 at 16:16 UTC
    No, you don't need the +:
    print map {"$_",}, qw/foo bar/
    works as well, although you need more characters. I don't think there is any case in Perl where you need unary minus for disambiguation where you can't disambiguate in another way using 2 or 3 other keystrokes.

    Unary plus is just a convenience, not a requirement.

      Quoting is not an identity function in Perl.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

        Quoting is not an identity function in Perl.

        It's not, but if you're going to use them as hash keys, they get quoted anyway:

        perl -MDevel::Peek -e '$a = 1; Dump ($a); %a = map +{$_}, $a; Dump ($a +)' SV = IV(0x8192edc) at 0x8191dc4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 SV = PVIV(0x8184888) at 0x8191dc4 REFCNT = 1 FLAGS = (IOK,POK,pIOK,pPOK) IV = 1 PV = 0x818b5b8 "1"\0 CUR = 1 LEN = 2

        perl -MDevel::Peek -e '$a = 1; Dump ($a); %a = map {"$_",}, $a; Dump ( +$a)' SV = IV(0x8192edc) at 0x8191dc4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 SV = PVIV(0x8184888) at 0x8191dc4 REFCNT = 1 FLAGS = (IOK,POK,pIOK,pPOK) IV = 1 PV = 0x818b5b8 "1"\0 CUR = 1 LEN = 2
        No difference.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://435452]
help
Chatterbox?
[corenth]: @stuff was pretty big. I think it grew to about 8000.
[corenth]: each element was several three + element references
[corenth]: That FANN thing sounds like something I
[Cosmic37]: When I say I like LGPL what I mean is that I like the GPL aspect. I am a fan of Rishard Stallman and the Free Software Foundation but I wish I could be more virtuous... self-flagellates
[corenth]: . . . I'd like to play with
[corenth]: I'm a pragmatic free-software advocate. I'll play in a walled sandbox when I need to.
[erix]: hm, there's a FANN perl module - looks a bit old
[Cosmic37]: I'm afraid I don't know the answer to your map question...... what were the references too?

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2018-02-20 18:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (274 votes). Check out past polls.

    Notices?