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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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...


In reply to Re: Magic by mirod
in thread What does it mean for a Perl feature to be Magic? by Elliott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 16:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found