[9129] in Perl-Users-Digest
Perl-Users Digest, Issue: 2747 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 28 11:07:50 1998
Date: Thu, 28 May 98 08:00:27 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 28 May 1998 Volume: 8 Number: 2747
Today's topics:
Advanced Perl Programming Book <redinger@usm.maine.edu>
Re: Advanced Perl Programming Book <tchrist@mox.perl.com>
Can anybody help me with a quick perl question <directors@when-it-matters.demon.co.uk>
Re: Email address checker - comments welcome (Joel Coltoff)
Re: Email address checker - comments welcome (John Porter)
Re: file size with perl and win NT (Stefaan A Eeckels)
Re: Help: Delete a file with Perl Script in WinNT scott@softbase.com
Re: how to init three dimentional array using perl (John Porter)
Re: HOWTO : Perl5/NT user authentication scott@softbase.com
Re: HOWTO : UDP ping ? <doug@weboneinc.net>
Re: Need a "word-count" <jerryp.usenet@connected.demon.co.uk>
Re: OO - explicit package name required <quednauf@nortel.co.uk>
Re: OO - explicit package name required (Chris Nandor)
Re: OO - explicit package name required <quednauf@nortel.co.uk>
Re: privateers (was Re: Copylefting manuals) (Charlie Stross)
Random signatures <tchrist@mox.perl.com>
Re: Text File Manipulatoin (John)
Re: Visibility of "my" vars <tchrist@mox.perl.com>
Re: Visibility of "my" vars (Bob Kline)
Re: Visibility of "my" vars (John Porter)
Wanted: info on passing args to functions in perl5 (Dean Karres)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 28 May 1998 09:56:40 -0400
From: "Christopher R. Redinger" <redinger@usm.maine.edu>
Subject: Advanced Perl Programming Book
Message-Id: <6kjqes$k9s$1@sol.caps.maine.edu>
Okay, I've searched the FAQ, I've read the groups, and I can't seem to find
the answer to this FAQ (at least around here). We've got the "Camel Book,"
we've got the "Llama Book," heck we've even got the "Hip Owls" book. The
question of the month around here as been, what the heck is on the cover of
Advanced Perl Programming by O'Reilly?? We've been calling it the "Puma
Book." But, I'm not too sure about the accuracy of that one. Any ideas?
Oh yeah, and shouldn't this be added to the FAQ? ;)
Not Just Another Perl Hacker,
Christopher
------------------------------
Date: 28 May 1998 14:26:44 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Advanced Perl Programming Book
Message-Id: <6kjs74$iol$2@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
"Christopher R. Redinger" <redinger@usm.maine.edu> writes:
:what the heck is on the cover of
:Advanced Perl Programming by O'Reilly?? We've been calling it the "Puma
:Book." But, I'm not too sure about the accuracy of that one. Any ideas?
It's actually a black leopard, and we all call it the ``Panther Book''.
The word panther denotes any large cat, usually in its darker color morph.
A mountain lion, a leopard, or a jaguar could all be black panthers.
http://work.ucsd.edu:5141/cgi-bin/http_webster?panther
--tom
--
The human mind ordinarily operates at only ten percent of its capacity
--the rest is overhead for the operating system.
------------------------------
Date: Thu, 28 May 1998 15:39:16 +0100
From: "When I.T. Matters Ltd." <directors@when-it-matters.demon.co.uk>
Subject: Can anybody help me with a quick perl question
Message-Id: <896366340.1009.0.nnrp-11.c1ed5f73@news.demon.co.uk>
Hi,
Let me start off by saying I am a complete beginner, so here is my problem
Just need a bit of advice really. I am trying to get a perl CGI script to
work. It is a form processor, one that will send me an e-mail when it is
processed. My problem is that it doesn't seem to like the - (inbetween
surrey and info) in my e-mail i.e
webmaster@surrey-info.com
Is the - some sort of special character in perl and if so how do Iet around
this.
Could you please e-mail me any suggestions or kind words of advice
Regards
Thomas Bathurst
P.S. I have tried using the \ before the -
------------------------------
Date: Thu, 28 May 1998 14:00:29 GMT
From: joel@wmi0.wmi.com (Joel Coltoff)
Subject: Re: Email address checker - comments welcome
Message-Id: <6kjql2$rsj@netaxs.com>
Keywords: from just another new york perl hacker
In article <eli$9805272119@qz.little-neck.ny.us>,
Eli the Bearded <*@qz.to> wrote:
>
>"Abandon all hope ye who enter here." I'd quote Dante directly if I knew
>enough Italian.
I don't know much Italian either but here is one motto I've heard.
traduttore traditore - [a translator is a traitor]
--
Joel Coltoff
I'd explain it, but there's a lot of math. -- Calvin
------------------------------
Date: Thu, 28 May 1998 14:11:25 GMT
From: jdporter@min.net (John Porter)
Subject: Re: Email address checker - comments welcome
Message-Id: <MPG.fd73c639a617da79896f5@news.min.net>
On 28 May 1998 01:56:30 GMT,
in article <eli$9805272119@qz.little-neck.ny.us>,
*@qz.to (Eli the Bearded) wrote:
> "Abandon all hope ye who enter here." I'd quote Dante directly if I knew
> enough Italian.
"Lasciate ogne speranza, voi ch'intrate", Inferno 3:9
John Porter
------------------------------
Date: 28 May 1998 14:13:28 GMT
From: Stefaan.Eeckels@ecc.lu (Stefaan A Eeckels)
Subject: Re: file size with perl and win NT
Message-Id: <6kjre8$auu$1@justus.ecc.lu>
In article <356ca9b5.17697798@news.club-internet.fr>,
vasile@club-internet.fr (Vasile CALMATUI) writes:
>
> It is a file made by the a mail reader program (Eudora Light).
> It's composed of text mails separated by 2-3 binary caracters.
> But why binary caracters can make life hard to Perl on Win32 ?
You might be hitting a CTRL-Z. If the file's opened in text
mode, this would be interpreted as EOF, and processing would
come to a halt. All praise the Windows text file concept :-)
--
Stefaan
--
PGP key available from PGP key servers (http://www.pgp.net/pgpnet/)
___________________________________________________________________
Williams and Holland's Law: If enough data is collected,
anything may be proven by statistical methods.
------------------------------
Date: 28 May 1998 12:45:50 GMT
From: scott@softbase.com
Subject: Re: Help: Delete a file with Perl Script in WinNT
Message-Id: <6kjm9u$i41$2@mainsrv.main.nc.us>
PH (thidinh@erols.com) wrote:
> What will be a function to delete a file in Perl scritp with WinNT server ?
Most likely it is a problem with permissions. Make sure your script
is running as a user who has permission to delete the file.
Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more.
------------------------------
Date: Thu, 28 May 1998 14:32:08 GMT
From: jdporter@min.net (John Porter)
Subject: Re: how to init three dimentional array using perl
Message-Id: <MPG.fd7413d3e3117369896f6@news.min.net>
On Thu, 28 May 1998 18:09:17 +0800,
in article <356D37CD.5704B7CE@asiapac.net>,
johnvun@asiapac.net (johnvun) wrote:
>
> i want to init the three dimentional array be zero.
>
> for ($in = 1; $in < 13; $in++)
> for ($shop =1; $shop < 120; $shop++)
> for ($trans=1; $trans<100; $trans++)
> @isarray{"$in","$shop","$trans"}=0;
>
> is this syntax ok ????
Obviously not, right? or you wouldn't be asking.
Problem #1: Braces are mandatory in Perl, they are not optional as in C.
Problem #2: When assigning to specific scalar members of an array, use $,
not @.
Problem #3: Perl's multi-dimensional array syntax doesn't look like that.
Tip #4: Your indices are numeric, and the array is to be fully
initialized (not sparse), so use arrays rather than hash.
Putting it all together:
for ( $in = 1; $in < 13; $in++ ) {
for ( $shop =1; $shop < 120; $shop++ ) {
for ( $trans=1; $trans < 100; $trans++ ) {
$isarray[$in][$shop][$trans] = 0;
}
}
}
> how i check my array is zero ???
By this I assume you mean, "how do I check that all elements are
zero". Here's a simple way:
$all_zero = 1;
CHECK_ZERO:
for ( $in = 1; $in < 13; $in++ ) {
for ( $shop =1; $shop < 120; $shop++ ) {
for ( $trans=1; $trans < 100; $trans++ ) {
if ( $isarray[$in][$shop][$trans] ) {
$all_zero = 0;
last CHECK_ZERO;
}
}
}
}
if ( $all_zero ) { ...
hth,
John Porter
------------------------------
Date: 28 May 1998 12:49:54 GMT
From: scott@softbase.com
Subject: Re: HOWTO : Perl5/NT user authentication
Message-Id: <6kjmhi$i41$3@mainsrv.main.nc.us>
Jerome Gay (gay@aspentech.com) wrote:
> I'd like to authenticate a user with his/her NT domain username and password
> on my NT box...
Why? NT is designed that once the user logs in, that's it, the user
has free reign over everything on the system which the user has been
given permission to access. The security model is specifically
designed for logging in once.
Scott
--
Look at Softbase Systems' client/server tools, www.softbase.com
Check out the Essential 97 package for Windows 95 www.skwc.com/essent
All my other cool web pages are available from that site too!
My demo tape, artwork, poetry, The Windows 95 Book FAQ, and more.
------------------------------
Date: Thu, 28 May 1998 10:09:39 -0400
From: Douglas Clifton <doug@weboneinc.net>
Subject: Re: HOWTO : UDP ping ?
Message-Id: <356D7023.7C88F7B9@weboneinc.net>
Greg Lindahl wrote:
>
> Calle Dybedahl <qdtcall@esb.ericsson.se> writes:
> > "Jerome Gay" <gay@aspentech.com> writes:
> >
> > > I need some kinda "UDP ping" and I'm pretty sure perl can do it... how ?
> >
> > RTFM Net::Ping
>
> pingecho() uses a TCP echo (not an ICMP one) to determine
> if the remote host is reachable.
>
> I don't know of anyone who's implemented UDP ping in perl, and tcp
> ping is not appropriate for all applications.
>
> -- g
Hello??--
use Net::Ping;
$p = Net::Ping->new("udp");
print "$host is reachable\n" if $p->ping($host);
$p->close();
--
Douglas Clifton
Unix/C/Perl/CGI/HTML Programmer
doug@weboneinc.com
------------------------------
Date: Wed, 27 May 1998 23:33:59 +0100
From: Jerry Pank <jerryp.usenet@connected.demon.co.uk>
Subject: Re: Need a "word-count"
Message-Id: <Svm$PNAXTJb1EwFg@connected.demon.co.uk>
In <comp.lang.perl.misc>
Tom Christiansen <tchrist@mox.perl.com>, writes:
<deletia>
>Yes, they are random.
>
>--tom
>
>#!/usr/bin/perl
>#
># sigrand -- supply random fortunes for .signature file
>
<deletia> Attr. TC
Ahem! But how many times do you run this before you're happy with the
results ? <Xor computation> :-)
--
Jerry Pank mailto:jerryp.usenet@connected.demon.co.uk
echo "Hmmm...you don't have Berkeley networking in libc.a..."
echo "but the Wollongong group seems to have hacked it in."
-- Larry Wall in Configure from the perl distribution
------------------------------
Date: Thu, 28 May 1998 14:52:31 +0100
From: "Frank L. Quednau" <quednauf@nortel.co.uk>
Subject: Re: OO - explicit package name required
Message-Id: <356D6C1F.EEA8A8DC@nortel.co.uk>
> Look up what 'use strict' does. :)
I can't !! (See amputated CPAN) :(
>
>
> gabor.
> --
> Although the Perl Slogan is There's More Than One Way to Do It, I
> hesitate to make 10 ways to do something. :-)
> -- Larry Wall in <9695@jpl-devvax.JPL.NASA.GOV>
--
____________________________________________________________
Frank Quednau
http://www.surrey.ac.uk/~me51fq
________________________________________________
------------------------------
Date: Thu, 28 May 1998 14:11:01 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: OO - explicit package name required
Message-Id: <pudge-2805981005260001@dynamic265.ply.adelphia.net>
In article <356D6C1F.EEA8A8DC@nortel.co.uk>, "Frank L. Quednau"
<quednauf@nortel.co.uk> wrote:
# > Look up what 'use strict' does. :)
#
# I can't !! (See amputated CPAN) :(
I don't know what you mean by that, but if you are using strict, you can
find out what it does.
man strict
perldoc strict
Or even:
more /opt/gnu/lib/perl5/strict.pm
# (or wherever your file is)
--
Chris Nandor mailto:pudge@pobox.com http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10 1FF77F13 8180B6B6'])
------------------------------
Date: Thu, 28 May 1998 15:33:18 +0100
From: "Frank L. Quednau" <quednauf@nortel.co.uk>
Subject: Re: OO - explicit package name required
Message-Id: <356D75AE.CD9CBDB2@nortel.co.uk>
Chris Nandor wrote:
> I don't know what you mean by that, but if you are using strict, you can
> find out what it does.
>
> man strict
> perldoc strict
>
> Or even:
>
> more /opt/gnu/lib/perl5/strict.pm
> # (or wherever your file is)
Yup, I know, but I wanted to moan about something, there usually isn't any
reason to moan in this newsgroup :)Thing is, I can always only do things to
and with Perl in the evening (on my nice little PC), or discuss the
problems I encountered in the discussion group the next morning on my
connected-to-the-web-but-having-no-permissions-whatsoever-due-to-just-being-a-student-machine...
Anyway the link in CPAN to the doc is broken, maybe someone can fix it :)
--
____________________________________________________________
Frank Quednau
http://www.surrey.ac.uk/~me51fq
________________________________________________
------------------------------
Date: Thu, 28 May 1998 14:04:28 GMT
From: charlie@antipope.org (Charlie Stross)
Subject: Re: privateers (was Re: Copylefting manuals)
Message-Id: <slrn6mqrq7.3mi.charlie@cs.ed.datacash.com>
On Wed, 27 May 1998 21:30:49 +0100, Ben Bullock
<ben@hayamasa.demon.co.uk> wrote:
>
>What's a software privateer? I know that
>Privateer was the `politically correct' name that British
>pirates gave themselves.
Not exactly. A privateer carried letters of marque, issued by the
government under whose flag they sailed, entitling them to legally
attack the shipping of a country with which they were at war (and
to steal their cargo and property). It was a cheap way for the
government to effectively boost their naval strength in a region,
because the takings were attractive enough to lure entrepreneurs
in -- however, woe betide the privateer captain whose letters of
marque were invalid, out of date, or who attacked the wrong vessel!
>I don't understand what a software privateer is though.
>
>I can't believe it's the same as a software `pirate'.
I believe someone's buggering around with the language.
(Unless Stalman believes that vendors of commercial software are
in a state of war with free software, and have acquired legal
permission from the government to hijack any free software they
come across and claim it for their own ...? Naah.)
-- Charlie
"Given two unrelated technical terms, an internet search engine
will retrieve only resumes." -- Schachter's Hypothesis
------------------------------
Date: 28 May 1998 14:21:59 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Random signatures
Message-Id: <6kjru7$iol$1@csnews.cs.colorado.edu>
Here's a slightly better version. The program gives you random signatures
by using named pipes. It expects the signatures file to have records
in the format of the fortune program--that is, each possibly multiline
record is terminated with "%%\n". Here's an example:
Make is like Pascal: everybody likes it, so they go in and change it.
--Dennis Ritchie
%%
I eschew embedded capital letters in names; to my prose-oriented eyes,
they are too awkward to read comfortably. They jangle like bad typography.
--Rob Pike
%%
God made the integers; all else is the work of Man.
--Kronecker
%%
I'd rather have :rofix than const. --Dennis Ritchie
%%
If you want to program in C, program in C. It's a nice language.
I use it occasionally... :-) --Larry Wall
%%
Basically, avoid comments. If your code needs a comment to be understood,
it would be better to rewrite it so it's easier to understand.
--Rob Pike
%%
Comments on data are usually much more helpful than on algorithms.
--Rob Pike
%%
Programs that write programs are the happiest programs in the world.
--Andrew Hume
%%
This program checks to see whether it's already running by using
a file with its pid in it. If that pid still exists (or, rarely,
that something else has reused it), the program just exits.
It also looks at your last/current Usenet posting to decide
whether to look in a per-newsgroup signature file.
You can use sigrand even on systems without named pipes if you remove
the code to create a named pipe, and extend the sleep interview before
file updates. Then you'd have just a regular file. Another portability
concern is that the program forks itself in the background, which is
almost like becoming a daemon. If you have no fork call, just comment
it out.
#!/usr/bin/perl -w
# sigrand -- supply random fortunes for .signature file
use strict;
# config section variables
use vars qw( $NG_IS_DIR $MKNOD $FULLNAME $FIFO $ART $NEWS $SIGS $SEMA
$GLOBRAND $NAME );
# globals
use vars qw( $Home $Fortune_Path @Pwd );
################################################################
# begin configuration section
# should really read from ~/.sigrandrc
gethome();
# for rec/humor/funny instead of rec.humor.funny
$NG_IS_DIR = 1;
$MKNOD = "/bin/mknod";
$FULLNAME = "$Home/.fullname";
$FIFO = "$Home/.signature";
$ART = "$Home/.article";
$NEWS = "$Home/News";
$SIGS = "$NEWS/SIGNATURES";
$SEMA = "$Home/.sigrandpid";
$GLOBRAND = 1/4; # chance to use global sigs anyway
# $NAME should be (1) left undef to have program guess
# read address for signature maybe looking in ~/.fullname,
# (2) set to an exact address, or (3) set to empty string
# to be omitted entirely.
$NAME = ''; # means no name used
## $NAME = "me\@home.org\n";
# end configuration section -- HOME and FORTUNE get autoconf'd
################################################################
setup(); # pull in inits
justme(); # make sure program not already running
fork && exit; # background ourself and go away
open (SEMA, "> $SEMA") || die "can't write $SEMA: $!";
print SEMA "$$\n";
close(SEMA) || die "can't close $SEMA: $!";
# now loop forever, writing a signature into the
# fifo file. if you don't have real fifos, change
# sleep time at bottom of loop to like 10 to update
# only every 10 seconds.
for (;;) {
open (FIFO, "> $FIFO") || die "can't write $FIFO: $!";
my $sig = pick_quote();
for ($sig) {
s/^((:?[^\n]*\n){4}).*$/$1/s; # trunc to 4 lines
s/^(.{1,80}).*? *$/$1/gm; # trunc long lines
}
# print sig, with name if present, padded to four lines
if ($NAME) {
print FIFO $NAME, "\n" x (3 - ($sig =~ tr/\n//)), $sig;
} else {
print FIFO $sig;
}
close FIFO;
# Without a microsleep, the reading process doesn't finish before
# the writer tries to open it again, which since the reader exists,
# succeeds. They end up with multiple signatures. Sleep a tiny bit
# between opens to give readers a chance to finish reading and close
# our pipe so we can block when opening it the next time.
select(undef, undef, undef, 0.2); # sleep 1/5 second
}
die "XXX: NOT REACHED"; # you can't get here from anywhere
################################################################
# Ignore SIGPIPE in case someone opens us up and then closes the fifo
# wihtout reading it; look in a .fullname file for their login name.
# Try to determine the fully qualified hostname. look our for silly
# ambersands in passwd entries. make sure we have signatures or fortunates.
# build a fifo if we need to.
sub setup {
$SIG{PIPE} = 'IGNORE';
unless (defined $NAME) { # if $NAME undef in config
if (-e $FULLNAME) {
$NAME = `cat $FULLNAME`;
die "$FULLNAME should contain only 1 line, aborting"
if $NAME =~ tr/\n// > 1;
} else {
my($user, $host);
chop($host = `hostname`);
($host) = gethostbyname($host) unless $host =~ /\./;
$user = $ENV{USER} || $ENV{LOGNAME} || $Pwd[0] || die "intruder alert";
($NAME = $Pwd[6]) =~ s/,.*//;
$NAME =~ s/&/\u\L$user/g; # can't believe some folks still do this
$NAME = "\t$NAME\t$user\@$host\n";
}
}
check_fortunes() if !-e $SIGS;
unless (-p $FIFO) { # -p checks whether it's a named pipe
if (!-e _) {
system("$MKNOD $FIFO p") && die "can't mknod $FIFO";
warn "created $FIFO as a named pipe\n";
} else {
die "$0: won't overwrite file .signature\n";
}
} else {
warn "$0: using existing named pipe $FIFO\n";
}
# get a good random number seed. not needed if 5.004 or better.
srand(time() ^ ($$ + ($$ << 15)));
}
# choose a random signature
sub pick_quote {
my $sigfile = signame();
if (!-e $sigfile) {
return fortune();
}
open (SIGS, "< $sigfile") || die "can't open $sigfile";
local $/ = "%%\n";
local $_;
my $quip;
rand($.) < 1 && ($quip = $_) while <SIGS>;
close SIGS;
chomp $quip;
return $quip || "ENOSIG: This signature file is empty.\n";
}
# See whether ~/.article contains a Newsgroups line. if so, see the first
# group posted to and find out whether it has a dedicated set of fortunes.
# otherwise return the global one. also, return the global one randomly
# now and then to spice up the sigs.
sub signame {
(rand(1.0) > ($GLOBRAND) && open ART) || return $SIGS;
local $/ = '';
local $_ = <ART>;
my($ng) = /Newsgroups:\s*([^,\s]*)/;
$ng =~ s!\.!/!g if $NG_IS_DIR; # if rn -/, or SAVEDIR=%p/%c
$ng = "$NEWS/$ng/SIGNATURES";
return -f $ng ? $ng : $SIGS;
}
# Call the fortune program with -s for short flag until
# we get a small enough fortune or ask too much.
sub fortune {
local $_;
my $tries = 0;
do {
$_ = `$Fortune_Path -s`;
} until tr/\n// < 5 || $tries++ > 20;
s/^/ /mg;
$_ || " SIGRAND: deliver random signals to all processes.\n";
}
# Make sure there's a fortune program. Search
# for its full path and set global to that.
sub check_fortunes {
return if $Fortune_Path; # already set
for my $dir (split(/:/, $ENV{PATH}), '/usr/games') {
return if -x ($Fortune_Path = "$dir/fortune");
}
die "Need either $SIGS or a fortune program, bailing out";
}
# figure out how directory
sub gethome {
@Pwd = getpwuid($<);
$Home = $ENV{HOME} || $ENV{LOGDIR} || $Pwd[7]
|| die "no home directory for user $<";
}
# "There can be only one." --the Highlander
sub justme {
if (open SEMA) {
my $pid;
chop($pid = <SEMA>);
kill(0, $pid) && die "$0 already running (pid $pid), bailing out";
close SEMA;
}
}
__END__
--
Data structures, not algorithms, are central to programming. --Rob Pike
------------------------------
Date: 28 May 1998 14:01:23 GMT
From: johns@cc.gatech.edu (John)
Subject: Re: Text File Manipulatoin
Message-Id: <6kjqnj$ilu$1@news-int.gatech.edu>
John (johns@cc.gatech.edu) wrote:
: Okay, I figured out some of this. I figured out pattern matching,
: but now I don't know how to edit just part of a line. I can
: find the text that's embedded in a line, but then all I've been able
: to do is write a WHOLE new line. What I want to do is just remove
: the pattern I'm searching for and replace it with some other text
: that isn't necessarily the same size at the pattern being removed.
: Could someone point me in the right direction here?
Well, I got it finished. Thanks for the couple of people that
actually helped me out with this...
--
John Q. Sindell Jr.
jqs@pikapp.net
jqsindel@gapac.com
http://www.cc.gatech.edu/~johns
------------------------------
Date: 28 May 1998 13:59:22 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Visibility of "my" vars
Message-Id: <6kjqjq$h2n$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc, gabor@vmunix.com (Gabor) writes:
:A 'my' var has block scope. A file in this case can be considered a
:block, hence everything in the file can see the 'my' var. It's as if
^ below
:the whole file was wrapped in curly brackets. If you declare a 'my'
:then all blocks below it can see it;
That's essentially right, and irrespective of packages. I'd also point
out that scopes nest, and that the file is just an enclosing scope
surrounding the subroutines.
--tom
--
Unix is supported by IBM, like a hanging man is supported by rope
- _Life With Unix_ Don Libes & Sandy Ressler
------------------------------
Date: 28 May 1998 14:12:30 GMT
From: bkline@cortex.nlm.nih.gov (Bob Kline)
Subject: Re: Visibility of "my" vars
Message-Id: <6kjrce$eo6$1@lhc.nlm.nih.gov>
Mark-Jason Dominus (mjd@op.net) wrote:
: So, unlike dynamic variables created by the ``local'' statement,
: lexical variables declared with ``my'' are totally hidden from the
: outside world, including any called subroutines.
: >This would appear to be saying that any called subroutines would not
: >be able to see a lexically scoped variable declared/defined at file
: >scope,
: No, because you have misinterpreted `outside world'. Scopes nest. A
: `my' variable declared in file scope is visible anywhere in that
: scope; subroutines in the file are inside that scope, not outside.
Mark-Jason:
Thanks for clarifying the intent of the documentation (much more
helpfully than the one-line email reply I receive which said only
"no, it doesn't"). I had originally assumed (without consulting the
docs) that variables with file scope would be visible to subroutines
in the same file, until a colleague pointed out the passage in the man
page. He noted that the language "including any called subroutines"
carried the inference that the outside world includes all called
subroutines, and I couldn't refute this (except by demonstrating the
behavior of Perl), hence my appeal to the newsgroup. Perhaps the
language might more precisely read something like "... including
any called subroutines which are outside the scope of the variable."
Bob
------------------------------
Date: Thu, 28 May 1998 14:39:10 GMT
From: jdporter@min.net (John Porter)
Subject: Re: Visibility of "my" vars
Message-Id: <MPG.fd742e887bf355a9896f7@news.min.net>
On 28 May 1998 12:05:26 GMT,
in article <6kjju6$rps$1@lhc.nlm.nih.gov>,
bkline@cortex.nlm.nih.gov (Bob Kline) wrote:
>
> The man page for perlsub has the following passage:
>
> "Unlike dynamic variables created by the ``local'' statement, lexical
> variables declared with ``my'' are totally hidden from the outside world,
> including any called subroutines ...."
>
> This would appear to be saying that any called subroutines would not
> be able to see a lexically scoped variable declared/defined at file
> scope,
Well, it may appear to say that, but it's really only talking about
lexical variables with block (e.g. subroutine) scope, not file scope.
This is, after all, the perlsub doc. It's only talking about how
subs work.
> Is this a bug in the documentation?
Only if you take the sentence out of context. :-)
> Can the behavior I'm observing
> be relied upon in future versions?
Absolutely.
> current behavior matches the file-static variables of C/C++, which
Except that in most implementations, file-static variables aren't
truly hidden from other files, unlike file-scoped lexicals in Perl.
Also, all C statics are initialized at load time, whereas 'my's
are initialized at run time. To get closer, you can use a BEGIN
block.
John Porter
------------------------------
Date: 28 May 1998 14:44:16 GMT
From: karres@southwind.net (Dean Karres)
Subject: Wanted: info on passing args to functions in perl5
Message-Id: <6kjt80$7hl$1@opal.southwind.net>
Hi,
I have this program that calls a subroutine. the program does a "tie"
to establish the connection to a DB file. The tie looks like
if (! ($DB_method = tie(%acpRecord, "DB_File",
"$LOGDIR/my_db_file", O_RDWR|O_CREAT,
0644, $Tree)))
{
die "Could not open db file\n$!\n";
}
the subsequent subroutine call looks like:
if (! filterBillingRecords($LOGDIR, \$DB_method, \$Tree,
\%acpRecord))
{
die "Can not open logfiles\n$!\n";
}
the subroutine accepts the parameters as:
my($dir, $DB_method, $Tree, %acpRecord) = @_;
'K. When I run this I get the message:
Odd number of elements in hash list at filterBillingRecords.pl line 22.
which is the above "my" line in the subroutine. The book says that this
message means what it says - there is an odd number of things in the
hash - which is odd because hashes are paired things...
So, I start looking for the usual suspects. After a lot of head banging
today I find the the entity called "Tree" above is a reference to a hash
of it's own. How do I pass a reference to a reference to a hash? Do I
need to? My barin hurts.
Dean...K...
--
Dean Karres | http://www2.southwind.net/~karres
karres@southwind.net |
Southwind Internet Access | Programmer / Systems Administrator
Wichita, KS | <Troll 2nd Class /w Clusters>
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 2747
**************************************