[12760] in Perl-Users-Digest
Perl-Users Digest, Issue: 170 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 16 17:17:33 1999
Date: Fri, 16 Jul 1999 14:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 16 Jul 1999 Volume: 9 Number: 170
Today's topics:
Re: Q: passing array/hash from one subroutine to anothe <jrennie@mitre.org>
Re: Q: passing array/hash from one subroutine to anothe <tchrist@mox.perl.com>
Re: Q: passing array/hash from one subroutine to anothe <jrennie@mitre.org>
Re: Remove leading zeros from a string (Abigail)
Re: Remove leading zeros from a string (Abigail)
Re: Remove leading zeros from a string <tchrist@mox.perl.com>
Re: Remove leading zeros from a string <uri@sysarch.com>
Re: Remove leading zeros from a string (Bart Lateur)
Re: search script <bloodlet19@hotmail.com>
Re: searching man pages, perldoc's, FAQ's, README's, HO <tchrist@mox.perl.com>
Re: Simple Question: How do I call a subroutine in a di (Abigail)
Re: Tiny error in perlfaq5 (Bart Lateur)
Re: Tiny error in perlfaq5 (John Borwick)
Re: Tiny error in perlfaq5 (John Borwick)
URL Verification <toinbo@hotmail.com>
Re: Where to start with perl programming ? (I R A Aggie)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 16 Jul 1999 15:14:58 -0400
From: "Jason D. Rennie" <jrennie@mitre.org>
To: anna@water.ca.gov
Subject: Re: Q: passing array/hash from one subroutine to another subroutine
Message-Id: <378F84B2.762D1E64@mitre.org>
anna@water.ca.gov wrote:
>
> I have an array and hash that I want to pass from one subroutine to
> another subroutine. But I don't know how to do it. Can you help?
If I were you, I would do this with references. Say I have a hash,
%foo and a list (or array), @bar that I want to pass to a function
&baz. If I pass references:
$fooref = \%foo;
$barref = \@bar;
&baz ($fooref, $barref);
then I can access both of them from within the subroutine:
sub baz
{
my ($fooref, $bazref) = @_;
print $fooref->{"some_key"}, "\n";
print $barref->[0], "\n";
}
For more information about passing things to functions, see
http://language.perl.com/newdocs/pod/perlfaq7.html
How can I pass/return a {Function, FileHandle, Array, Hash, Method,
Regexp}?
Jason Rennie
781-271-7281
jrennie@mitre.org
http://www.andrew.cmu.edu/~jr6b/
------------------------------
Date: 16 Jul 1999 13:19:18 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Q: passing array/hash from one subroutine to another subroutine
Message-Id: <378f85b6@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, anna@water.ca.gov writes:
:I have an array and hash that I want to pass from one subroutine to
:another subroutine. But I don't know how to do it. Can you help?
:
:Here's what I want to pass:
:--------------------------
:$sensor_list{$sensor_num} = $sensor_name;
:push (@sensors,$sensor_num);
You're saying you want to pass %sensor_list and @sensors, right?
What part of the "Pass by Reference" in the standard perlsub manpage that
comes with every included with every distribution of Perl did you find
particularly unclear? Barring that, what part of the question on "How
can I pass/return a {Function, FileHandle, Array, Hash, Method, Regexp}?"
in the standard perlfaq7 manpage that comes with every included with every
distribution of Perl did you find particularly unclear? Patches welcome.
--tom
--
"Bigotry dwarfs the soul by shutting out the truth."
- Edwin Hubbel Chaplin
------------------------------
Date: 16 Jul 1999 20:29:34 GMT
From: Jason Rennie <jrennie@mitre.org>
Subject: Re: Q: passing array/hash from one subroutine to another subroutine
Message-Id: <7mo4ne$5nj$1@top.mitre.org>
jbalwit@linfield.edu said:
> Thanks so much Jason for your clear reply. I didn't ask the question
> originally but it was exactly what I needed to know. I had one other
> question though--If you create a Hash inside one subroutine can you
> pass it back to the main namespace so that it can be used in other
> subroutines? Look below in your sub 'baz' to see what I want to do.
Yup, you sure can. I do this on a regular basis. If you want to
return a single list or hash, it should be okay to return it exactly as
your example shows:
>sub baz
>{
> my ($fooref, $bazref) = @_;
>
> print $fooref->{"some_key"}, "\n";
> print $barref->[0], "\n";
# change array somehow ??
# does this work?
return %foo;
>}
>
So, something like "%foo = &baz ($fooref, $barref)" should work as you
might expect it to. However, returning multiple data structures (lists,
hashes) won't work like you expect it unless you use hashes. You could
do "return \%foo, \@bar;" At the other end, you would have to deal
with references (the blue camel book, chapter 4, gives lots of info
about how to deal with references).
Enjoy!
Jason Rennie
781-271-7281
jrennie@mitre.org
http://www.andrew.cmu.edu/~jr6b/
------------------------------
Date: 16 Jul 1999 14:56:02 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Remove leading zeros from a string
Message-Id: <slrn7ov3hj.c9j.abigail@alexandra.delanet.com>
Simon Kerr (skerr@ryder.co.uk) wrote on MMCXLV September MCMXCIII in
<URL:news:378f29b3.0@nnrp1.news.uk.psi.net>:
{} Hi,
{}
{} I have a string, such as '00001234'. All I want to do is remove the leading
{} zeros. The length of the string can vary, so I can't just chop off the
{} first n characters.
{}
{} Can anyone help, or point me in the right direction. If it's in perldoc,
{} then I can't find it!
The FAQ explains how to remove leading spaces. You'd think you can read
that part of the FAQ, and figure out the difference between a space and
a 0?
Abigail
--
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 16 Jul 1999 14:57:16 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Remove leading zeros from a string
Message-Id: <slrn7ov3js.c9j.abigail@alexandra.delanet.com>
Bill Cox (bilcox@unx.sas.com) wrote on MMCXLV September MCMXCIII in
<URL:news:378f4a1f.1902623868@newshost.unx.sas.com>:
!!
!! Why not just use a reg exp to remove zeros.
!!
!! $n = '000001234';
!! $n =~ s/^0+//g;
Could you give an example of a string that has more than one
leading sequence of 0s?
Abigail
--
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 16 Jul 1999 14:11:51 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Remove leading zeros from a string
Message-Id: <378f9207@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc,
abigail@delanet.com writes:
:!! $n = '000001234';
:!! $n =~ s/^0+//g;
:
:Could you give an example of a string that has more than one
:leading sequence of 0s?
$* = 1;
$n = "000001234\n" x 10;
$n =~ s/^0+//g;
But I do not pretend to imagine that they were thinking that.
--tom
--
Because . doesn't match \n. [\0-\377] is the most efficient way to match
everything currently. Maybe \e should match everything. And \E would
of course match nothing. :-) --Larry Wall in <9847@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: 16 Jul 1999 16:22:39 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Remove leading zeros from a string
Message-Id: <x7iu7kjqeo.fsf@home.sysarch.com>
>>>>> "TC" == Tom Christiansen <tchrist@mox.perl.com> writes:
TC> :Could you give an example of a string that has more than one
TC> :leading sequence of 0s?
TC> $* = 1;
TC> $n = "000001234\n" x 10;
TC> $n =~ s/^0+//g;
TC> But I do not pretend to imagine that they were thinking that.
but what if the numbers were not on per line, the ^ will not find their
beginnings.
s/(?:^|(?<=\D))0+//gm ;
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: Fri, 16 Jul 1999 20:44:57 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Remove leading zeros from a string
Message-Id: <37909924.792402@news.skynet.be>
Bill Cox wrote:
>Why not just use a reg exp to remove zeros.
>
>$n = '000001234';
>$n =~ s/^0+//g;
Oops.
$n = '00000';
$n =~ s/^0+//;
print $n;
-->
nada
I think "0" is expected.
$n =~ s/^0+(?=\d)//;
There. Leave at least one leading digit.
Bart.
------------------------------
Date: Fri, 16 Jul 1999 20:34:13 GMT
From: bandhunt <bloodlet19@hotmail.com>
Subject: Re: search script
Message-Id: <7mo505$q9k$1@nnrp1.deja.com>
There are some free search scripts @ these URL's.
They should be a good reference point.
http://cgi.resourceindex.com/Programs_and_Scripts/Perl/Searching/Searchi
ng_Your_Web_Site/
http://www.freecode.com/webhost.html
Also you can check out this article called "Roll your own search engine"
http://www.hotwired.com/webmonkey/code/97/16/index2a.html?tw=backend
Good Luck,
D.J.
In article <932130256.997.95@news.remarQ.com>,
"Jody Thigpen" <fast_styx@hotmail.com> wrote:
> I'm relatively new to Perl, but not actually a beginner, and I'm
working on
> what will be my first website search script. Does anyone have or
know where
> I could find an example of just such a thing designed to search
through a
> site that I might use as a refernce? I'd like to compare and see
where I'm
> making my mistakes.
>
> Thanks,
>
> Jody Thigpen
> jthigpen@socket.net
>
>
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: 16 Jul 1999 13:26:21 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: searching man pages, perldoc's, FAQ's, README's, HOWTO's, etc.
Message-Id: <378f875d@cs.colorado.edu>
[courtesy cc of this posting mailed to cited author]
In comp.lang.perl.misc, "David Christensen" <dchristensen@california.com> writes:
:Is there a way to search man pages, perldoc's, FAQ's, README's,
:HOWTO's, etc.?
grep ye first the wisdom of pod,
and its obviousness.
then all these things
shall be answered unto you
hallelu hallelujah.
--tom
--
> This made me wonder, suddenly: can telnet be written in perl?
Of course it can be written in Perl. Now if you'd said nroff,
that would be more challenging... --Larry Wall
------------------------------
Date: 16 Jul 1999 14:58:29 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Simple Question: How do I call a subroutine in a different file?
Message-Id: <slrn7ov3m7.c9j.abigail@alexandra.delanet.com>
Don Soloway (don@infi.net) wrote on MMCXLV September MCMXCIII in
<URL:news:378ed84d.76870456@news.supernews.com>:
|| I would like to creat a file of subroutines and be able to call them
|| from perl scripts. The subroutines take parameters and returns one.
|| What is the simplest way of doing this?
Perl has various ways of doing this. And it's all in the manual.
Abigail
--
perl -MNet::Dict -we '(Net::Dict -> new (server => "dict.org")
-> define ("foldoc", "perl")) [0] -> print'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Fri, 16 Jul 1999 20:40:02 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Tiny error in perlfaq5
Message-Id: <378f97e5.473453@news.skynet.be>
John Stanley wrote:
>>Tell me you're joking.
>
>???
>
>But I don't see where what I said has anything to do with what
>rand() returns, only what rand(0) returns.
My mistake. The whole thread is about what rand() returns, and of the
fact that it may occasionally return zero.
I understood what you said as "if it returns 0, now it will return 1".
Which *would* have been related to the thread. You seem to be jumping to
another subject, which confused me. I'm still not sure why you brought
it up.
Bart.
------------------------------
Date: Fri, 16 Jul 1999 20:19:34 GMT
From: John.Borwick@sas.com (John Borwick)
Subject: Re: Tiny error in perlfaq5
Message-Id: <379c9395.115808313@newshost.unx.sas.com>
On 16 Jul 1999 16:51:16 GMT, stanley@skyking.OCE.ORST.EDU (John
Stanley) wrote:
>>rand() is supposed to be >=0, but <1.
>You could look at the code yourself to see. It is, after all, open
>source. But I don't see where what I said has anything to do with what
>rand() returns, only what rand(0) returns. When the parameter to the
>funtion is 0, 1 is used instead. I suppose that is because "rand(0)"
>would otherwise always return 0 and that isn't a very random sequence at
>all.
Doesn't replacing the occurrence x=0 with x=1 make the value less
random?
Also the range is supposed to be from the CLOSED interval 0 upwards,
so 0 is *supposed* to be a possibility, as I understand.
--
John Borwick
------------------------------
Date: Fri, 16 Jul 1999 20:21:05 GMT
From: John.Borwick@sas.com (John Borwick)
Subject: Re: Tiny error in perlfaq5
Message-Id: <379d93f2.115901667@newshost.unx.sas.com>
On Fri, 16 Jul 1999 16:44:40 GMT, bart.lateur@skynet.be (Bart Lateur)
wrote:
>>The code $hits = int( (time() - 850_000_000) / rand(1_000) );
>>will occasionally generate a division by zero error.
>So fix it.
> $hits = int((time() - 850_000_000) / (1_000 * (1-rand)));
I like your solution. I would fix it myself, except it's in the FAQ.
--
John Borwick
------------------------------
Date: Fri, 16 Jul 1999 22:52:30 +0200
From: "Toinbo & Renbo" <toinbo@hotmail.com>
Subject: URL Verification
Message-Id: <7mo5is$46p$1@news3.Belgium.EU.net>
Hi,
I would like to know how to make a script that tests if an URL given by
a visitor exists.
For exemple, you write http://www.yourdomain.com/image.gif The script
checks if the image exists. If it exists, it continues but if it doesn't
exist, the script write a message saying that the image doesn't exist.
Thanks
Toinbo
------------------------------
Date: 16 Jul 1999 19:13:28 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Where to start with perl programming ?
Message-Id: <slrn7ov171.lpe.fl_aggie@thepentagon.com>
On Fri, 16 Jul 1999 15:14:36 GMT, arpith@hotmail.com <arpith@hotmail.com>, in
<7mni8g$hv0$1@nnrp1.deja.com> wrote:
+ I have no access to CGI hosting webservers. Can I run the scripts
+ on my home computer ?
Sure, if you are using CGI.pm. You can run them in "off-line mode",
and either enter your expected data from the keyboard, or from a
input file.
+ What webserver would you recommend ? where can I find more help ?
Obviously apache, and I even think they have a win32 version.
<url:http://www.apache.org/>.
+ I really need help starting out and am really lost!
Do you know any programming? you may want to look at _Learning Perl_
or possibly _Programming Perl_, depending on your level of skill and
comfort with the material.
James
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
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 V9 Issue 170
*************************************