Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Favorite Symbol Variable

by vroom (Pope)
on May 15, 2000 at 20:02 UTC ( #11666=poll: print w/ replies, xml ) Need Help??

vote on Favorite Symbol Variable

$_
[bar] 96/61%
$@
[bar] 9/6%
$<
[bar] 3/2%
$/
[bar] 9/6%
$!
[bar] 17/11%
Where's $*
[bar] 9/6%
Other
[bar] 14/9%
157 total votes
Comment on Favorite Symbol Variable
RE: Favorite Symbol Variable
by guice (Scribe) on May 15, 2000 at 20:09 UTC
    You have $/ but where's $\? Playing with mutiple platforms like I do, $\ proved to be very useful. It's a very usefull playing with files. Another one of my favorites is $| and $" ... You can do some nice prints of arrays when you play with $" :).
    Just my thought on things ...

    -- philip
    We put the 'K' in kwality!

"Dude!" Variable
by neshura (Chaplain) on May 15, 2000 at 20:34 UTC
    Why is $_ by far my favorite? Hmmm...there's a car commercial out there, I can't remember which car company. Anyway, it's touting the amazing suspension by having four coffee-swilling Xers driving around. They just keep saying "Dude!" over and over again in various intonations. The driver is heading for railroad tracks, and the exclamations of "Dude!" get increasingly agitated (anticipating hot coffee in lap).

    It ends predictably of course, but the point is that we know what they are saying beyond just "Dude!". Well, I do, anyway.
    Point: The conversational form of "Dude!" and the perl variable $_ are disturbingly analogous...

    e-mail neshura

      Dude, I totally know what you're saying... dude!

      Sorry, I couldn't resist!
      Dude
        Personally, I enjoy the variant form of Dude - the "intentional typo, just because I like it that way" Dued!
      Dude.

      Duuuuuuddddeeee.

      Dude?

      Dude.

        Homes

        Buddy

        Heh heh heh, that's a pretty good cartoon short.

        --
        perl -pe "s/\b;([st])/'\1/mg"

RE: Favorite Symbol Variable
by PipTigger (Friar) on May 16, 2000 at 05:43 UTC
    The first choice ($_) is the only one I've ever used before (well that's not including "other" which I've certainly used before =) ). Would anyone care to give a terse summary of the usefulness and appropriate contexts for each of the others? For MonksInTraining, it would be nicely instructional. Thanks muchly in advance. TTFN & Shalom.

    -PipTigger
    p.s. Come to think of it, I like $# better than $_ but it's more like $#xxxx and you don't really get $_xxxx so it probably doesn't belong. =) I'm a dork.
    p.p.s. So as not to be a hypocrite, for those who haven't seen $#xxxx before, it is the scalar value associated with the last indexable value in an array (er list... whichever is the politically correct name for it these days). You can quickly modify the size of an array/list by assigning a new value to this scalar (ie. To cut the array junklist in half rounded up do: $#junklist /= 2; ). Keep in mind that this value is always one less than the scalar context of the array name itself (ie. @junklist). This is true even in an empty list when the scalar context for @junklist == 0 && $#junklist == -1. Happy Hacking! =)
      $@ - how your most recent eval() screwed up. $< - the real uid of your process. $/ - the input line separator; useful for slurping in files. $! - how anything else in your program but eval() most recently screwed up. $* - let Perl assume that strings are single-line for regex matching.
      $@ - how your most recent eval() screwed up. $< - the real uid of your process. $/ - the input line separator; useful for slurping in files. $! - how anything else in your program but eval() most recently screwed up. $* - let Perl assume that strings are single-line for regex matching.
RE: Favorite Symbol Variable
by snowcrash (Friar) on May 16, 2000 at 14:49 UTC
    my absolute fav is $^W, better written as ${chr(24)} :)
    it's default value beats the others, too.

    cheers
    sc
      That is definately a good one, but only when $^W==1
RE: Favorite Symbol Variable
by Adam (Vicar) on May 16, 2000 at 18:44 UTC
    I'm partial to $[ but $_ takes a close second. j/k
RE: Favorite Symbol Variable
by radixzer0 (Beadle) on May 17, 2000 at 00:14 UTC
    $_ RULZ
    Seriously, though, how can you not like a variable that is so useful that 95% of the time you dont even need to reference it explicitly.

    Or, on the other hand, how can you not pick $_ when you (intentionally or not) use it more than any other?

    Be one with the $_.....
    -r0

      Well .. I use it so often, I don't even think of it as there. It's became, well ... default. It's the most useful variable in Perl, but cause I use it so much, I don't see it as a 'kewl' variable. You can't 'do' much with it. Where $\ and $" actually let you play with how things are displayed. Just like CDs where kewl and most useful for ditital media until it's so popular, it's not longer 'kewl'.
      Thing is, you barely ever have to type $_ - despite it being implicitly used millions of times each day.

View List Of Past Polls


Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-09-19 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (133 votes), past polls