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...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.