[11469] in Perl-Users-Digest
Perl-Users Digest, Issue: 5069 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 5 20:07:27 1999
Date: Fri, 5 Mar 99 17:00:20 -0800
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, 5 Mar 1999 Volume: 8 Number: 5069
Today's topics:
$ENV{'AUTH_TYPE'} and $ENV{'REMOTE_USER'} (Todd P.)
Re: COnverting comma separate values <emschwar@mail.uccs.edu>
Re: COnverting comma separate values <gellyfish@btinternet.com>
Re: COnverting comma separate values (Alan Barclay)
Re: Cross Platform DBMs <tchrist@mox.perl.com>
Re: getting 4 digit years <gellyfish@btinternet.com>
Re: grep oddity - looking for explaination (Larry Rosler)
Re: hash from split in one step <aqumsieh@matrox.com>
Re: Help needed on pattern matching in reverse <aqumsieh@matrox.com>
HELP: howto get local_IP under Win9x ("Adrian Fiorinni")
Re: IO::Socket! Documentation <stampes@xilinx.com>
make and perl500502 <richardr@ldr.com>
Operation not permitted?? lbrown2@uswest.net
perl targeted url redirection. <tlehrer@spectrumdynamic.com>
Perl under Win (CGI!) <ceecsa@cee.hw.ac.uk>
Re: Printing to multiple Filehandles simultaneously <jglascoe@giss.nasa.gov>
redirection <nospam-seallama@mailcity.com>
Re: redirection (Larry Rosler)
Re: Regexp: split on ; but not on \; <aqumsieh@matrox.com>
Re: Seriously confused about subscripts <jglascoe@giss.nasa.gov>
Set @INC Path for Modules within Perl Script <honching@synopsys.com>
Re: Sorting an associative array <jglascoe@giss.nasa.gov>
Re: Sorting an associative array <gellyfish@btinternet.com>
Re: split on meta question <aqumsieh@matrox.com>
Re: Verifying URL's with perl. <jeromeo@atrieva.com>
Re: web browser in Perl? ("Adrian Fiorinni")
Re: without the awk! <aqumsieh@matrox.com>
Re: Yesterday! (Larry Rosler)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 05 Mar 1999 17:19:51 -0600
From: email@domain.com (Todd P.)
Subject: $ENV{'AUTH_TYPE'} and $ENV{'REMOTE_USER'}
Message-Id: <email-0503991729000001@the-cure.adtran.com>
I can not get my script to produce the print the information for the
$ENV{'AUTH_TYPE'} and $ENV{'REMOTE_USER'} variables.
The user does log in befor they run the script, but I do not get any
information. The server is Netscape Enterprise 3.5.1 and I used the admin
server to set up the permissions.
Is there a script that I can use with a form that would allow the person login.
I'm trying to get the redirect the user to a certain page based on the login..
Thanks,
Todd
------------------------------
Date: 05 Mar 1999 16:32:14 -0700
From: Eric The Read <emschwar@mail.uccs.edu>
Subject: Re: COnverting comma separate values
Message-Id: <xkfemn3fr7l.fsf@valdemar.col.hp.com>
dhosek@webley.com writes:
> Of course the question then becomes, if his perl is old enough to not have
> that notice does he even have perldoc to begin with? (And if you don't have
> perl documentation, how do you find out that perldoc -v will give you a
> pointer to documentation anyway ;-)
Well, actually I'm running 5.004_04, and yes, Virginia, there is a
perldoc. Would that upgrading were under my control, but it ain't.
-=Eric
------------------------------
Date: 5 Mar 1999 23:18:39 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: COnverting comma separate values
Message-Id: <7bpoof$25s$1@gellyfish.btinternet.com>
On 5 Mar 1999 16:00:29 GMT Jeff Lovell wrote:
> Jonathan Stowe rambled on in comp.lang.perl.misc:
>>This is pretty fundamental stuff.
>
> [smartass stuff snipped]
>
Thankyou - I'd rather be considered a smartass ...
> Oh, I see, clp.misc is for people who are beyond the basics.
For myself I would like to think that it is at the very least for people
who have taken some steps to help themselves before requesting the
assistance of others - call me a Perl spartacist but I'd leave them on a
freezing rock with nothing but a laptop some Linux disks and the source
code for Perl.
> This is
> the type of responses that irk me.
Hey that was one of those *questions* that irk me, alright !?
> You could politely pointed this
> person to the documentation they needed, but instead you take this
> "holier than thou" approach.
"Holier than thou" ? I think not - unholier perhaps, more arrogant, piss
taking, worthy of contempt - but "Holier than thou" I just cant take.
> If what you have to say is not helpful
> in the slightest, keep it to yourself.
>
If what you have to say is not helpful in the slightest, keep it to
yourself. I didnt see you propose a substantive answer to the original
contribution whereas you have made a substantial contribution to the
seeming surfeit of meta-discussion on this group - as have I of course now.
> Maybe we should propose comp.lang.perl.usless_answers in alt.config.
>
Well they've got alt.perl so I guess we're half the way there.
I do hope you feel better for that. I know I do.
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 5 Mar 1999 23:48:27 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: COnverting comma separate values
Message-Id: <920677704.574302@elaine.drink.com>
In article <7bpl8l$g1d$1@nnrp1.dejanews.com>, <dhosek@webley.com> wrote:
>In article <7bpbr9$fro$1@samsara0.mindspring.com>,
>Of course the question then becomes, if his perl is old enough to not have
>that notice does he even have perldoc to begin with? (And if you don't have
>perl documentation, how do you find out that perldoc -v will give you a
>pointer to documentation anyway ;-)
>
5.004_04 doesn't have that message, and that's the one you get if you
download the stable.tar.gz from CPAN, so I'd consider that a current
release, not old at all.
------------------------------
Date: 5 Mar 1999 16:29:31 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Cross Platform DBMs
Message-Id: <36e068db@csnews>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Simeon McAleer <mcaleer@jlab.org> writes:
:I am trying to use a internal PERL DBM database to record the output of
:some programs I am running. On Sun machines perl database files are
:created in pairs with the file extensions .dir and .pag. On Linux there
:is only one file created with a .db extension. The files created on one
:platform can not be accessed by PERL on the other platform. Does any one
:know how to get around this problem? Thanks in advance.
Put a
use DB_File;
in the top of the script. This will require some more work on the
Sun to get the thing installed, but at least now it should work.
--tom
--
"You can only measure the size of your head from the inside." --Larry Wall
------------------------------
Date: 6 Mar 1999 00:53:22 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: getting 4 digit years
Message-Id: <7bpua2$29s$1@gellyfish.btinternet.com>
On 5 Mar 1999 00:14:54 GMT Abigail wrote:
> Brad McBride (bmcbride@bmcbride.access.one.net) wrote on MMXI September
> MCMXCIII in <URL:news:36DEEF03.C05FF9DB@bmcbride.access.one.net>:
> ~~ I'm trying to get Perl to return 4 digit years instead of 2 in order to
> ~~ deal with Y2k issues, and am having no luck. I am trying to pull the
> ~~ time from the system and using the localtime() function, but both return
> ~~ the year as 2 digit. How do I get Perl to return the date with a 4 digit
> ~~ year.
>
>
> sub four_digit_year () {
> sleep 901 * 365.2425 * 24 * 3600;
> (localtime) [5];
> }
>
It all depends on how long the CPU fan and the disk drive motors hold out
really doesnt it ?
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Fri, 5 Mar 1999 15:04:08 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: grep oddity - looking for explaination
Message-Id: <MPG.114a02c2d713fed49896f7@nntp.hpl.hp.com>
In article <MPG.1148bb276d719eab9896e2@nntp.hpl.hp.com> on Thu, 4 Mar
1999 15:46:16 -0800, Larry Rosler <lr@hpl.hp.com> says...
...
> The reason why the regex with /$dir/ delimiters doesn't care about
> slashes in the interpolated string is that the syntax tree is determed
> at compile time, while the contents of $dir aren't known until run time.
>
> This is typical of all interpolations. For example,
>
> my $bar = '"';
> print "foo $bar baz\n";
>
> The double-quote in $bar is printed. It doesn't terminate the string.
> How could it?
Pardon my responding to my own post, but I got email from the person I
was responding to that raises an interesting point.
<QUOTE>
I see where I went wrong now, I am used to writing shell scripts, csh,
ksh, etc. where all the code is interpreted at run time, so the double-
quote in $bar _would_ terminate the string.
</QUOTE>
I recall clearly going through the same mental gyrations when converting
a csh *script* to my very first Perl *program*. The emphases in the
previous sentence are intended to point up what may be a REAL
distinction between 'scripting' languages and 'programming' languages.
In this view, a scripting language parses the program text (at 'run
time'), and the syntax depends on the content of interpolated variables,
which interpolation happens during the parse. OTOH, a programming
language parses the program text first (let's say, at 'compile time'),
and the syntax is not changed by the content of interpolated variables,
which interpolation happens later (at 'run time').
Is there any substance to this thought?
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 06 Mar 1999 00:02:35 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: hash from split in one step
Message-Id: <7bpram$lc4$1@nnrp1.dejanews.com>
In article <7bkdlo$u82$1@nnrp1.dejanews.com>,
vicuna@my-dejanews.com wrote:
> lo
>
> Would be high droogy if someone could grok me the glimmer.
Do you speak English?
> my %pretty;
>
> my $this ='would be key | want be value';
> ($lame_key, $lame_value) = split(/\|/,$this);
> $pretty{$lame_key} = $lame_value;
>
> but two step, want one.
%pretty = split /\|/, $this;
--Ala
$monger->{montreal}->[0];
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Sat, 06 Mar 1999 00:35:03 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: Help needed on pattern matching in reverse
Message-Id: <7bpt7n$n41$1@nnrp1.dejanews.com>
In article <7bln3l$1cn$1@nnrp1.dejanews.com>,
rnbernardo@yahoo.com wrote:
> I was wondering if it's possible in Perl to do a pattern match in reverse
> direction. For example, m/foo/ searches for the first occurrence of 'foo'.
> What I'd like is the search for the last occurrence.
I wonder why, but you might get away with the following:
my $string = 'a string with foo in it and another foo here';
my $r_string = reverse $string;
my $pattern = 'foo';
my $r_pattern = reverse $pattern;
$r_string =~ /$r_pattern/;
--Ala
$monger->{montreal}->[0];
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 05 Mar 1999 15:16:14 -0800
From: grumetedapanair@hotmail.com ("Adrian Fiorinni")
Subject: HELP: howto get local_IP under Win9x
Message-Id: <VAZD2.3161$xv.27532884@WReNphoon2>
Hello people,
i'm using this code below to make a TCP/IP connection
between my client and a server; but this was written
to run on a Unix ( fix IP ) system. Now i'm trying
to translate to Win9x ( dynamic IP ), and, guess what,
i have *no idea* how to work the line "3" ( $localhost
= `hostname`)...
***any help would be most appreciated***
thx.
sub connect_socket
{
my($machine, $port) = @_;#print "1\n";
my($sockaddr) = 'S n a4 x8';#print "2\n";
chop($localhost = `hostname`);#print "3\n"; ### get
the localhost
my($name0, $aliases0, $proto) =
getprotobyname('tcp');#print "4\n";
my($name1, $aliases1, $type1, $len1, $localaddr) =
gethostbyname($localhost);#print "5\n";
my($name2, $aliases2, $type2, $len2, $remaddr) =
gethostbyname($machine);#print "6\n";
my($local_pack) = pack($sockaddr, &AF_INET, 0,
$localaddr);#print "7\n";
my($remote_pack) = pack($sockaddr, &AF_INET, $port,
$remaddr);#print "8\n";
socket(S, &PF_INET, &SOCK_STREAM, $proto) || die
"Socket: $!";#print "9\n";
bind(S, $local_pack) || die "Bind: $!";#print "10\n";
connect(S, $remote_pack) || die "Connect: $!";#print
"11\n";
select(S); $| = 1; select(STDOUT);#print "12\n";
}
*** Posted from RemarQ - http://www.remarq.com - Discussions Start Here (tm) ***
------------------------------
Date: 5 Mar 1999 23:28:44 GMT
From: Jeff Stampes <stampes@xilinx.com>
Subject: Re: IO::Socket! Documentation
Message-Id: <7bppbc$7p1@courier.xilinx.com>
Tenchi <wolfie@wolfie.dhs.org> wrote:
: Hi!
: Someone knows where i can get some documentation on this module? I'm
: trying to learn it but i just see some few scripts....
Sure, once it's installed, just type perldoc IO::Socket
--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com
------------------------------
Date: Fri, 05 Mar 1999 14:59:37 -0800
From: Richard Robinson <richardr@ldr.com>
Subject: make and perl500502
Message-Id: <36E061D4.AEF65504@ldr.com>
I'm having problems making perl on IRIX 6.5.
I configured as follows: sh Configure -Dcc=gcc.
Then I accepted all the defaults except that when Configure asked me to
use nm -- I answered y for yes (instead of n for no, which was default).
This gave me a config.sh that had "undef" for libc.
And when I went to make, I got the following:
.
.
.
Use of unitilialized value at configpm line 339, <GLOS> chunk 541
Use of unitilialized value at configpm line 339, <GLOS> chunk 542
Use of unitilialized value at configpm line 403.
configpm: tmp not valid at configpm line 403.
*** Error code 2 (bu21)
Comments in the Makefile say that if I'm having problems with configpm
script, I can comment out the simple tests at the end of latter. Which I
did. (make minitest failed, so I resorted to previously mentioned).
When I ran make this time, it just hung on the "Extracting pod2html
(with variable substitutions)" line.
Any one have this kind of problem. Any one have a suggestion?
--
Richard Robinson
Web Administrator
Litho Development & Research
richardr@ldr.com
503-255-5800 x172
------------------------------
Date: Fri, 05 Mar 1999 23:47:17 GMT
From: lbrown2@uswest.net
Subject: Operation not permitted??
Message-Id: <7bpqe2$ko4$1@nnrp1.dejanews.com>
Hi,
I'm trying to run a Perl script on my BSD UNIX box which runs fine on an
external Linux box.
I am setting up a TCP socket connection to another server. When I call Bind
for the socket, I get an error: Operation not permitted
I am root and the script has been chmod to 4777, and still Operation not
permitted. TCP/IP seems to be working fine with all other apps, but not with
the script.
Any ideas/suggestions??
THANKS!!
-TM
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 5 Mar 1999 17:57:34 -0700
From: "Thomas Lehrer" <tlehrer@spectrumdynamic.com>
Subject: perl targeted url redirection.
Message-Id: <7bpu24$1ao$1@nnrp03.primenet.com>
I'm trying to write a redirector that will update a frame, other than the
frame that originally called the script. The redirection works but the
targeted frame is not being updated. The frame that calls the script is the
only one that is updated. Can anyone help.. Below is my script. This is
written for Active State's Active perl for win32 build 509. Any help would
be greatly appreciated.
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<([^>]|\n)*>//g;
$value =~ s/<//g;
$value =~ s/>//g;
$FORM{$name} = $value;
}
# Match abrev to full state
$dir = 'http://intranet/samptee/website/states';
for ($FORM{State})
{
$page = /AZ/ && 'arizona.htm'
|| /WA/ && 'washington.htm'
|| /OR/ && 'oregon.htm'
|| /CA/ && 'california.htm'
|| /ID/ && 'idaho.htm'
|| /NV/ && 'nevada.htm'
|| /UT/ && 'utah.htm'
|| /MT/ && 'montana.htm'
|| /WY/ && 'wyoming.htm'
|| /CO/ && 'colorado.htm'
|| /NM/ && 'nmexico.htm'
|| /ND/ && 'ndakota.htm'
|| /SD/ && 'sdakota.htm'
|| /NE/ && 'nebraska.htm'
|| /KS/ && 'kansas.htm'
|| /OK/ && 'oklahoma.htm'
|| /TX/ && 'texas.htm'
|| /MN/ && 'minnesota.htm'
|| /IA/ && 'iowa.htm'
|| /MO/ && 'missouri.htm'
|| /AR/ && 'arkansas.htm'
|| /LA/ && 'lou.htm'
|| /WI/ && 'wisconsin.htm'
|| /IL/ && 'illinois.htm'
|| /MI/ && 'michigan.htm'
|| /IN/ && 'indiana.htm'
|| /KY/ && 'kentucky.htm'
|| /TN/ && 'tenn.htm'
|| /MS/ && 'miss.htm'
|| /AL/ && 'alabama.htm'
|| /FL/ && 'florida.htm'
|| /OH/ && 'ohio.htm'
|| /GA/ && 'georgia.htm'
|| /SC/ && 'scarolina.htm'
|| /NC/ && 'ncarolina.htm'
|| /VA/ && 'virginia.htm'
|| /WV/ && 'wvirginia.htm'
|| /PA/ && 'penn.htm'
|| /DE/ && 'delaware.htm'
|| /NJ/ && 'newjersey.htm'
|| /CT/ && 'conn.htm'
|| /RI/ && 'rhode.htm'
|| /MA/ && 'mass.htm'
|| /ME/ && 'maine.htm'
|| /NH/ && 'nhampshire.htm'
|| /VT/ && 'vermont.htm'
|| /NY/ && 'ny.htm'
|| /AK/ && 'alaska.htm'
|| /HI/ && 'hawaii.htm'
|| /MD/ && 'maryland.htm'
}
print "HTTP/1.0 302 Found\n";
print "Window-target: top\n";
print "Location: $dir/$page\n\n";
exit;
------------------------------
Date: Sat, 6 Mar 1999 00:37:42 -0000
From: "equality7-2125" <ceecsa@cee.hw.ac.uk>
Subject: Perl under Win (CGI!)
Message-Id: <7bpteo$i50$1@glencoe.hw.ac.uk>
I am using a Web Server in Windows, and everything is fine (apart from the
constant GPFs...) but I can't seem to get it right. This is back to the
basics here so I am trying to eradicate the stupid error that I am most
likely making.
If I have a Perl program, that returns a value, how do I call it in an HTML
page.
Say I have my program: thing.pl
and put this in my CGI-BIN folder.
I would need a call in my HTML like:
<IMG SRC="http:/..... etc. /cgi-bin/thing.pl>
N'est pas?
Does it have something to do with the fact that I am in Win 98 and have no
control over chmod? I have Linux, though haven't used it for my Web server
yet... I will be though after I hand in two big projects (using Word and
Visual Basic you see) so will it be easier then?
Thanks for reading and helping if you can, any info appreciated!
C.,
ceecsa@cee.hw.ac.uk
------------------------------
Date: Fri, 05 Mar 1999 18:31:18 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: "Andrew M. Langmead" <aml@world.std.com>
Subject: Re: Printing to multiple Filehandles simultaneously
Message-Id: <36E06946.A04BF488@giss.nasa.gov>
[courtesy copy of post sent to cited author, Andrew, via email]
"Andrew M. Langmead" wrote:
>
> You could hide the loop in a module that implements perl's tied
> filehandle interface:
>
> tie *ALL, MultiHandle, *STDOUT, *STDOUT or die;
>
> print *ALL "Stuff to print";
>
> with an implementation of MultiHandle that would look like this:
<snip *cool* stuff>
That's pretty damn cool, Andrew. :)
--
"Who are you who are so wise in the ways of science?"
--Sir Bedevere
------------------------------
Date: Fri, 05 Mar 1999 14:50:44 -0800
From: dan <nospam-seallama@mailcity.com>
Subject: redirection
Message-Id: <36E05FC3.EB0D62D8@mailcity.com>
how do i redirect a script to another page? when i try
print "Location: $webpage\n\n";
it prints the value of the variable to the page, am i missing something?
thanks
------------------------------
Date: Fri, 5 Mar 1999 15:41:32 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: redirection
Message-Id: <MPG.114a0b84f781c50e9896f9@nntp.hpl.hp.com>
In article <36E05FC3.EB0D62D8@mailcity.com> on Fri, 05 Mar 1999 14:50:44
-0800, dan <nospam-seallama@mailcity.com> says...
> how do i redirect a script to another page? when i try
> print "Location: $webpage\n\n";
>
> it prints the value of the variable to the page, am i missing something?
Not a Perl question. You probably have a 'Content-Type:' header ahead
of that 'Location:' header. Don't.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 06 Mar 1999 00:23:55 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: Regexp: split on ; but not on \;
Message-Id: <7bpsii$mbo$1@nnrp1.dejanews.com>
In article <36de60ad.86493891@news.uni-X.net>,
collin@rogowski.de (Collin Rogowski) wrote:
> How can I split a String at ; but not at \;
% perl -w
$_ = 'this is a line ; with a line \; and another line ; finished';
@a = split /[^\\];/;
for (@a) {
print ">> $_.\n";
}
__END__
>> this is a line.
>> with a line \; and another line.
>> finished.
Does this help?
--Ala
$monger->{montreal}->[0];
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 05 Mar 1999 17:47:39 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Seriously confused about subscripts
Message-Id: <36E05F0B.E2CE6930@giss.nasa.gov>
[courtesy copy of post sent to cited Larry]
Larry Rosler wrote:
<snip>
> You need a space after those two dashes!
hi Larry,
edification via constructive criticism
is always appreciated, thank you.
--a space
"Narf!"
--Pinky
------------------------------
Date: Fri, 05 Mar 1999 17:25:22 -0600
From: Hon-Chi Ng <honching@synopsys.com>
Subject: Set @INC Path for Modules within Perl Script
Message-Id: <36E067E2.21AA91E@synopsys.com>
Hi
I wrote a few Perl programs that share some common subroutines, which I
keep them in some Perl Module (.pm) files. I want to distribute my Perl
programs (+ the related Perl modules) to some other users. Is there a
way for my Perl programs to "use" my Perl modules without having the
users to set the path explicitly?
E.g.
In /home/joeuser/perl/bin/
MyLib1.pm
MyLib2.pm
...
In /home/joeuser/perl/bin/MyProg1.pl
#! /usr/local/bin/perl
...
use lib "/home/joeuser/perl/bin";
use MyLib1;
use MyLib2;
...
I don't want to hardcode the path in MyProg1.pl because the users
receive my programs are on different OS and file system. Since
MyProg1.pl and MyLib1.pm are always in the same directory (thru tar), so
I tried the following, but it didn't work.
In MyProg1.pl
#! /usr/local/bin/perl
..
my ($prog_dir) = $0 =~ m|^(.*/)?[^/]+$|;
use lib "$prog_dir";
use MyLib1;
use MyLib2;
...
It returned the error "Can't locate MyLib1.pm in @INC", which I believe
has something to do with Perl compile-time and run-time issues, although
I don't fully understand. :^)
I know I can have the following alternatives:
1. In MyProg1.pl,
#! /usr/local/bin/perl -I/home/joeuser/perl/bin
...
2. In csh,
setenv PERL5LIB $PERL5LIB:/home/joeuser/perl/bin
But, again, both require users to know and set the correct path since
they've different OS and file system than mine.
I can't use
use lib ".";
because the users may run the program from anywhere, assuming the $PATH
is correctly set.
I appreciate if someone can show me the way to "set lib" dynamically
(with $prog_dir, or something similar). Or if there is a better way to
share subroutines among Perl programs other than using Perl modules,
without hardcoding any explicit path.
Thanks.
Hon-Chi
------------------------------
Date: Fri, 05 Mar 1999 18:06:25 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Sorting an associative array
Message-Id: <36E06371.5A20F2DB@giss.nasa.gov>
[Posted and a courtesy copy mailed.]
In article <MPG.1149f844519e1e69896ee@nntp.hpl.hp.com> Larry Rosler wrote:
>
<snip>
> Neither witty nor wise, in this case!
<snip>
> Golly gee, what overkill! This is pathetically slow. I just posted a
hi Larry,
once again, many thanks for your thoughtful and
always courteous corrections.
Jay Glascoe
--
"That which does not kill me makes me stranger."
--Larry Wall
------------------------------
Date: 6 Mar 1999 00:41:08 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Sorting an associative array
Message-Id: <7bptj4$29p$1@gellyfish.btinternet.com>
On Fri, 5 Mar 1999 14:19:26 -0800 Larry Rosler wrote:
> [Posted and a courtesy copy mailed.]
>
> In article <36E01E7A.FEC0E002@giss.nasa.gov> on Fri, 05 Mar 1999
> 13:12:10 -0500, Jay Glascoe <jglascoe@giss.nasa.gov> says...
>> Henning Koch wrote:
>> > I have a problem sorting an associative array.
>> > The values of this array are numbers.
>> > If I want to sort this numbers with:
>> > foreach $number (sort values(%array))
>> > how can I access the numbers and the related index ?
>>
>> let's say "%hash" is your associative array.
>> Now, behold the wit and wisdom of the "Schwartzian
>> Transform":
>
> Neither witty nor wise, in this case!
>
>> my @sorted_keys = map { $_->[0] }
>> sort { $a->[1] <=> $b->[1] }
>> map { [$_, $hash{$_}] }
>> keys %hash;
>
> Golly gee, what overkill! This is pathetically slow. I just posted a
> rather lengthy analysis of a benchmark that shows why this is so. So I
> won't do it again.
>
I have no doubt about the performance thing but I do tend to find this
sort of thing useful myself when I want dont care about the hashness of the
data anymore and can lose the last map to get a sorted array of references
to key-value pairs but dont know if thats any more efficient than doing the
lookups again - I just find it cleaner in some circumstances.
> my @sorted_keys = sort { $hash{$a} <=> $hash{$b} } keys %hash;
>
> Naive, and best, and in perlfaq5: "How do I sort a hash (optionally by
> value instead of key)?"
>
On a purely subjective basis however (IE I have no quantitative evidence
nor can be bothered to work out how to provide any :) It *appears* to use
more memory and CPU time despite being faster - but perhaps thats just a
consequence of taking 'top' too literally ;-}
/J\
--
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Sat, 06 Mar 1999 00:26:28 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: split on meta question
Message-Id: <7bpsna$mm6$1@nnrp1.dejanews.com>
In article <36DE68DE.53525FC5@mihy.mot.com>,
rpsarathi@usa.net wrote:
> ($a, $b, $c) = split(/[\.\|]/, "any-string");
The dot and the pipe are not special in a character class, and don't have to
be escaped (it doesn't harm though):
($a, $b, $c) = split /[.|]/, $string;
--Ala
$monger->{montreal}->[0];
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 05 Mar 1999 15:17:56 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: sidney_roberts@my-dejanews.com
Subject: Re: Verifying URL's with perl.
Message-Id: <36E06624.58B2B1A2@atrieva.com>
sidney_roberts@my-dejanews.com wrote:
>
> I have a list of url's and I need to check three things. First, did I get
> a response back from the server. Second, was the file found or not? Third
> (and this is important), was the response that I got back binary or text
> data?
>
> Right now, I'm doing it this way:
>
> #--
> for ($pic_count = 0; $pic_count < 100; $pic_count++)
> {
> $pic_url = $pic_array[$pic_count];
> $agent = LWP::UserAgent->new();
>
> print "TESTING: $pic_url";
> $request = HTTP::Request->new('HEAD', $pic_url);
> $response = $agent->request($request);
>
> $result = $response->code;
>
> if ($result != '200')
> {
> print " not found ($result).\n";
> } else {
> print " ", $result, "\n";
> }
> }
> #---
>
> There's a few problems with this, though. First, it's really slow. I think
> it's because it's downloading the whole file (I'm requesting binary files)
> before it gives a response or not.
You aren't downloading the whole file, as you're doing a HEAD request.
What you are doing is creating a brand new UA and Request for every
iteration, which can't be speedy.
Create one UA, and one request, then iterate over your data.
$agent = LWP::UserAgent->new();
$request = HTTP::Request->new('HEAD',$uri);
foreach(@pic_array){
print qq{Testing $_\n};
$request->url($_);
$response = $agent->request($request);
$result = $response->code();
#
# etc...
#
}
For all the exciting details on LWP, User Agents, and HTTP, see the
documentation for HTTP:: classes, and LWP. You might also want to check
up on the perlobj man page.
> What I'd like to do is just download the first 64 bytes or so and check that data.
You do understand exactly what a HEAD request is, right? And a MIME
type?
>Secondly, can I assume that 200 is the "everything was cool" response?
For all the exciting detail on HTTP, the request response process,
server return codes and other things that make the web go, read RFC2068.
> Also, how would I go about setting the timeout time before it returns an error?
Read the documentation for LWP::UserAgent.
> Thanks in advance for any help you can give.
You're welcome!
Good Luck!
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Fri, 05 Mar 1999 15:04:06 -0800
From: grumetedapanair@hotmail.com ("Adrian Fiorinni")
Subject: Re: web browser in Perl?
Message-Id: <wpZD2.3155$xv.27438245@WReNphoon2>
personally i found much more interesting writing
automatic page-downloaders ( for offline browsing ),
or automatic form posters, or any tedious task.
Perl is great for that, but for a browser... i guess
u'll take a trip to hell; just parsing DHTML and Java
is no funny at all ( even JavaScripts/VBscripts aren't
nice to deal with ) imagine interpret and execute
those.
*** Posted from RemarQ - http://www.remarq.com - Discussions Start Here (tm) ***
------------------------------
Date: Sat, 06 Mar 1999 00:16:05 GMT
From: @l@ <aqumsieh@matrox.com>
Subject: Re: without the awk!
Message-Id: <7bps3t$m6m$1@nnrp1.dejanews.com>
In article <WTqD2.193$bH4.862@news12.ispnews.com>,
"Robert Acklin" <robace@REMOVEvol.com> wrote:
> How would I do the following:
> but without the awk!
>
> foreach $dirname ( `smbclient $smbcmd | grep "Disk" | awk '{print $3}' ` )
>
> $dirname =~ tr /A-Z/a-z/;
> &do_thing;
> }
1) I hope you know what you're doing.
2)
for my $temp (`smbclient $smbcmd | grep "Disk"`) {
$dirname = (split)[2];
&do_thing;
}
Or even, without the outside grep:
for my $temp (grep { /Disk/ } split /\n/, `smbclient $smbcmd`) {
# same thing here
}
--Ala
$monger->{montreal}->[0];
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 5 Mar 1999 15:08:29 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Yesterday!
Message-Id: <MPG.114a03cd824285669896f8@nntp.hpl.hp.com>
In article <7bp3pn$8q4$1@pegasus.csx.cam.ac.uk> on 5 Mar 1999 17:20:55
GMT, M.J.T. Guy <mjtg@cus.cam.ac.uk> says...
> Larry Rosler <lr@hpl.hp.com> wrote:
> > use Time::Local;
> >
> > $_ = '03011999'; # mmddyyyy
> > /(\d\d)(\d\d)(\d{4})/;
> > my $time = timelocal(0, 0, 12, $2, $1 - 1, $3 - 1900);
> > my ($d, $m, $y) = (localtime($time - 24*60*60))[3 .. 5];
> >
> >Note that I choose local noon to shut off the usual carping about
> >anomalies around Summer-Time transitions.
>
> While that does indeed indeed avoid the problem (for any sanely defined
> daylight saving scheme), why mess with localtime at all? If you
> use timegm() and gmtime() instead, all such problems disappear.
> And it ought to be more efficient.
I agree. I deliberately chose to stick with localtime because everyone
else does, and it is more fun, because it generates more controversy.
:-) But I should have mentioned gmtime() also.
Of course, that still leaves the 'leap seconds' idiocy to deal with...
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5069
**************************************