[7236] in Perl-Users-Digest
Perl-Users Digest, Issue: 861 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 13 15:27:12 1997
Date: Wed, 13 Aug 97 12:01:44 -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 Wed, 13 Aug 1997 Volume: 8 Number: 861
Today's topics:
Perl and HTTP rob@persimmon.com
Re: Perl Interface to /etc/passwd (Bob)
Re: Perl String truncation (Ed Vielmetti)
Re: Problem with ENV{REMOTE_USER} (Bob)
random numbers (David Cheitel)
Re: Set $! after success system call <rootbeer@teleport.com>
split perl string <dannyl@computize.com>
Re: Time problem. (Chris Russo)
Re: Time problem. <rootbeer@teleport.com>
Re: typeglob in perl 4 and 5 (Terry von Gease)
Re: typeglob in perl 4 and 5 <rootbeer@teleport.com>
Using Parameter (variables) files <ttucker@stirlingsystems.com>
Re: version of Perl5 for NT4 <tmcgee@psa.com>
Re: Why warning of uninitialized value even if it is in (Thomas Honigmann)
Re: Will Pay: Write this script for me! (Bob)
WIN32Perl vs. Perl ( ~= and =~) <mbosley@games-online.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 13 Aug 1997 11:41:03 -0600
From: rob@persimmon.com
Subject: Perl and HTTP
Message-Id: <871490111.16183@dejanews.com>
Does anyone have a Perl script that initiates an HTTP connection
and performs a POST action, or even a GET? I'm new to sockets
and am just looking for some examples.
Thanks
Rob
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Wed, 13 Aug 1997 16:38:39 GMT
From: xxbbell@voicenet.com (Bob)
Subject: Re: Perl Interface to /etc/passwd
Message-Id: <33f1e2fd.167675806@netnews.voicenet.com>
Thanks for the replies!
--
- Bob
http://www.voicenet.com/~bbell
xxbbell@voicenet.com
remove x's to reply
------------------------------
Date: 13 Aug 1997 17:24:45 GMT
From: emv@umich.edu (Ed Vielmetti)
Subject: Re: Perl String truncation
Message-Id: <5ssqkt$8i3$1@hawk.branch.com>
Thomas Winzig (tsw@pvo.com) wrote:
: Mwebernet wrote:
: >
: > I have a string that is very long. I want to chop it off at 50
: > charectors. How can I do this?
: One of two ways:
: 1) Go to http://www.ora.com/ and buy the Programming Perl book. Flip
: to Chapter 3 and enjoy! :-)
: 2) $shortstring = substr($longstring, 0, 50);
You haven't specified the whole problem. If the very long strong turns
out to be short instead, what do you want to have happen?
3) Use pack (and the shortstring will be null filled)
$shortstring = pack "a50", $longstring;
4) Use regular expressions (and there will be no shortstring at all if it's not short)
if ($longstring =~ /(.{50})/) { $shortstring = $1 };
5) Use regex (and there will be no shortstring if longstring is null)
if ($longstring =~ /(.{1,50})/) { $shortstring = $1 };
6) Use split and join. (Left as an exercise to the reader).
thanks
Ed
Edward Vielmetti
emv@umich.edu
------------------------------
Date: Wed, 13 Aug 1997 16:57:51 GMT
From: xxbbell@voicenet.com (Bob)
Subject: Re: Problem with ENV{REMOTE_USER}
Message-Id: <33f4e757.168789864@netnews.voicenet.com>
"Mai Yang [I]" <yangma@cig.mot.com> wrote:
>I need to know the name of the person who is accessing my homepage. I
>examined the enviroment variable ENV{REMOTE_USER} and ENV{HTTP_FROM} to
>get the user's name and email. But both turned out to be null. I then
>displayed all the enviroment variables. I found the above two variables
>were not defined at all.
>
>Can anyone give me any suggestions or reasons for this? Thanks a lot.
I successfully use $ENV{'REMOTE_USER'}, but it is on an
htaccess/htpasswd site. I don't know if it is set otherwise.
Bob
--
- Bob
http://www.voicenet.com/~bbell
xxbbell@voicenet.com
remove x's to reply
------------------------------
Date: Tue, 12 Aug 1997 16:10:56 GMT
From: david1@earthlink.net (David Cheitel)
Subject: random numbers
Message-Id: <5ssmo1$lm4@chile.earthlink.net>
I am writing a test generation script in perl. The questions that are given
are random.
I am familiar with the rand function but I need to generate 15 random numbers
from a range of 1 to 30 that are unique from each other. The rand function
does not guarantee this.
Please reply to david1@earthlink.net
------------------------------
Date: Wed, 13 Aug 1997 08:35:33 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Clark Dorman <clark@s3i.com>
Subject: Re: Set $! after success system call
Message-Id: <Pine.GSO.3.96.970813082233.10950N-100000@julie.teleport.com>
On 13 Aug 1997, Clark Dorman wrote:
> $anls = `ls` or die "Die: ($!)";
This may not be doing what it looks like it's doing. If the command in
backticks can't be run (or if it produces no output or one other unlikely
case) the die will be executed - but the value of $! may not be set, for
somewhat technical reasons. You probably want the value from $? (which is
not a message, but just a number) to see whether the backtick command
succeeded.
$anls = `ls`;
die "ls command returned exitstatus $?" if $?;
For those technical reasons mentioned earlier, running a process with
system or backticks (or upon closing a process opened on a pipe) will
return an exit status in $? instead of setting the magical $! variable.
Anything in $! is probably left over from some other operation, and won't
normally have anything to do with the success or failure of the other
process.
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 13 Aug 1997 09:24:01 -0500
From: Danny LaPrade <dannyl@computize.com>
Subject: split perl string
Message-Id: <33F1C381.2083@computize.com>
How do I split at string like
"here1here2here3here4here5here6here7"
every 5th character?
And all are char (s).
I want to be able to take this string
and split it every five chars and the string
can be anywhere from 0 to 100 chars long.
Also want to be able to compare each to a string.
Can anyone help ?
Need something efficient.
--
--------------------------------------------------------------
-- Danny LaPrade
-- Advertising - Web Development
-- 1030 Wirt Road #400
-- Houston, Texas 77055-6849
-- 713.957.0057 ext 211
-- 713.613.4812 Fax
--
-- http://www.computize.com/
--------------------------------------------------------------
"Hold on to your dreams while pulling
through the present. "
------------------------------
Date: Wed, 13 Aug 1997 08:28:43 -0700
From: crusso@alink.net (Chris Russo)
Subject: Re: Time problem.
Message-Id: <crusso-1308970828430001@buzz.alink.net>
In article <33F1AD35.8026CA7D@idnopheq.moc>, Paul Jorgensen
<b1ff@idnopheq.moc> wrote:
>Hi.
>
>Yeah. Same thing here. I reasoned that Perl (or my OS) counts months
>beginning at 0 insted of 1. What is the ruling on this?
>
>Charles Boone wrote:
>
>> I am using perl to gather some info from wtmp. I just happened to
>> notice that when I convert the login time it gives me the wrong month
>> ex. 7 for Aug instead of 8. I was wandering if there is a bug in
>> 5.003 or what. Please email me ccboone@amber.indstate.edu
Heaven forbid you guys so much as glance at the documentation. Let's see,
on a UNIX system, to get that information (assuming I didn't know to look
at perlfunc):
man perl
man perlfunc
/localtime
n
Why wouldn't you do that and get the answer right away rather than to post
to USENET, wait a day or so, look like a newbie, etc.?
Anyway,
Chris Russo
----------------------------------------------------------------------
Chris Russo A-Link Network Services, Inc.
crusso@alink.net Bolo me
http://www.alink.net/~crusso
------------------------------
Date: Wed, 13 Aug 1997 10:25:50 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Paul Jorgensen <b1ff@idnopheq.moc>
Subject: Re: Time problem.
Message-Id: <Pine.GSO.3.96.970813102507.10950a-100000@julie.teleport.com>
On Wed, 13 Aug 1997, Paul Jorgensen wrote:
> Yeah. Same thing here. I reasoned that Perl (or my OS) counts months
> beginning at 0 insted of 1. What is the ruling on this?
It's the OS which does it. Since it's documented, it's not a bug. :-)
Hope this helps!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 13 Aug 1997 16:01:37 GMT
From: twv@rose.hp.com (Terry von Gease)
Subject: Re: typeglob in perl 4 and 5
Message-Id: <5sslp1$3h5$1@rosenews.rose.hp.com>
Tom Phoenix (rootbeer@teleport.com) wrote:
>On 13 Aug 1997, Terry von Gease wrote:
>> Is there some sort of change to the way typeglobs are handled from
>> perl 4 to perl 5?
>>
>> In perl 4 I could say something like...
>>
>> $hash{'abc'}="some data";
>>
>> foreach (@list) {
>> &myfunct(*hash);
>> }
>>
>> sub myfunct {
>> local(*scrap)=@_;
>>
>> $val=$scrap{'abc'};
>>
>> }
>>
>> And the value of $val in myfunct would indeed be set to "some data".
>
>Not unless you put something into @list. Once I do that, it does what I
>think you want in my tests under 5.004 and other versions I have sitting
>around.
It's a given that there's something in @list, I didn't fall off the turnip
truck.
>
>> If I try this with perl5, the %scrap array in myfunct is empty, as in
>> null.
>
>That's what I get when @list is empty, but that's what I'd expect
>to get. :-)
>
>> In order to make it work in perl5 i have to add a line in the foreach
>> loop...
>
>> foreach (@list) {
>> local(*hash)="hash"; #### add this line to make it work
>> &myfunct(*hash);
>> }
>
>That doesn't make any difference in my tests, but maybe I'm missing
>something. I think one of us is. :-)
>
>Seriously, if you can come up with a script which works in version 4 but
>not in 5, and if the reason isn't already documented in the perltrap(1)
>manpage, please submit it with perlbug.
I hage a script that runs in 4 but not in 5. It's part of a larger
system and it's well nigh impossible to distill it down to just the
failing pieces in any sort of reasonable time. Moreover, if you
use the per debugger and display just the right variables at
just the right lines, it works fine.
The actual problem is a lot more complicated that what I gave for
an example, I was just trying to find out if there were any issues
dealing with the mishandling of typeglobs.
Let me see if I can give a crude picture of just what is going on...
1. at some point in some subroutine we do...
...
@varlist=&funct1{"abc__xyz");
...
sub funct1 {
local($name)=@_;
local(*var1)=$name;
...
@var1; #set return value
2. at some later point we do...
...
%var1=split(":",$varlist[0]);
local(@nlist)=&funct2(1,*var1);
...
sub funct2 {
local($idx,*var1)=@_;
at this point, as viewed with the perl debugger, a 'p @_' reveals...
perl 5 >> '1*main::abc__xyz'
perl 4 >> '1*main'var1'
Perl 4 has the correct name, while perl5 seems to be stuck on the
last use of *var1.
Note that it would seem that if I break in funct1 and look
around, then perl 5 seems to get it right. I'm not certain of
this as it's merely a secondary effect right now. At leat to
me and I have a host of other things on my mind.
Also note that the examples I gave bear only a gross functional
relationship to the actual script.
But just to show that mu heart's in the right place, here's a
script that works in perl4 but not in perl5...
#########################################
#!/usr/local/bin/perl
sub funct1 {
local($name)=@_;
local(*var1)=$name;
@var1=("1:a:2:b:3:c:4:d");
@var1;
}
sub funct2 {
local($idx,*var1)=@_;
$var1{$idx};
}
@varlist=&funct1("abc__xyz");
%var1=split(":",$varlist[0]);
foreach (keys(%var1)) {
$x=&funct2($_,*var1);
print $x,"\n";
}
##########################################
perl4 -v reveals...
$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36
perl5 -v reveals...
This is perl, version 5.003 with DEBUGGING EMBED
built under hpux at May 2 1997 14:31:37
+ suidperl security patch
--
Terry You'll get further with a smile and a gun
than just a smile.
------------------------------
Date: Wed, 13 Aug 1997 10:30:01 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Terry von Gease <twv@rose.hp.com>
Subject: Re: typeglob in perl 4 and 5
Message-Id: <Pine.GSO.3.96.970813102629.10950b-100000@julie.teleport.com>
[ The message you sent me by e-mail didn't tell me that you'd posted as
well. ]
On 13 Aug 1997, Terry von Gease wrote:
> But just to show that mu heart's in the right place, here's a
> script that works in perl4 but not in perl5...
>
> #########################################
> #!/usr/local/bin/perl
>
> sub funct1 {
> local($name)=@_;
> local(*var1)=$name;
> @var1=("1:a:2:b:3:c:4:d");
> @var1;
> }
>
> sub funct2 {
> local($idx,*var1)=@_;
>
> $var1{$idx};
> }
>
> @varlist=&funct1("abc__xyz");
> %var1=split(":",$varlist[0]);
> foreach (keys(%var1)) {
> $x=&funct2($_,*var1);
> print $x,"\n";
> }
>
> ##########################################
Thanks; that helped me to track it down. And here's the bug! The perltrap
manpage says this:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
=item * (Globs)
glob assignment from variable to variable will fail if the assigned
variable is localized subsequent to the assignment
@a = ("This is Perl 4");
*b = *a;
local(@a);
print @b,"\n";
# perl4 prints: This is Perl 4
# perl5 prints:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
That doesn't fix things, I know, but I hope it helps to know that this is
the expected behavior. Good luck with your project!
--
Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 13 Aug 1997 10:26:42 +0000
From: Trent Tucker <ttucker@stirlingsystems.com>
Subject: Using Parameter (variables) files
Message-Id: <33F18BD5.4661@stirlingsystems.com>
Howdy-
I'm a newbie at PERL, and though I've looked through the Llama Book
and FAQs for a solution to my simple problem, I haven't been able to
come up with the answer.
All I'm looking for is snippets of code for:
A) creating (exporting) delimited key/value pairs to a "variables"
text file (note: they need to be delimitted since some values may
be longer than 1 line),
and
B) reading (importing) previously created key/value pairs into an
associative array from a "variables" text file.
Basically, what I'm trying to do is use one script to collect some
data and store it in a text file, and then use another script to
process the data. The storing is no problem. What I don't know
how to do it slurp it back into the second script and reestablish
the variables. The additional wrinkle that I have is that some
values may be more than one line long.
I'm sure that this is a simple matter, I just haven't been able
to find the code to do it. If someone can send me some guidance on
how the text file needs to be formatted, and some code for parsing
the variables back into the second script, I'd be eternally greatful.
Thank you very much in advance.
Best Regards,
Trent Tucker
------------------------------
Date: Wed, 13 Aug 1997 11:30:51 -0400
From: Tom McGee <tmcgee@psa.com>
Subject: Re: version of Perl5 for NT4
Message-Id: <33F1D32B.6C83@psa.com>
John Scriven wrote:
>
> Hi!
>
> I am looking for a vesion of Perl working under NT4.
> I haven't found anything on the homepage of Perl.
> Can you help with this please?
>
> by the way any explanations, tips or links about how to install
> Perl on NT4 for is welcome.
>
> Thanks
>
> Please reply at this e-mail address :
> michauts@adc.port.ac.uk
>
> --
Look at http://www.perl.hip.com/ for the Win32 versions.
--Tom
------------------------------
Date: 13 Aug 1997 15:39:44 GMT
From: honig@kummer.mathematik.hu-berlin.de (Thomas Honigmann)
Subject: Re: Why warning of uninitialized value even if it is initialized?
Message-Id: <5sskg0$ljo@suncom.rz.hu-berlin.de>
In article <xz27mdqgw2f.fsf@uebemc.siemens.de>, Ronald Fischer wrote:
>The command
> perl -w -e 'local($a)="abc"; open($a)'
>produces the warning
> Use of uninitialized value at -e line 1.
>In Perl 5.002.
>Could someone please confirm if this still appears in 5.004, or if the
>warning is correct in this case?
The warning is there in 5.004 (tested on Solaris 2.5) and is IMHO correct.
Look up open() in the perlfunc manpage: if the second argument is omitted,
the scalar variable of the same name as the FILEHANDLE (first argument)
contains the filename. The FILEHANDLE here is named 'abc' and so perl
is looking for the scalar $abc which indeed is undefined and causes the
warning.
HTH,
Thomas
------------------------------
Date: Wed, 13 Aug 1997 16:52:02 GMT
From: xxbbell@voicenet.com (Bob)
Subject: Re: Will Pay: Write this script for me!
Message-Id: <33f2e5a8.168359649@netnews.voicenet.com>
ilesasw@aol.com (Ilesa SW) wrote:
>I need someone to write a perl script for me, that takes an email address
>in the query string, and then returns either the IP address of that email
>address, or "no" if the user isn't online. I think this can be
>accomplished with the finger protocol, but I don't know. If you can do
>this for me, I'd pay...I know its a short script, if you know what you're
>doing. Unfortunately, I don't know a bit of Perl. If you can help me, send
>email to ilesasw@ilesa.com.
>
>Thanks,
>Mal
I had a little bash script at one point that did a "who" or
"finger" (can't remember which) to all of the computers at my school,
and told someone where I was logged on, and how many times. However,
no matter what you do, you can't write a universal script to do
anything like this. The closest you would probably get is to use
finger, but you're dependent on the server to allow it and report back
the information in a manageable fashion.
--
- Bob
http://www.voicenet.com/~bbell
xxbbell@voicenet.com
remove x's to reply
------------------------------
Date: Wed, 13 Aug 1997 13:21:45 +0000
From: mbosley <mbosley@games-online.com>
Subject: WIN32Perl vs. Perl ( ~= and =~)
Message-Id: <33F1B4EF.66A59D88@games-online.com>
Hi all,
I have looked through the WIN32 FAQ and other information I have been able to
find but I can't find any mention about this.
On normal perl (5.003) I use the statement '$var ~= s/\W//g;' but in WIN32 it
fails. It then works if I use '$var =~ s/\W//g;' reversing the ~= with =~.
Whada?
Maybe I just missed the mentioning of it, but this has me relatively confused.
If this is correct (which I am assuming it is, since it works that way) how
would one go about using ~= in standard perl and =~ in WIN32 perl?
thx in advance
Michael Bosley
------------------------------
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 861
*************************************