Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Interesting line which I read from Monk's snippets

by Tanktalus (Canon)
on Jan 31, 2006 at 04:38 UTC ( #526657=note: print w/replies, xml ) Need Help??


in reply to Interesting line which I read from Monk's snippets

qw(a - b = c ~ d ^) creates a list: "a", "-", "b", "=", "c", "~", "d", "^". Put that in braces, and you are initialising an anonymous hash. Use the arrow to dereference that hash. The brace to the right shows what key to use to dereference the hash. The key to use is the substring of $0 (the program name) - starting at position 0, length of 1.

It's like this:

my %underline = ( a => '-', b => '=', c => '~', d => '^', ); my $first_letter = substr($0, 0, 1); my $pat = $underline{$first_letter};
Just a bit more concisely, and much less readably.

It's a cute trick, but I wouldn't recommend learning how to code from it ;-)

Replies are listed 'Best First'.
Re^2: Interesting line which I read from Monk's snippets
by vennirajan (Friar) on Jan 31, 2006 at 05:16 UTC
    Hi tanktalus,

        Nice explanation.Thanks for your contribution to the Community.

    Regards,
    S.Venni Rajan.
    "A Flair For Excellence."
                    -- BK Systems.

Re^2: Interesting line which I read from Monk's snippets
by jesuashok (Curate) on Jan 31, 2006 at 04:46 UTC
    Hi

    Thanks a lot for your fantastic explanation.
    Amazing perl

    "Keep pouring your ideas"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://526657]
help
Chatterbox?
[marto]: This won't take till Summer to complete I hope ;)
[Discipulus]: i hope too, vacuum cleaner permitting, 2-3 afternoon to build. Or is the 1:1 serie? ;=)
[Tanktalus]: Sure, no one is active for hours and hours in the cb, so I go to upgrade the db, and then someone is active. Sheesh :)
[Discipulus]: anyway poppins probably died with the last night cold. But is not normal to see them in dec. they must pop in April
NodeReaper eyes the thorns in the side
Discipulus : the party puller!

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-12-18 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (498 votes). Check out past polls.

    Notices?