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...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|