Everything2
Near Matches
Ignore Exact
Full Text
Everything2

$_

created by iain

(thing) by iain (5.3 y) (print)   ?   I like it! Sat May 20 2000 at 21:06:37

A special variable in Perl which simply means the default -- used whenever an operator or function hasn't been given any other variable to work with, and used extensively by Perl hackers. In particular it can be used in a while loop to represent each line of an input file.

(thing) by fibonaci (2.6 y) (print)   ?   I like it! Thu Oct 24 2002 at 4:05:41

In Perl 6, $_ is known as the topic. It is lexically scoped (unlike in Perl 5), and is automatically assigned by topicalizers.

Some of the various topicalizers are for, given, CATCH (which is a special form of given), sub and -> (pointy sub), and bare closures.

What follows is an example of topicalizing blocks (in a simple ELIZA program):

    for <> -> $line {    # Both $line and $_ are <> 
        given $line {    # $line aliased to $_ (as before)
            when :iw/i love (\S+)/ {
                print "Do you have further plans for $1?\n"
            }
            when :i/sex/ {
                print "Tell me more about your sex life.\n"
            }
            when :i/eliza/ {
                print "You talkin' bout me?\n"
            }
        }
    }

The for and given alias to $_, and the pointy sub (-> in the first line) aliases to its argument.

The funny slashy things with colons are the regular expressions from Perl 6. The rest should be fairly self explanatory.


(thing) by benjya (1 mon) (print)   ?   I like it! Mon Sep 27 2004 at 13:20:23

In DOS (and Windows NT/2000/XP, and possibly OS/2) prompt strings, $_ generates a new line. This can be quite useful.

Often, people use $p$g as their prompt string, which shows their current directory ($p) and then the > prompt character ($g). With modern disks, and especially Microsoft's love with long path names (such as "Documents and Settings", "Temporary Internet Files" and the like), this can end up rather long, and the actual prompt character (and therefore where you type) gets lost.

So, using $p$_$n$g can make life easier. You still get your whole path, but you then get the prompt on a new line.

(Back in the good old DOS days, when everybody loaded an ANSI screen driver, you could do clever tricks that put a "status bar" at the top of the screen with the current path and current date and time in pretty colours. Hum de hum.)

wertperch said I actually miss ANSI.SYS. Hm. Wonder if it's still there in any form. I believe it is there - c:\windows\system32\ansi.sys or c:\winnt\system32\ansi.sys - but it's a bit messy to get it to load into a command prompt.


printable version
chaos

How to get a pseudo random .signature $& The *REAL* Obfuscated Perl multiplication table in Perl
@_ Perl 6 10 steps to becoming a Perl Ninja @ARGV
=~ Perl: Converting an integer or float to currency $ARG perl monks
Drinking Robitussin due to complete boredom Eliza Perl Pointy sub
given lcfirst Simple statement modifiers in Perl Closure
Mormonism &lt;&gt; superposition qw()
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
After stirring Everything, these nodes rose to the top:
Ford Galaxie
Search Engine Mechanics
Cassette Culture
I, Insomniac
Is it possible to learn things on everything?
Laughter and lying on grass
postmodernism
Clamdigger
Anti-coffee legislation throughout history
Daedalus
Bowling for Columbine
Fear and Trembling
Nelson Riddle
New Writeups
Ereneta
Stone Soup, Part Two(person)
jjen
Sorrier than I ever thought I would be(personal)
locke baron
Moskva class antisubmarine cruiser(thing)
Wuukiee
May 15, 2008(idea)
locke baron
Kuznetsov class aircraft carrier(thing)
_lesra
for abby(thing)
Adaptive Child
Annie's garden salsa(recipe)
Simulacron3
Zig-Zag(thing)
Ouzo
Special Grilled Cheese(fiction)
Noung
Tiananmen Square Massacre(idea)
aneurin
Lord St Clair(person)
artman2003
Assholes and Douchebags: A Comparison(person)
locke baron
Tyan Thunder K8WE(thing)
locke baron
Udaloy class destroyer(thing)
Scaevola
Same-sex marriage(idea)
This page courtesy of The Everything Development Company