[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] Perl and $_ ?

This is a multi-part message in MIME format.
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Wow, a perl question I can actually answer.  I'm still learning myself.  My
first project involving modules started yesterday.  It's going to be a web
interface to Oracle.  Any suggestions from the gallery would be greatly
appreciated.  So far I've just read the documentation for DBD-Oracle-0.59,
but have much to learn before this project is complete.

And now the answer to your $_ question.

Personally I don't like the strange shortcuts in perl such as the $_, but
mine's a subjective opinion.  The $_ is documented as the default variable
and works in the following way.  I most frequently use it during file
operations so that is where I picked my example from:

# Simple counter file exerpt . . . you might want to note that this does not
increment the counter . . .just looks at it

open (COUNTER, "/export/home/nobody/counter") || die ("Unable to open
counter file");   #  opens the counter file for reading
while (<COUNTER>)
# reads the file line by line and performs the following operation on it

# chops the newline after each line
        $counter =
#  sets the counter equal to the current line using the default variable
#  hmm, not sure what this does, but the book said to do it so I did . . .

You might want to note that my counter file is never larger than 1 line so
the use of the while loop is a bit moot, but works very well to explain the
default variable.


David S. Jackson wrote:

> Okay, I'm just chugging through "Learning Perl" and came to Chapter 6 and
> the $_ variable.  I thought I understood it, but now that I'm chugging
> through Chapter 7 (Regular Expressions) I'm not so sure.
> Could someone explain it to me in their own words with simple examples,
> maybe?
> TIA!  :-)
> --
> David S. Jackson                           http://www.dsj.net
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> "You may satisfy all your senses and still not be satisfied."
>                         --Edward S. Martin

Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Mark Cotner
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Mark Cotner
n:              Cotner;Mark
org:            RoadRunner(formarly MediaOne Express)
adr:            4545 Stonegate Ind. Blvd;;;Stone Mountain;Georgia;30083;United States
email;internet: mcotner at mediaone.net
title:          UNIX System Administrator
tel;work:       404-228-6091
tel;fax:        404-298-6733
tel;home:       770-465-2750
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
version:        2.1
end:            vcard