[15440] in Perl-Users-Digest
Perl-Users Digest, Issue: 2850 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 24 03:05:24 2000
Date: Mon, 24 Apr 2000 00:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <956559908-v9-i2850@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 24 Apr 2000 Volume: 9 Number: 2850
Today's topics:
Re: basic number parsing question (Craig Berry)
Re: basic number parsing question <lr@hpl.hp.com>
Re: call sub from browser (David Efflandt)
common filehandle to read and write!! prakash_ojha@my-deja.com
Re: executing sub in a module without calling it <dimitrio@perlnow.com>
Re: executing sub in a module without calling it <dimitrio@perlnow.com>
filehandle for RAM buffer? jlamport@calarts.edu
Re: filehandle for RAM buffer? <jeff@vpservices.com>
Re: Hair Loss ???? <uri@sysarch.com>
Re: How can I delay "use"ing a module until the module msouth@fulcrum.org
Re: How can I delay "use"ing a module until the module alexandria_sarkut@my-deja.com
Re: How can I delay "use"ing a module until the module (Craig Berry)
Re: How can I delay "use"ing a module until the module <lr@hpl.hp.com>
Re: I want to use the login name. How can I get the log <yosikim@lgeds.lg.co.kr>
Re: ICQ client <rick@zt.energy.gov.ua>
min/max <dimitrio@perlnow.com>
Re: min/max (brian d foy)
Re: min/max (Craig Berry)
Re: Perl CGI Download (David Efflandt)
Re: purpose of use vars () ? jlamport@calarts.edu
Re: purpose of use vars () ? <schan_ca@geocities.com>
Show me if you don't mind <rmb34NOSPAM@mindspring.com>
socket fd exit with child? <schan_ca@geocities.com>
wierd behaviour untainting... <mathias@singapura.singnet.com.sg>
Re: Win32::OLE with Word 97 <ben@leedsnet.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 24 Apr 2000 05:21:37 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: basic number parsing question
Message-Id: <sg7mf198cdo144@corp.supernews.com>
chris (chris@aol.com) wrote:
: if I have a date stored in variable $date and it is equal to "20000423"
: (todays date) how can I store only the last 2 digits (the day of the
: month) in a new variable? in this
: example I want the new variable to be equal to "23"
$day = substr $date, -2;
I'd do it differently (using unpack, for example) if I wanted to grab all
three pieces of the date.
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "The road of Excess leads to the Palace
of Wisdom" - William Blake
------------------------------
Date: Sun, 23 Apr 2000 22:44:02 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: basic number parsing question
Message-Id: <MPG.136d7ef14b56938098a95f@nntp.hpl.hp.com>
In article <8e04s9$vo1$1@nnrp1.deja.com> on Mon, 24 Apr 2000 00:35:22
GMT, prakash_ojha@my-deja.com <prakash_ojha@my-deja.com> says...
> In article <39039BAD.E127FA25@aol.com>,
> chris <chris@aol.com> wrote:
> > if I have a date stored in variable $date and it is equal to
> "20000423"
> > (todays date) how can I store only the last 2 digits (the day of the
> > month) in a new variable? in this
> > example I want the new variable to be equal to "23"
>
> use $s= substr($date, -2, 2) it will return the last two characters in
> $s.
True. So will simply:
$s = substr $date, -2;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 24 Apr 2000 05:10:03 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: call sub from browser
Message-Id: <slrn8g7lo0.ckb.efflandt@efflandt.xnet.com>
On Sun, 23 Apr 2000 16:41:02 GMT, dmayo2@yahoo.com <dmayo2@yahoo.com> wrote:
>Hello...
>
>I was wondering if there is a way to call a subroutine in a perl script
>directly from the browsers location bar.
>
>e.g.
>
>/cgi-bin/perlsrcipt.cgi?subroutine3
This is an example using CGI :standard function method where the query
string would be something like ?do=add. Other subs not in the @do list
cannot be accessed directly:
# Limit outside calls to @do list (or initial admin if no saved password)
@do =
('jump','random','add','postlink','admin','maindata','linkdata','alink');
if ($do = param('do')) {
if (grep /^$do$/, @do) {
eval "&$do";
print header,start_html(-title=>'Subroutine Error', %body),
"Subroutine error: $@\n" if $@; # only if eval error
} else {
my $sub = param('do');
print header,start_html(-title=>'Not Implemented', %body),
h1('Feature Not Available'), "\nThe requested feature ",
"'$sub' is unavailable or disabled.\n",p,end_html;
}
exit;
} elsif (!$q->param('passwd')) { # $q->params from data file
# if no existing password in data file, set up new data file
# and do &admin for initial settings.
exit;
}
# Display default page
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/ http://cgi-help.virtualave.net/
------------------------------
Date: Mon, 24 Apr 2000 06:03:14 GMT
From: prakash_ojha@my-deja.com
Subject: common filehandle to read and write!!
Message-Id: <8e0o2u$jn1$1@nnrp1.deja.com>
is there a common way to create filehandle for both read/append..
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 24 Apr 2000 03:32:03 GMT
From: "Dimitri Ostapenko" <dimitrio@perlnow.com>
Subject: Re: executing sub in a module without calling it
Message-Id: <TePM4.58568$2D6.1777123@news20.bellglobal.com>
> > I need to run init sub in a package every time this
> > package is loaded. Is there way to do it?
>
> Could you provide an example of what you want to do?
> Normally a package will only get loaded once for an
> execution session when it is used or required, i.e. it is
> not clear what you mean by "every time".
>
> perldoc perlmod would be a good place to look for some
> info, especially about BEGIN, or possibly INIT, blocks (if
> I interpret your situation correctly).
>
> hth
> t
Thanks a lot for your help.
I should have been more specific.
I'm using apache+modperl. To cache some frequently used modules I import
them into Startup.pm, which is loaded on every server restart.
One of the modules has some structures that have to be initialized once and
then used many times.
I use init sub for that. What I'd like to do is instead of calling init
from Startup.pm, execute it automatically on server restart.
But you already answered my question.
thanks again
dimitri
------------------------------
Date: Mon, 24 Apr 2000 04:25:42 GMT
From: "Dimitri Ostapenko" <dimitrio@perlnow.com>
Subject: Re: executing sub in a module without calling it
Message-Id: <a1QM4.58664$2D6.1784928@news20.bellglobal.com>
<nobull@mail.com> wrote in message news:u9og70n1t9.fsf@wcl-l.bham.ac.uk...
> "Dimitri Ostapenko" <dimitrio@perlnow.com> writes:
>
> > I need to run init sub in a package every time this package is loaded.
> >
> > Is there way to do it?
>
> BEGIN { init(); }
>
> If when you say "package" you really mean "module" then you may also
> overload the import() method which may or may not be more appropriate
> to your needs.
>
> For details: perldoc perlmod
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
With first option how would I predeclare init() if I want to put BEGIN
before init body?
Using prototype sub init(); before BEGIN doesn't seem to work
thanks
Dimitri
------------------------------
Date: Mon, 24 Apr 2000 02:08:32 GMT
From: jlamport@calarts.edu
Subject: filehandle for RAM buffer?
Message-Id: <8e0aao$5kh$1@nnrp1.deja.com>
Is there some way to create a filehandle which points to a buffer in RAM
rather than to a physical file? Ideally I'd like to do something like
this:
my $buffer;
open(HANDLE, \$buffer ); #pseudo-code, doesn't really work
print HANDLE "Some text";
close HANDLE;
print $buffer; #prints out "Some text"
Especially nice would be doing this with STDOUT. Any suggestions?
-jason
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 23 Apr 2000 20:14:34 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: filehandle for RAM buffer?
Message-Id: <3903BC1A.4F93734A@vpservices.com>
jlamport@calarts.edu wrote:
>
> Is there some way to create a filehandle which points to a buffer in RAM
> rather than to a physical file? Ideally I'd like to do something like
> this:
>
> my $buffer;
> open(HANDLE, \$buffer ); #pseudo-code, doesn't really work
> print HANDLE "Some text";
> close HANDLE;
> print $buffer; #prints out "Some text"
>
> Especially nice would be doing this with STDOUT. Any suggestions?
The IO::Scalar module in IO::Stringy does exactly that:
#!perl -w
use strict;
use IO::Scalar;
my $s;
tie *STDOUT, 'IO::Scalar', \$s;
print "hello new world"; # prints to scalar
untie *STDOUT;
print "\U$s!\n"; # prints to screen
__END__
Or you can tie it to some other filehandle.
--
Jeff
------------------------------
Date: Mon, 24 Apr 2000 03:33:21 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Hair Loss ????
Message-Id: <x7ya6441hb.fsf@home.sysarch.com>
>>>>> "H" == Helper <Helper> writes:
H> Help for Hair Loss is now available I tried this hair oil.
spam the other language groups and not here. perl hackers don't have to
tear out their hair because of their choise of languages.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 24 Apr 2000 03:12:58 GMT
From: msouth@fulcrum.org
Subject: Re: How can I delay "use"ing a module until the module is needed?
Message-Id: <8e0e3q$350$1@inxs.ncren.net>
alexandria_sarkut@my-deja.com wrote:
> In article <MPG.1368ed1582d60fc898a93c@nntp.hpl.hp.com>
> on Thu, 20 Apr 2000 11:32:22 -0700 Larry Rosler says...
>> In article <8dngoc$8p$1@nnrp1.deja.com> on Thu, 20 Apr 2000 18:03:03
>> GMT, alexandria_sarkut@my-deja.com <alexandria_sarkut@my-deja.com
>> says...
> <SNIP of discussion which you seem not to have understood.>
> Off topic inflammatory comment of no purpose.
It's hard to tell where that "<SNIP..." line came from. In a
pure-oxygen environment, poor quoting could be conisdered
inflammatory...
>> > if (conditional statement)
>> Evaluated at run time.
>> > {
>> > use LWP::Simple
>> Evaluated at compile time, hence evaluated regardless of the value of
>> the conditional expression (not 'statement').
> Would you point to documentation substantiating your
yes, see below
> claim a module called via a conditional statement
> is evaluated during compilation?
Your understanding of what 'use' does is incorrect. It doesn't
"call" anything at compile time. The documentation for 'use'
(perldoc -f use) will tell you that 'use' basically puts
a 'require' in a BEGIN block for you. Whatever is in the
BEGIN block (_regardless_ of where the BEGIN block appears
in your code) executes before everything else. You can
read about that in
perldoc perlmod
["Off topic comments of no purpose" removed :) ]
--
Michael South | http://fulcrum.org
Head Mathophile, | 101 Canyon Run
fulcrum.org | Cary NC 27513 USA
(msouth@fulcrum.org) | (919) 465-9074
------------------------------
Date: Mon, 24 Apr 2000 04:59:37 GMT
From: alexandria_sarkut@my-deja.com
Subject: Re: How can I delay "use"ing a module until the module is needed?
Message-Id: <8e0kbj$g3h$1@nnrp1.deja.com>
msouth@fulcrum.org wrote:
> alexandria_sarkut@my-deja.com wrote:
> > on Thu, 20 Apr 2000 11:32:22 -0700 Larry Rosler says...
> >> alexandria_sarkut@my-deja.com <alexandria_sarkut@my-deja.com
> >> says...
> >> > if (conditional statement)
> >> Evaluated at run time.
> >> > {
> >> > use LWP::Simple
>
> >> Evaluated at compile time, hence evaluated regardless of the value
> >> of the conditional expression (not 'statement').
> > claim a module called via a conditional statement
> > is evaluated during compilation?
> Your understanding of what 'use' does is incorrect. It doesn't
> "call" anything at compile time. The documentation for 'use'
> (perldoc -f use) will tell you that 'use' basically puts
> a 'require' in a BEGIN block for you. Whatever is in the
> BEGIN block (_regardless_ of where the BEGIN block appears
> in your code) executes before everything else. You can
> read about that in
> perldoc perlmod
Technical journal writers should be subject to
a prerequisite of a degree in English before
being allowed to contribute technical articles
for publication.
Documentation for Perl via your reference is
so poorly written, its readability ranges from
mis-leading to incomprehensible.
Definition of and agreement upon terms of usage
for discussion is a must and well abided concept
amongst trained scientists. In this case, terms
such as 'evaluated', 'loaded', 'compiled' and
'executed' are very poorly used quite often.
A module referenced by a conditional statement
is not evaluated first at compile time nor is it
executed until called, save for any initialization
code which may or may not be present. A module is
loaded into memory as a 'sub-routine' in a general
sense. It is present, basically as ascii code until
executed by direct call. It is not pulled into memory
until a portion of a script is read containing a
reference. This reference may fall anywhere within
a script and a module will be evaluated when this
reference is read, quite contrary to previous claims
of a module being evaluated before any other coding.
This term "evaluation" does apply in the sense of
checking for usual syntax errors, format errors,
just as all code is upon compile, but without
execution of any sort, dismissing initialization
when present.
A point was made in this thread regarding a
difference between behaviors of "require" and
of "use" which, in general, are correctly
worded and understandable. However, some have
suggested a module, such as LWP, is "executed"
first before anything else within a program.
This is quite inaccurate as a result of sloppy
wording and poor use of technical terms.
A statement is made:
" Perhaps you were thinking of:
eval 'use Package';
which while being useful from the perspective of deferring the use
until runtime, also fails to do the import until runtime, so
prototypes and bareword-subroutines will fail. As long as you're
going that far, I'd suggest this:
if ($some_condition) {
require Package...."
As you can clearly read, it is said "deferring the use until...."
which is immediately qualified by contrast of "...do the import...."
This author is stating a module is "executed" ("...the use....")
before any other code is executed. I disagree.
You have stated,
"Whatever is in the BEGIN block (_regardless_ of where
the BEGIN block appears in your code) executes before
everything else...."
I also disagree with this statement along with previous
statements of this nature posted within this thread.
A module is not executed until it is called, regardless
where a call is located within a script. This is quite
in evidence of my example of a LWP call. If a conditional
statement is not passed, not met, a LWP module is never
executed although present as a "sub-routine" within memory.
These claims a module is executed regardless, are simply
not accurate. However, I suspect these claims appear as
such because of difficulties in correct usage of technical
terms in discussion and within documentation. Quite contrary
to a claim of one I do not understand what is being said,
I understand all too well; quite often what is said, is
poorly worded, misleading and, at times, unreadable.
Andrea Alexandria Sarkut
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 24 Apr 2000 05:49:09 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How can I delay "use"ing a module until the module is needed?
Message-Id: <sg7o2lkocdo178@corp.supernews.com>
alexandria_sarkut@my-deja.com wrote:
: Technical journal writers should be subject to
: a prerequisite of a degree in English before
: being allowed to contribute technical articles
: for publication.
:
: Documentation for Perl via your reference is
: so poorly written, its readability ranges from
: mis-leading to incomprehensible.
That's the beauty of open source: If you think you can do better, please
do so! (My mind wanders to Utah Phillips' brilliant "Moose Turd Pie"
story <http://davytany.tripod.com/13msetrd.htm>, which I believe should be
required reading for all developers and users of open-source, cooperative-
development projects.)
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "The road of Excess leads to the Palace
of Wisdom" - William Blake
------------------------------
Date: Sun, 23 Apr 2000 23:53:58 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How can I delay "use"ing a module until the module is needed?
Message-Id: <MPG.136d8f562157ed4c98a960@nntp.hpl.hp.com>
In article <8e0kbj$g3h$1@nnrp1.deja.com> on Mon, 24 Apr 2000 04:59:37
GMT, alexandria_sarkut@my-deja.com <alexandria_sarkut@my-deja.com>
says...
...
> A module referenced by a conditional statement
> is not evaluated first at compile time nor is it
> executed until called, save for any initialization
> code which may or may not be present. A module is
> loaded into memory as a 'sub-routine' in a general
> sense. It is present, basically as ascii code until
> executed by direct call. It is not pulled into memory
> until a portion of a script is read containing a
> reference. This reference may fall anywhere within
> a script and a module will be evaluated when this
> reference is read, quite contrary to previous claims
> of a module being evaluated before any other coding.
>
> This term "evaluation" does apply in the sense of
> checking for usual syntax errors, format errors,
> just as all code is upon compile, but without
> execution of any sort, dismissing initialization
> when present.
...
> You have stated,
>
> "Whatever is in the BEGIN block (_regardless_ of where
> the BEGIN block appears in your code) executes before
> everything else...."
>
> I also disagree with this statement along with previous
> statements of this nature posted within this thread.
>
> A module is not executed until it is called, regardless
> where a call is located within a script.
It takes about two minutes of coding to put all your blather into place.
#!/usr/bin/perl -w
use strict;
print "in try.txt\n";
use foo;
__END__
#!/usr/bin/perl -w
use strict;
print "in foo.pm\n";
__END__
Output of execution of try.txt:
in foo.pm
in try.txt
Obviously the code in 'foo.pm' -- which is in no sense 'initialization'
-- is executed before the code 'try.txt'.
It is too bad that you make assertions here which are provably wrong
with minimal effort.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 24 Apr 2000 15:27:06 +0900
From: Yongsik Kim <yosikim@lgeds.lg.co.kr>
Subject: Re: I want to use the login name. How can I get the login name?
Message-Id: <3903E93A.236F13D7@lgeds.lg.co.kr>
How about starting from the following?
http://www.perl.com/pub/doc/FAQs/cgi/perl-cgi-faq.html
http://theoryx5.uwinnipeg.ca/CPAN/data/CGI.pm/CGI.html
yoon wrote:
>
> I would like to get the client's login name in my CGI file.
>
> I don't know how to get it.I am beginner.
>
> http://csweb2.cs.tamu.edu:8000/intranet-bin/comm/buildRootWin.cgi?loginId=la
> mer&passKey=EDFsdfGFG
>
> This is the hyperlink that is indicated as URL in ADDRESS BAR.
> So I think I can parse the loginId from the URL.
>
> Do you know how I can get the only loginId from URL?
>
> or If you know other ways to know the login name and assign it into new
> variable, please let me know it.
>
> Thanks!
------------------------------
Date: Mon, 24 Apr 2000 08:42:30 +0300
From: "Yaroslav F. Vishnevsky" <rick@zt.energy.gov.ua>
Subject: Re: ICQ client
Message-Id: <8e0mpu$9hc$1@relay-2.energy.gov.ua>
> > Is there a possibility to write a ICQ client with perl?
>
> It's been done.
Where?
------------------------------
Date: Mon, 24 Apr 2000 04:04:12 GMT
From: "Dimitri Ostapenko" <dimitrio@perlnow.com>
Subject: min/max
Message-Id: <0JPM4.58659$2D6.1781800@news20.bellglobal.com>
is there a better (shorter) way to get min/max of 2/many values without
loading any modules ?
I use : $min = ($a>$b)?b:a; for 2 values
and (sort {$a<=>$b} @nums)[0]; for many
while 2-nd seems concise enough for what it does, I'm too lazy and curious
about the 1st.
I'm sure this one is frequently asked question and i did try perldoc -q
Thanks
Dimitri
------------------------------
Date: Sun, 23 Apr 2000 21:35:31 -0700
From: brian@smithrenaud.com (brian d foy)
Subject: Re: min/max
Message-Id: <brian-2304002135320001@183.sanjose-13-14rs16rt.ca.dial-access.att.net>
In article <0JPM4.58659$2D6.1781800@news20.bellglobal.com>, "Dimitri Ostapenko" <dimitrio@perlnow.com> wrote:
>is there a better (shorter) way to get min/max of 2/many values without
>loading any modules ?
why don't you want to use List::Util?
--
brian d foy
Perl Mongers <URI:http://www.perl.org>
CGI MetaFAQ
<URI:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
------------------------------
Date: Mon, 24 Apr 2000 05:34:19 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: min/max
Message-Id: <sg7n6ra1cdo111@corp.supernews.com>
brian d foy (brian@smithrenaud.com) wrote:
: In article <0JPM4.58659$2D6.1781800@news20.bellglobal.com>, "Dimitri Ostapenko" <dimitrio@perlnow.com> wrote:
: >is there a better (shorter) way to get min/max of 2/many values without
: >loading any modules ?
:
: why don't you want to use List::Util?
Brian's choice is indeed The Way. But if you insist on following the path
of the Dark Side, here's OWTDI:
my @data = qw(foo bar baz quux abcd wxyz);
my ($min, $max) = (sort @data)[0, -1];
print "$min:$max\n";
This does the default lexical sort; you can of course insert your own sort
func (perldoc -f sort) to sort by whatever arbitrary criterion you
require.
Note that for long lists (where how long 'long' is depends on a lot of
factors, but is probably around 100+ items), it will be markedly more
efficient to iterate once through the list remembering highest and lowest
encountered values:
my @data = qw(foo bar baz quux abcd wxyz);
my ($min, $max) = ($data[0]) x 2;
foreach (@data) {
$min = $_ if $_ lt $min;
$max = $_ if $_ gt $max;
}
print "$min:$max\n";
But the first version gets a better golf score. :)
--
| Craig Berry - cberry@cinenet.net
--*-- http://www.cinenet.net/users/cberry/home.html
| "The road of Excess leads to the Palace
of Wisdom" - William Blake
------------------------------
Date: 24 Apr 2000 05:27:04 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Perl CGI Download
Message-Id: <slrn8g7mnt.ckb.efflandt@efflandt.xnet.com>
On 23 Apr 2000, junv@coco2.pacific.net.ph <junv@coco2.pacific.net.ph> wrote:
>
>i tried the perl code below that would allow somebody to download a given
>file via cgi, unfortunately the dialog box prompts for the cgi script
>instead of the actual filename. a quick workaround is to append a "/filename"
>at the end. is there an alternative other than this method?
Not for MSIE, which is not MIME compliant because it is based on Mosaic
which originated before there were HTTP server headers (HTTP/0.9). MSIE
bases its actions on the name of the file it thinks it is accessing.
This has nothing at all to do with Perl.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/ http://cgi-help.virtualave.net/
------------------------------
Date: Mon, 24 Apr 2000 02:26:26 GMT
From: jlamport@calarts.edu
Subject: Re: purpose of use vars () ?
Message-Id: <8e0bc6$6rf$1@nnrp1.deja.com>
In article <39036B34.AF3B56C4@geocities.com>,
steve <schan_ca@geocities.com> wrote:
> I think I have it now, but it introduce another question.
> Since you "use vars qw($yo) " to be visible outside
> " package aaa ", does that " $yo " variable pollute the
> calling script's namespace?
>
> Thanks
> Steve
Basically, the practical difference between 'use vars' and 'my' is that
'use vars' pre-declares PACKAGE-scoped variables, whereas 'my' pre-
declares FILE-scoped variables.
say you have a file 'aaa.pm':
package aaa;
use strict;
use vars '$package_var';
my $file_var;
If your main script loads aaa.pm (using either use or require), then your
main script will be able to access $package_var as $aaa::package_var (but
not as just $package_var, unless the main script explicitly imports it
into its namespace or the package aaa explicitly exports it into package
main's namespace, see the perlmod docs for details on how to do those
things), but the main script will *not* be able to access $file_var *at
all* -- $file_var is strictly local to the file aaa.pm.
Hope that helps.
-jason
>
> =======================================
>
> msouth@fulcrum.org wrote:
>
> > To summarize:
> >
> > In file 'fileaaa', if you have
> >
> > package aaa;
> > use strict;
> >
> > use vars qw($yo);
> > my $ya;
> >
> > $yo = 1; # that's really $aaa::yo, visible outside
> > $ya = 2; # that's not $aaa::ya, and not visible outside
> >
> > sub foo {
> > print "yo is $yo, ya is $ya\n";
> > }
> > 1;
> >
> > Then in file 'useaaa.pl' you have
> >
> > #!/usr/bin/perl -w
> > use strict;
> > require 'fileaaa';
> >
> > print "aaa::yo is $aaa::yo \n";
> > print "aaa::ya is $aaa::ya \n";
> >
> > print "here's what &aaa::foo says:\n";
> >
> > &aaa::foo();
> >
> > the output is:
> >
> > Name "aaa::yo" used only once: possible typo at useaaa.pl line 5.
> > Name "aaa::ya" used only once: possible typo at useaaa.pl line 6.
> > aaa::yo is 1
> > Use of uninitialized value at useaaa.pl line 6.
> > aaa::ya is
> > here's what &aaa::foo says:
> > yo is 1, ya is 2
> >
> > See how $aaa::ya gives you an unitialized value warning? Nobody
> > initialized it, $ya, a my() variable in fileaaa, is not related
> > to $aaa::ya, and not visible outside fileaaa. However, the
> > subroutine &aaa::foo is in package aaa, and it:
> >
> > a) can see $ya, knowing its value is 2
> >
> > and
> >
> > b) knows that $yo means $aaa::yo in fileaaa, because use vars
> > declared that to be so.
> >
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 24 Apr 2000 04:22:36 GMT
From: steve <schan_ca@geocities.com>
Subject: Re: purpose of use vars () ?
Message-Id: <3903CD59.9EBFCFAD@geocities.com>
Got it. Thanks man.
Steve.
==========================================
jlamport@calarts.edu wrote:
> In article <39036B34.AF3B56C4@geocities.com>,
> steve <schan_ca@geocities.com> wrote:
> > I think I have it now, but it introduce another question.
> > Since you "use vars qw($yo) " to be visible outside
> > " package aaa ", does that " $yo " variable pollute the
> > calling script's namespace?
> >
> > Thanks
> > Steve
>
> Basically, the practical difference between 'use vars' and 'my' is that
> 'use vars' pre-declares PACKAGE-scoped variables, whereas 'my' pre-
> declares FILE-scoped variables.
>
> say you have a file 'aaa.pm':
>
> package aaa;
> use strict;
> use vars '$package_var';
> my $file_var;
>
> If your main script loads aaa.pm (using either use or require), then your
> main script will be able to access $package_var as $aaa::package_var (but
> not as just $package_var, unless the main script explicitly imports it
> into its namespace or the package aaa explicitly exports it into package
> main's namespace, see the perlmod docs for details on how to do those
> things), but the main script will *not* be able to access $file_var *at
> all* -- $file_var is strictly local to the file aaa.pm.
>
> Hope that helps.
>
> -jason
------------------------------
Date: Sun, 23 Apr 2000 23:54:02 -0400
From: "RMB" <rmb34NOSPAM@mindspring.com>
Subject: Show me if you don't mind
Message-Id: <8e0k13$jj5$1@nntp9.atl.mindspring.net>
Hey d'ere-
For you seasoned Perl programmers, I had a question. Could you send me some
of your code and a description of what it does? I would like to see what
nicely written Perl script looks like.
I just begun learning Perl and I would like to see some real-world perl
script.
Just email it to me at rmb34@mindspring.com
I truly appreciate it.
Later,
RMB
------------------------------
Date: Mon, 24 Apr 2000 04:19:00 GMT
From: steve <schan_ca@geocities.com>
Subject: socket fd exit with child?
Message-Id: <3903CC81.8199041C@geocities.com>
Hello:
A child process opens a socket fd
my ($socket) = IO::Socket::INET->new( Proto => 'tcp',
PeerAddr => $server,
PeerPort => $service_port,
Reuse => 1 );
if you exit the child process via an alarm,
do you have to explicitly close the socket
or will the OS close the socket fd and any
other fd belonging to the child automatically
upon child exit?
Thanks
Steve
------------------------------
Date: 24 Apr 2000 05:22:55 GMT
From: Mathias Koerber <mathias@singapura.singnet.com.sg>
Subject: wierd behaviour untainting...
Message-Id: <8e0lnf$qo7$1@mawar.singnet.com.sg>
I have a function which starts like this:
sub provision {
print "##1 @_ <BR>";
my($server,$domain,$alias,$target) = @_;
my($ssh_str);
print "##2 $server:$domain:$alias:$target <BR>\n" if $debug;
# untaint
$server =~ /^([\w.]*)$/;
$server = $1;
$domain =~ /^([\w.]*)$/;
$domain = $1;
$alias =~ /^([\w.]*)$/;
$alias = $1;
$target =~ /^([\w.]*)$/;
$target = $1;
print "###3 $server:$domain:$alias:$target <BR>\n" if $debug;
[...]
whose output when called is this:
##1 heleconia abc myself abc@def
##2 heleconia:abc:myself:abc@def
##3 heleconia:abc:myself:myself
I have no clue why that last parameter (target) gets replaced with the
previous one during the untainting..
WOuld anyone be able to enlighten me?
(I guess it must be very obvious and normal, but I've been staring at it for
hours now w/o a solution :-(
any help is appreciated...
# perl -V
Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
Platform:
osname=linux, osvers=2.2.5-22smp, archname=i386-linux
uname='linux porky.devel.redhat.com 2.2.5-22smp #1 smp wed jun 2 09:11:51 edt 1999 i686 unknown '
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef useperlio=undef d_sfio=undef
Compiler:
cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
stdchar='char', d_stdstdio=undef, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
alignbytes=4, usemymalloc=n, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lc -lposix -lcrypt
libc=, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Built under linux
Compiled at Aug 30 1999 23:09:51
@INC:
/usr/lib/perl5/5.00503/i386-linux
/usr/lib/perl5/5.00503
/usr/lib/perl5/site_perl/5.005/i386-linux
/usr/lib/perl5/site_perl/5.005
--
Mathias Koerber | Tel: +65 / 471 9820 | mathias@staff.singnet.com.sg
SingNet NOC | Fax: +65 / 475 3273 | mathias@koerber.org
Q'town Tel. Exch. | PGP: Keyid: 768/25E082BD finger mathias@singnet.com.sg
2 Stirling Rd | 1A 8B FC D4 93 F1 9A FC BD 98 A3 1A 0E 73 01 65
S'pore 148943 | Disclaimer: I speak only for myself
There are 3 types of people in the world, those who make things happen,
those who watch things happen and those who wonder what just happened.
------------------------------
Date: 24 Apr 2000 05:42:18 GMT
From: <ben@leedsnet.com>
Subject: Re: Win32::OLE with Word 97
Message-Id: <8e0mrq$q59$1@supernews.com>
Cameron Dorey <camerond@mail.uca.edu> wrote:
> Patrick Renaud wrote:
>>
>> Hello,
>>
>> I'm using Win32::OLE with Word 95 since a long time and all is ok.
>>
>> The problem is that my system manager has installed Word 97 instead and
>> nothing works correctly.
>>
>> Do you have an idea ?
One good plan would lie somewhere between explaining to your manager
that he or she has caused you inconvenience, and getting a new manager.
If Word 95 works for you, don't change it. I use a Mac and have a copy
of Word 5.1 lying around (about 1992 vintage). Not using later versions
has saved installation time and effort, and the waste of trying to
learn new software.
Ben.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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.
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 V9 Issue 2850
**************************************