Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Magic

by mirod (Canon)
on Oct 12, 2001 at 19:26 UTC ( [id://118500]=note: print w/replies, xml ) Need Help??


in reply to What does it mean for a Perl feature to be Magic?

The most immediate "magic" in Perl is usually the result of the deliberate DWIM-ism (Do What I Mean) of the language: the interpretor goes out of its way to do what people expect it to do, even though that might not be the real logical thing to do.

2 examples:

  • in regexps the $ matches the end of the string... or a \n and the end of the line, try it: perl -e' $foo="toto"; $bar="tata\n"; foreach ( $foo, $bar) { if( m/^t.t.$/) { print "$_ matches\n"; } }'
  • autoincrementing: the interpreter tries real hard to make sense of the content of the variable and return a meaningfull value:
    perl -e 'foreach my $foo ("1", "A1", "AA", "A001", "A009", "A999", "Z +", "AZ", "ZZ", "Z999") { my $bar= $foo; print "$bar++ = "; $bar++; p +rint $bar , "\n"; }'

There are more. In fact Perl goes beyond trying to "make the easy things easy", it tries real hard at "making not-so-easy things look easy". That's Magic!

There are of course other kinds of magic: tie-ed variables look like ordinary variables but behave magically (of course, as they have set the "Magic bit"), then there are deeper kinds of magics, but you will have to attend Dominus classes to learn them...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://118500]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-03-29 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found