snowyy has asked for the wisdom of the Perl Monks concerning the following question:

I often see the word magic on online docs and source for Perl. But there is almost no documentation on what magic is. Can someone explain what is magic in Perl?

 "...then magic is applied"

what does this phrase means?

Replies are listed 'Best First'.
Re: What is Magic ?
by japhy (Canon) on May 31, 2001 at 20:05 UTC
    It has two distinct meanings:
    • behind-the-scenes: doing $x++ when $x is undef returns 0, not undef, in a magical sort of way (the ++ causes it to return 0)
    • highly advanced technology*: $! is both a number and a string. printf "%d: %s", $! = 10, $!;
    (* any sufficiently advanced technology is indistinguishable from magic)

    japhy -- Perl and Regex Hacker
Re: What is Magic ?
by davorg (Chancellor) on May 31, 2001 at 20:05 UTC
    "Any sufficiently advanced technology is indistinguishable from magic"
    - Arthur C Clarke

    Generally, it means something incredibly clever and complex that the writer doesn't have time to explain in detail.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

Re: What is Magic ?
by lhoward (Vicar) on May 31, 2001 at 20:10 UTC
    From the Jargon File/New Hacker's Dictionary:
    magic

    1. adj. As yet unexplained, or too complicated to explain; compare automagically and (Arthur C.) Clarke's Third Law: "Any sufficiently advanced technology is indistinguishable from magic." "TTY echoing is controlled by a large number of magic bits." "This routine magically computes the parity of an 8-bit byte in three instructions." 2. adj. Characteristic of something that works although no one really understands why (this is especially called black magic). 3. n. Stanford A feature not generally publicized that allows something otherwise impossible, or a feature formerly in that category but now unveiled. 4. n. The ultimate goal of all engineering & development, elegance in the extreme; from the first corollary to Clarke's Third Law: "Any technology distinguishable from magic is insufficiently advanced".

    Parodies playing on these senses of the term abound; some have made their way into serious documentation, as when a MAGIC directive was described in the Control Card Reference for GCOS c.1978. For more about hackish `magic', see Appendix A. Compare black magic, wizardly, deep magic, heavy wizardry.

Re: What is Magic ?
by bikeNomad (Priest) on May 31, 2001 at 20:50 UTC
    from perlguts:
           Any SV may be magical, that is, it has special features
           that a normal SV does not have.  These features are stored
           in the SV structure in a linked list of "struct magic"'s,
           typedef'ed to "MAGIC".

    An SV is Perl's internal representation of a scalar value. As I understand it, magic allows accesses (reads, writes) from/to variables to call special functions that do special things.

    One simple example of this is the %ENV hash: changing values in %ENV change the environment for spawned subprocesses.

    Another example of this is the %SIG hash.

    Extensions (XS modules) can also add their own magic to variables.

Re: What is Magic ?
by Beatnik (Parson) on May 31, 2001 at 20:06 UTC
    Altho Merriam-Webster lists it as
    Main Entry: 1mag·ic
    Pronunciation: 'ma-jik
    Function: noun
    Etymology: Middle English magique, from Middle French, from Latin
    magice, from Greek magikE, feminine of magikos Magian, magical, from
    magos magus, sorcerer, of Iranian origin; akin to Old Persian magus
    sorcerer
    Date: 14th century
    1 a : the use of means (as charms or spells) believed to have supernatural
    power over natural forces b : magic rites or incantations
    2 a : an extraordinary power or influence seemingly from a supernatural
    source b : something that seems to cast a spell : ENCHANTMENT
    3 : the art of producing illusions by sleight of hand 
    there usually should be "The innerworks are far too complex to describe here, just take it like it is" OR "I'm WAAAAAAAAAAAAAAAY too lazy to explain what happens here, so I'll just stick to magic".

    Greetz
    Beatnik
    ... Quidquid perl dictum sit, altum viditur.
Re: What is Magic ?
by boo_radley (Parson) on May 31, 2001 at 20:06 UTC
    boo_radley pulls a coin from behind snowyy's ear!

    That's magic!

      jeffa hands boo some <Doug_Henning> tags
Re: What is Magic ?
by sierrathedog04 (Hermit) on May 31, 2001 at 22:02 UTC
    I think the term comes from the related expression "automagically." Magic is something unexpectedly good that happens behind the scenes to make a program work. Magic is the opposite of "gotchas", something unexpectedly bad that happens behind the scenes to break a program.

    For instance, case sensitivity can be a gotcha for Windows users logging in to a UNIX webserver. Case insensitivity can be magic for UNIX users logging into a Windows webserver.