[16656] in Perl-Users-Digest
Perl-Users Digest, Issue: 4068 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 19 21:06:12 2000
Date: Sat, 19 Aug 2000 18:05:14 -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: <966733513-v9-i4068@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 19 Aug 2000 Volume: 9 Number: 4068
Today's topics:
Authorizing Users <aran@mapcruzin.com>
Re: Authorizing Users nobull@mail.com
Re: Authorizing Users (Martien Verbruggen)
Beginer help with "hello" syntax. <anthony_coley@hotmail.com>
Re: Can't get a simple GETHOSTBYADDR() to work <sborruso@stny.rr.com>
Re: Can't get a simple GETHOSTBYADDR() to work (Martien Verbruggen)
Re: Checking if variables exist (Keith Calvert Ivey)
Re: cross platform newline processing <elijah@workspot.net>
Re: Embedding Perl (Martien Verbruggen)
Re: Following Hyperlinks with cgi <amonotod@netscape.net>
Re: Following Hyperlinks with cgi <amonotod@netscape.net>
Re: GD.pm problems, can't install and I need it (Martien Verbruggen)
Great software deals <thewarehouse@europe.com>
Re: Great software deals <lr@hpl.hp.com>
Re: help with RegExp <godzilla@stomp.stomp.tokyo>
Re: help with RegExp michaeljgardner@my-deja.com
Re: How do I get statistics from Win NT processes? (ie (Astrid Behrens)
Re: How do I get statistics from Win NT processes? (ie <amonotod@netscape.net>
Need help of a Perl expert!!! <hvenetie@casema.net>
Re: Need help of a Perl expert!!! nobull@mail.com
Re: newbie: s/// on windows subdirs? (Ilya Zakharevich)
Re: obfusicate routine to count max string len in hash <lr@hpl.hp.com>
Re: Problem with hash initialization using list <lr@hpl.hp.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 19 Aug 2000 19:30:19 GMT
From: "Aran Meuser" <aran@mapcruzin.com>
Subject: Authorizing Users
Message-Id: <ffBn5.47843$rd1.9341948@typhoon-news1.southeast.rr.com>
(CGI)
Hey, I'm trying to authorize users. I have various reasons for not using
forms to do it. What I have now is:
print "Status: 401 Unauthorized\n";
print "WWW-Authenticate: Basic realm=\"Blah Blah\"\n\n";
This works in Netscape and IE, so thats good. But, I cannot figure out what
to do after this point. I printed every environment variable to a text file
and I still can't seem to find the part that says the login and password
that the user entered.
Any help, links, or suggestions would be greatly appreciated.
Thank you, Aran
------------------------------
Date: 20 Aug 2000 01:25:56 +0100
From: nobull@mail.com
Subject: Re: Authorizing Users
Message-Id: <u9hf8g22y3.fsf@wcl-l.bham.ac.uk>
"Aran Meuser" <aran@mapcruzin.com> writes:
> I printed every environment variable to a text file
> and I still can't seem to find the part that says the login and password
> that the user entered.
Most web server packages handle authentication inside the web server
software and do not pass the raw information through to CGI scripts.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 20 Aug 2000 01:00:40 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Authorizing Users
Message-Id: <slrn8pu9k4.qmo.mgjv@martien.heliotrope.home>
On Sat, 19 Aug 2000 19:30:19 GMT,
Aran Meuser <aran@mapcruzin.com> wrote:
> (CGI)
Indeed. So why ask here? The comp.infosystems.www.* groups are much more
appropriate.
> Hey, I'm trying to authorize users. I have various reasons for not using
> forms to do it. What I have now is:
Then don't use forms. Use the standard mechanisms implemented by your
HTTP server. Authentication should never be coded at the CGI level,
unless it's authentication above and beyond what the server is already
doing.
> print "Status: 401 Unauthorized\n";
> print "WWW-Authenticate: Basic realm=\"Blah Blah\"\n\n";
Oh, good. Perl code to comment on:
If you use the qq() operator, you don't have to use as many backwhacks.
> This works in Netscape and IE, so thats good. But, I cannot figure
> out what to do after this point. I printed every environment variable
> to a text file and I still can't seem to find the part that says the
> login and password that the user entered.
Whether you write this in C, Cobol, Fortran, Java, Perl PostScript, or
BananaScript, the solution to the problem would be the same. Just the
code would be different. So... Go to one of the comp.infosystems.www.*
groups, and ask around there how people normally do authentication with
webby applications. If you're still convinced after that that you need
to do it in your CGI thingy, implement the solution you found there. If
you at that point have trouble with Perl, NOT with the algorithms,
techniques or general programming issues, then you can come back and
ask.
Thank you for keeping this group uncluttered
Martien
--
Martien Verbruggen |
Interactive Media Division | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd. | Universe and Reboot +++
NSW, Australia |
------------------------------
Date: Sun, 20 Aug 2000 00:58:46 GMT
From: "Anthony E. Coley" <anthony_coley@hotmail.com>
Subject: Beginer help with "hello" syntax.
Message-Id: <a3Gn5.99103$3E6.892026@news1.alsv1.occa.home.com>
Could someone tell me what's wrong with my script? It works if I enter
anthony, but if I try an arbitrary name I get stuck in the
"Wrong, try again. What is the secret word? " loop. I'm going by
O'Reilly's "learning Perl" book 1993 and I'm using perl-5.00503-10
for Liunx and per-5.6.0.616 WinNT and both systems behave the
same. If I set the @words aray to only "camel" it work correctly, but
with multiply values it fails.
Thanks,
Anthony
#!/usr/bin/perl
@words = ("camel","llama","oyster");
print "What is your name? ";
$name = <STDIN>;
chop($name);
if ($name eq "anthony") {
print "Hello, $name! How good of you to be here!\n";
} else {
print "Hello, $name!\n";
print "What's the secret word? ";
$guess = <STDIN>;
chop($guess);
$i = 0;
$correct = "maybe";
while ($correct eq "maybe") {
if ($words[$i] eq $quess) {
print "I've made it this far\n";
## print "$words[$i] and $guess\n";
print "You got it\n";
$correct = "yes";
} elsif ($i < 2) {
$i = $i + 1;
} else {
print "Wrong, try again. What is the secret word? ";
$guess = <STDIN>;
chop($guess);
$i = 0;
}
} # end of while not correct
} # end of anthony
------------------------------
Date: Sat, 19 Aug 2000 22:30:50 GMT
From: Steve Borruso <sborruso@stny.rr.com>
Subject: Re: Can't get a simple GETHOSTBYADDR() to work
Message-Id: <399F07B6.64AEFF5A@stny.rr.com>
Thank you for the clarification. My problem appears to go a little deeper than
gethostbyaddr.
Any assistance or pointers to other news groups for an answer would be greatly
appreciated .......
I am parsing image urls from html pages and later making decisions upon the
hostname in the url.
Recently I found an image url, on an html page I was parsing, as follows -
http://216.32.245.142/imageserver/00007c7f/llebreton/1coral.jpg
I thought I could just parse out the ipaddr from the url, issue a gethostbyaddr,
and I would have the host name for later processing.
The gethostbyaddr fails to return anything with 216.32.245.142 as the input IP
addr.
(I can ping 216.32.245.142 just fine)
When I manually type in the url above into a browser, it displays the jpg and
resolves the address to be at -
http://imagehost.auctionwatch.com/bin/imageserver.x/00007c7f/llebreton/1coral.jpg
Is some type of redirection going on ? (not as familiar with webservers as I
would like to be yet)
I need to be able to resolve the location in the same way the browser has
somehow, whether the ipaddress is "redirected" or not.
Any ideas ?
Thank you,
Steve Borruso
David Efflandt wrote:
> On Sat, 19 Aug 2000 15:26:00 GMT, Steve Borruso <sborruso@stny.rr.com> wrote:
> >
> >I've tried folllowing countless examples, found on the net, to issue a
> >gethostbyaddr() but nothing is ever
> >returned when I issue the function. I've recoded this several ways and
> >just can't get anythiing to return.
> >
> >I'm running on SunOS 5.7
>
> You appear to be making this more complicated than necessary. I have no
> idea about the format of your data, but first make sure that you can
> reliably parse out the hostnames or IPs you want to lookup.
>
> The following is a commandline script that works in both Linux and Solaris
> for IP, hostname, or even those all number names that porno sites use:
>
> use Socket;
> if ($ARGV[0]) {
> $host = shift;
> } else {
> print "Enter host to resolve on command line\n";
> exit;
> }
> print "Host: $host\n";
> $ip = scalar gethostbyname($host);
> @ip = unpack("C4",$ip);
> $ip = join(".",@ip);
> print "IP: $ip\n";
> $rhost = gethostbyaddr(inet_aton($ip), AF_INET);
> print "Reverse lookup: $rhost\n\n";
>
> # I added following to show output data you are looking for:
>
> ($name,$alias,$adrtype,$length,@address) =
> gethostbyaddr(inet_aton($ip),AF_INET);
>
> print "Resolved hostname is $name\nalias is $alias\naddress is ";
> foreach (@address) {
> @ip = unpack("C4",$_);
> print join(".",@ip)," ";
> }
> print "\nlength is $length\ntype is $adrtype\n";
>
> --
> 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: 20 Aug 2000 01:00:45 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Can't get a simple GETHOSTBYADDR() to work
Message-Id: <slrn8puapg.qmo.mgjv@martien.heliotrope.home>
On Sat, 19 Aug 2000 22:30:50 GMT,
Steve Borruso <sborruso@stny.rr.com> wrote:
> The gethostbyaddr fails to return anything with 216.32.245.142 as the
> input IP addr.
There is probably something wrong with your local name services. Check
with your system admin.
> (I can ping 216.32.245.142 just fine)
watch:
# perl -wl
use Socket;
my $addr = inet_aton('216.32.245.142') || die;
print scalar gethostbyaddr($addr, AF_INET);
__END__
imagehost.auctionwatch.com
#
> When I manually type in the url above into a browser, it displays the
> jpg and resolves the address to be at -
>
[wrapped ugly URL]
> http://imagehost.auctionwatch.com/bin/imageserver.x/\
> 00007c7f/llebreton/1coral.jpg
What your browser displays, and what your nameservers resolve are
different things, and don't necessarily relate to each other.
> Is some type of redirection going on ? (not as familiar with
> webservers as I would like to be yet)
Possibly, but that would be unrelated in this case.
> I need to be able to resolve the location in the same way the browser has
> somehow, whether the ipaddress is "redirected" or not.
You don't. If you want to follow redirections, let LWP do it. If you
already have the IP address, you should even really need to find the
name, unless you want to do something based on that name. Do you really
know what your problem is? Why do you need to have that name?
[Jeopardectory performed. Please, for future reference, put your
comments AFTER the suitably trimmed quoted text you include. Respect the
arrow of time]
Martien
--
Martien Verbruggen |
Interactive Media Division | Freudian slip: when you say one thing
Commercial Dynamics Pty. Ltd. | but mean your mother.
NSW, Australia |
------------------------------
Date: Sat, 19 Aug 2000 21:58:56 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Checking if variables exist
Message-Id: <39abfff9.30083084@news.newsguy.com>
Joe Kline <jkline@one.net> wrote:
>I would suggest doing:
>
>if ( ( exists $FORM{'realname'} && $FORM{'realname'} ) &&
> ( exists $FORM{'callsign'} && $FORM{'callsign'} ) &&
> ( exists $FORM{'computer'} && $FORM{'computer'} ) &&
> ( exists $FORM{'email'} && $FORM{'email'} ) &&
> ( exists $FORM{'location'} && $FORM{'location'} )
> )
>{ $required = "yes"; }
>
>The "exists" check avoids autovivification. I do believe in I might be
>a bit paranoid with my checking.
Yes, you are. Just using a hash element in a boolean context
won't autovivify it, so the exists() checks above are
unnecessary. You may be thinking of hashes of the
autovivification that occurs when you use a nonexistent hash
element as a hash reference -- something like:
if (exists $hash{abc}{def}) {
That would cause $hash{abc} (but not $hash{abc}{def}) to spring
into existence. To avoid that, check first like this:
if (exists $hash{abc} && exists $hash{abc}{def}) {
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: 19 Aug 2000 16:55:48 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: cross platform newline processing
Message-Id: <eli$0008191247@qz.little-neck.ny.us>
In comp.lang.perl.misc, Eric Bohlman <ebohlman@netcom.com> wrote:
> Alan J. Flavell (flavell@mail.cern.ch) wrote:
> : But when required to handle cross-platform text of this kind, I would
> : open the stream in binmode, and would write the code in terms of the
> : binary representations \015 and \012. Since $/ can't be set to
> : several alternatives at the same time, I wouldn't use it, but would
> : use some other coding for breaking up the binary chunks into
> : lines/records (call them what you will).
>
> Translating a \015 optionally followed by a \012 into a single \n would
> work *if* the file contained no "irregular" line endings. The tricky part
> would be deciding what to do if the file contained, say, an LFCR pair, or
> a CR followed by multiple consecutive LFs, or contained both LFs and CRs
> that weren't adjacent. How, for example, should a run of text followed by
> a CR followed by a run of the same text followed by a CRLF be treated
> (presumably an attempt to create bold text on a line printer)? What if
> the two runs of text weren't identical?
One of my favorite vi macros is:
" Split line on previous space; use with J for reformatting
map S F r<ctrl-M>
And I've written many others that have \cMs in them, not always at
the end.
I've seen bizarre things come out of automatic 'text file conversion'
run on my .exrc (ex/vi config file). Getting the file from a Unix
system and then trying to use it in Mac Vim caused all sorts of
frustrations.
Elijah
------
ended up reentering a bunch of macros
------------------------------
Date: 20 Aug 2000 01:00:19 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Embedding Perl
Message-Id: <slrn8pu8q6.qmo.mgjv@martien.heliotrope.home>
On Sat, 19 Aug 2000 08:59:41 -0700,
Larry Rosler <lr@hpl.hp.com> wrote:
> In article <8nm357$lme$1@provolone.cs.utexas.edu>, logan@cs.utexas.edu
> says...
>
> ...
>
> > By the way, if you do this, you're going to end up mixing perl's I/O
> > buffering with C++'s, at least unless you use syswrite() and sysread()
> > under perl.
>
> I wonder if there is a problem. As the perl code and the C++ code are
> bound into one executable, wouldn't they each end up calling the same
> functions in te C I/O library, and using the same buffers?
There's always the possibility that calls to the stream functions get
mixed with direct system calls or other I/O calls. The C++ programmer
doesn't know what Perl does internally (apart from looking at Perl's
code, and that is something that shouldn't be necessary), and perl
doesn't know what happens in the C++ program. Since this isn't really
documented, you probably use it at your own peril, and probably make it
very unportable.
I would avoid passing open file numbers around, and just pass the file
name, and if you realy need to communicate this sort of information: the
file offset and anything else you need. Design a struct or class that
has all this stuff, and make that your communication unit.
Relying on both Perl internally, and your C++ and C libraries both to not
interfere with each other's file I/O is dangerous, unless you _know_
what sort of I/O is being done in both.
There might not be a problem, and there probably isn't, but I would not
want to take the risk. And what if the problem doesn't exist on
platforms A and B, where you wrote and tested this? And you need to port
it to C, where it suddenly starts failing, mysteriously. You now have
quite a lot of code to rewrite.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | Curiouser and curiouser, said Alice.
NSW, Australia |
------------------------------
Date: Sat, 19 Aug 2000 20:05:03 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Following Hyperlinks with cgi
Message-Id: <8nmp95$fla$1@nnrp1.deja.com>
In article <Mqxn5.16858$4T.1006183@bgtnsc07-news.ops.worldnet.att.net>,
"Jeremiah Adams" <adams1015@worldnet.att.net> wrote:
> From out of the abundance of the heart the mouth speaks.
Godzilla!'s heart must be full of confusion and stupidity.
>
> Would you actually speak face to face to one another in
> the manner you illustrated with your posts? I think not.
>
> jeremiah
I dunno if what you say is true. I do truly think that we would be
better off if the trolls (Specifically Godzilla!) were, at the very
least, comatose.
amonotod
--
`\|||/ amonotod@
(@@) netscape.net
ooO_(_)_Ooo________________________________
_____|_____|_____|_____|_____|_____|_____|_____|
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 19 Aug 2000 20:03:33 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Following Hyperlinks with cgi
Message-Id: <8nmp6b$fkt$1@nnrp1.deja.com>
In article <Mqxn5.16858$4T.1006183@bgtnsc07-news.ops.worldnet.att.net>,
"Jeremiah Adams" <adams1015@worldnet.att.net> wrote:
> From out of the abundance of the heart the mouth speaks.
>
> Would you actually speak face to face to one another in
> the manner you illustrated with your posts? I think not.
>
> jeremiah
I dunno if what you say is true. I do truly think that we would be
better off if the trolls (Specifically Godzilla!) were, at the very
least, comatose.
amonotod
--
`\|||/ amonotod@
(@@) netscape.net
ooO_(_)_Ooo________________________________
_____|_____|_____|_____|_____|_____|_____|_____|
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 20 Aug 2000 01:00:48 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: GD.pm problems, can't install and I need it
Message-Id: <slrn8pub5f.qmo.mgjv@martien.heliotrope.home>
On Sat, 19 Aug 2000 17:37:37 GMT,
Zacarias <zacarias@teleline.es> wrote:
>
> I need to use GD.pm, it's not installed on my
> server. I have a paid webhosting account (server
> shared with other users)
>
> Tech support on my webhosting company say "we
> don't install custom perl modules, sorry"
Dump them. Go somewhere else.
> And I need GD.pm working. Any ideas?
Go somewhere where they install it for you.
> I tried to upload GD.pm to the same directory
> of my program (/cgi-bin/graphgenerator/)
> and add that directory to the search path
> but it does not work.
Get a machine with the same OS as your provider.
unpack the GD distribution
perl Makefile.PL PREFIX=/tmp/perl5
make
make install
tar up anyting under /tmp/perl4, and install it on your account, say
under $HOME/perl5
in your script:
use lib '/home/whoami/perl5';
and that should work.
If they have NT, you'll have to figire out whether you can make ppm
install somewhere else than in the standard spot.
>
> Any ideas?
> This is off-topic but I can't find a suitable
> group for this question.
It's not horribly offtopic, but clp.modules would have been more
appropriate.
> I have the same problem with GD for PHP3 on
> the same server.
Can't tell you ow to do the PHP thing. If they didn't compile that into
PHP, I'm pretty sure that you won't be able to use it. Go to another
provider, and next time you sign up with one, make sure that you know in
advance how cooperative they are going to be when you want something.
Martien
--
Martien Verbruggen |
Interactive Media Division | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd. | bundled with your Microsoft product.
NSW, Australia |
------------------------------
Date: Sat, 19 Aug 2000 23:14:19 +0200
From: "Alexander" <thewarehouse@europe.com>
Subject: Great software deals
Message-Id: <8nmt6a$anm$5@SOLAIR2.EUnet.yu>
Hey, everybody!
This is a letter to inform you that our company, The Programmer's
Warehouse, is selling all the hottest software, such as programming
languages (Delphi, Visual Studio, Borland C++), animation and rendering
software (3D Studio MAX, Lighthouse, Maya), CAD software (AutoCAD,
ArchiCAD, MathCAD), graphics software (Photoshop, Corel), database
software (Oracle, DBase), but also more diverse things, such as RedShift for
astronomy lovers, and many other things. The best part, of course, is
that most prices range from only $39.95 to only $69.95. Take advantage
of this great offer, and contact us at thewarehouse@europe.com .
Remeber, you are not forced to buy anything, and all inquiries are
welcome. Why pay thousands of dollars for this software, when you can
have it much cheaper. So drop us an e-mail at thewarehouse@europe.com
for more details.
Sincerely,
The Programmers's Warehouse
thewarehouse@europe.com
------------------------------
Date: Sat, 19 Aug 2000 15:45:38 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Great software deals
Message-Id: <MPG.1408adef91dc218c98aca8@nntp.hpl.hp.com>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <8nmt6a$anm$5@SOLAIR2.EUnet.yu>, thewarehouse@europe.com
says...
> Hey, everybody!
> This is a letter to inform you that our company, The Programmer's
> Warehouse, is selling all the hottest software, such as programming
> languages (Delphi, Visual Studio, Borland C++), animation and rendering
> software (3D Studio MAX, Lighthouse, Maya), CAD software (AutoCAD,
> ArchiCAD, MathCAD), graphics software (Photoshop, Corel), database
> software (Oracle, DBase), but also more diverse things, such as RedShift for
> astronomy lovers, and many other things. The best part, of course, is
> that most prices range from only $39.95 to only $69.95. Take advantage
> of this great offer, and contact us at thewarehouse@europe.com .
> Remeber, you are not forced to buy anything, and all inquiries are
> welcome. Why pay thousands of dollars for this software, when you can
> have it much cheaper. So drop us an e-mail at thewarehouse@europe.com
> for more details.
>
> Sincerely,
> The Programmers's Warehouse
> thewarehouse@europe.com
Spam is not welcome in this newsgroup, nor I assume in any of the other
dozen or so that you have plastered. Your ad doesn't even mention Perl,
making this spam all the more gratuitous.
I've removed all the others from my response. Maybe you should send
each of them an apology for this egregious behavior.
FOAD.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 19 Aug 2000 12:12:54 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: help with RegExp
Message-Id: <399EDC36.266D34CB@stomp.stomp.tokyo>
"Alex T." wrote:
> I need to remove suffixes from last names.
> WHITE<any number of blanks>JR
> should become WHITE
> ST<any number of blanks>LOUIS<any number of blanks>III
> should become ST LOUIS
> I tried this:
> $lastname =~ s/([\w|\s]+?)\s+?(\w+?)$/$1/i;
> and a few other ways, but I couldn't get it to work. How can I do it?
An alternative to usual Cargo Cult. This is based upon your
set parameters of no leading space and no trailing space.
However, I use leading spaces in my data to help hold my
interest in such a simple task. You will notice I included
multiple spaces in my data as set by your parameters.
With no leading space or spaces, you may remove this line:
$element =~ s/^\s+//;
Should you decide you have a trailing space or spaces,
this snippet is easy enough to add, after my global removal
of multiple spaces and before my substring operation:
$element =~ s/\s+$//;
Both snippets above treat multiple spaces which is not
really needed for my script. However, this style may
be of help should you try something different involving
multiple spaces without a global replacement to one space.
This test script will parse quite a combination of names,
which may include a first name, middle name, initials, a
last name in any combinations. Only requirement is you
stick with your parameters for a suffix. With this script,
there is no need to sort out only your last name and suffix.
You may treat an entire full name with desired results;
removal of a suffix.
TEST SCRIPT:
____________
#!/usr/local/bin/perl
print "Content-Type: text/plain\n\n";
$string = "Robert Frost I
Robert Frost II
Robert Frost III
Robert Frost Esq.
Robert Frost Esquire
Robert Frost Jr.
Robert Frost Junior
Robert Frost Sr.
Robert Frost Senior";
@Array = split (/\n/, $string);
foreach $element (@Array)
{
$element =~ s/\s+/ /g;
$element =~ s/^\s+//;
$element = substr ($element, 0, ${\rindex ($element, " ")});
print "$element\n";
}
print "\n\n\nGodzilla Rocks!";
exit;
PRINTED RESULTS:
________________
Robert Frost
Robert Frost
Robert Frost
Robert Frost
Robert Frost
Robert Frost
Robert Frost
Robert Frost
Robert Frost
Godzilla Rocks!
------------------------------
Date: Sun, 20 Aug 2000 00:44:18 GMT
From: michaeljgardner@my-deja.com
Subject: Re: help with RegExp
Message-Id: <8nn9l0$14v$1@nnrp1.deja.com>
In article <MPG.14074476e7cee7398ac96@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
> In article <8njjoh$gv$1@nnrp1.deja.com> on Fri, 18 Aug 2000 15:12:36
> GMT, michaeljgardner@my-deja.com <michaeljgardner@my-deja.com> says...
>
> ...
>
> > So, you've basically got a string of two "words" separated by one or
> > more spaces, and you want to convert it to the first word. Here's a
> > couple of ideas;
> >
> > 1) replace the space(s) and the last word with nothing
> >
> > $name=~s/\s+\w+//;
>
> As that might work earlier in the string if there were leading spaces
or
> more than two words, an anchor at the end would be a good idea.
>
> $name =~ s/\s+\w+$//;
>
> > 2) return just the first word;
> >
> > $name=~m/(^\w+)/;
> >
> > I'm not sure if the second one changes $name's value to the match,
so I
> ^^^^^^^^^^^^^^^
> > put parenthesis around the match so that in any event, the first
match
> > would be saved in the system variable $1. So you may need to re-
assign
> ^^^^^^^^^^^^^^^
> > $name=$1.
>
> If you can run a Perl program, it takes less effort to test these
> conjectures than to talk about them. If you can't run a Perl
program,
> why are you responding here?
>
> Or you could even read (gasp!) perlop before posting, to further your
> own knowledge so as to be able better to help others.
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
>
Larry,
Your comments are valid. I am honored that you took time to reprimand
me. Next time I'll run the script prior to posting.
Michael
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sat, 19 Aug 2000 18:59:09 GMT
From: behrens@haulpak.com (Astrid Behrens)
Subject: Re: How do I get statistics from Win NT processes? (ie total memory used by process)
Message-Id: <slrn8ptmn7.f53.behrens@pc32.haulpak.com>
amonotod <amonotod@netscape.net> wrote:
>In article <slrn8pqu2p.e0c.behrens@pc32.haulpak.com>,
> behrens@haulpak.com (Astrid Behrens) wrote:
>> There were a couple scripts like that posted to the perl-ntadmin
>> mailing list, about a month or two ago.
>> You could try searching for them at
>> http://www.topica.com/lists/perl-ntadmins/
>>
>>
>That is great advice, but you should've refered him to:
>Perl-Win32-Admin@listserv.ActiveState.com,
>http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin
>since ActiveState actually hosts the list.
>
I think they are two separate lists.
Astrid
------------------------------
Date: Sat, 19 Aug 2000 21:05:21 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: How do I get statistics from Win NT processes? (ie total memory used by process)
Message-Id: <8nmsq7$jfq$1@nnrp1.deja.com>
In article <slrn8ptmn7.f53.behrens@pc32.haulpak.com>,
behrens@haulpak.com (Astrid Behrens) wrote:
> amonotod <amonotod@netscape.net> wrote:
> >In article <slrn8pqu2p.e0c.behrens@pc32.haulpak.com>,
> > behrens@haulpak.com (Astrid Behrens) wrote:
> >> There were a couple scripts like that posted to the perl-ntadmin
> >> mailing list, about a month or two ago.
> >> You could try searching for them at
> >> http://www.topica.com/lists/perl-ntadmins/
> >>
> >>
> >That is great advice, but you should've refered him to:
> >Perl-Win32-Admin@listserv.ActiveState.com,
> >http://listserv.ActiveState.com/mailman/listinfo/perl-win32-admin
> >since ActiveState actually hosts the list.
> >
>
> I think they are two separate lists.
>
> Astrid
>
Be that the case, I shall check it out myself, thanks.
amonotod
--
`\|||/ amonotod@
(@@) netscape.net
ooO_(_)_Ooo________________________________
_____|_____|_____|_____|_____|_____|_____|_____|
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 20 Aug 2000 02:25:39 +0200
From: "Henri" <hvenetie@casema.net>
Subject: Need help of a Perl expert!!!
Message-Id: <399f25c5$0$13616@reader3>
I start learning Perl but at this moment I don't have enough knowledge to
solve the following problem Who would like to help me.
I have a Linux server with Apache installed on it. Several pc's contact my
server and when they are online the server gets info from that pc's (ip
+port number).
This "whoisalive" htm file is as follows
<table border="1">
<tr>
<td><a href="http://1.2.3.4/alive/live.htm"><img border="0"
src="http://1.2.3.4.10:2000/cgi-bin/image" width="75" height="57"
alt="pc001"></a><td>
</tr>
</table>
Is it possible to check with Perl that if the pc is online he is going to
get the information from the pc and when the pc is offline he shows an
offline image. For instance:
<table border="1">
<tr>
ping 1.2.3.4
if alive
print <td><a href="http://1.2.3.4/alive/live.htm"><img border="0"
src="http://1.2.3.4.10:2000/cgi-bin/image" width="75" height="57"
alt="pc001"></a><td>
else
print "offline image pc001"
endif
</tr>
</table>
It must be possible to generate a html file of all of this.
I know it is a stupid question but I'm a newbie concerning Per :-(
THNX very much for the help.
Henri.
------------------------------
Date: 20 Aug 2000 01:46:19 +0100
From: nobull@mail.com
Subject: Re: Need help of a Perl expert!!!
Message-Id: <u9g0o02204.fsf@wcl-l.bham.ac.uk>
"Henri" <hvenetie@casema.net> writes:
> Subject: Need help of a Perl expert!!!
Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
> I start learning Perl but at this moment I don't have enough knowledge to
> solve the following problem
The two halves of this statement are probably unrelated.
What makes you think that the knowledge you are lacking is Perl
knowledge? Could you solve the problem in some other language?
> Is it possible to check with Perl that if the pc is online he is going to
> get the information from the pc and when the pc is offline he shows an
> offline image.
Actually it's fundametally impossible to detect that a IP host is
offline execpt by trying to communicate with it and timing-out. Of
course if you time-out quickly you never know if it's really off line
or you've just not waited long enough.
> For instance:
> ping 1.2.3.4
Indeed this is what the ping command does.
There is a Perl module available on CPAN (www.cpan.org) that does
something similar to the ping command. Guessing the name is left as
an exercise for the reader.
I should point out however that while the module does something
similar to the "ping" command it is not quite identical and it is
important to read them manual that comes with it. To see the mess that
you get into if you don't read the manual do a Usent search in this
group on the name of the module.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 19 Aug 2000 22:48:07 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: newbie: s/// on windows subdirs?
Message-Id: <8nn2r7$33g$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Christoph
<nospam@nowhere.net>],
who wrote in article <8nk4qa$9b7$1@news.rrz.Uni-Koeln.DE>:
> Could someone point me to a perl script that will perform a string
> substitution on all files that have one of several given file extensions
> (for example *.htm and *.html and *.txt) in a directory and all of its
> subdirectories on a Windows (!) system?
pfind /this/directory "s/foo/bar/"
(pfind is on CPAN in my directories).
Ilya
------------------------------
Date: Sat, 19 Aug 2000 15:07:00 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: obfusicate routine to count max string len in hash
Message-Id: <MPG.1408a4db167a21fe98aca6@nntp.hpl.hp.com>
In article <39a2aa70.8183019@news.newsguy.com>, kcivey@cpcug.org says...
> Larry Rosler <lr@hpl.hp.com> wrote:
> >Jim Mauldin <mauldin@netstorm.net> says...
> >> Larry Rosler wrote:
>
> >> > print length +(sort keys %hash)[-1];
> >>
> >> Very nice as usual, Larry, but help me out here.
> >
> >But wrong; see below.
> >
> >> I believed the
> >> +(whatever) construct to be essentially a precedence manager.
> >
> >In this case, it disambiguates the left paren from being the beginning
> >of a parenthesized arg list for print().
>
> You meant length(), not print(), of course.
... of a parenthesized argument for length().
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Sat, 19 Aug 2000 14:37:04 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Problem with hash initialization using list
Message-Id: <MPG.14089dd8af9fcfc998aca5@nntp.hpl.hp.com>
In article <399EBA72.D8FE82FC@home.com>, rick.delaney@home.com says...
+
+ Keith Calvert Ivey wrote:
+ >
+ > Larry Rosler <lr@hpl.hp.com> wrote:
+ >
+ > >So why not write it as
+ > >
+ > > chomp for values %info;
+ > >
+ > >One token fewer, at that!
+ > >
+ > >Note to the unwary: The values() function wasn't lvaluable until
5.6.0.
+ >
+ > If it's really lvaluable, shouldn't you be able to do
+ >
+ > chomp values %info
+ >
+ > to save another token?
+
+ I'd think so.
But you'd be wrong. Experience teaches that testing is better than
guessing what Perl will do, especially in the absence of a language
definition.
Can't modify values in chomp at ...
+ But if you just want to save tokens you can do
+
+ chomp %info;
+
+ in 5.6 or 5.5.3. I'm not sure how far back this works. It isn't
+ documented very well. Up until today I didn't know you could do this
+ and I only found out by poking through the source for the cause of the
+ bug you mentioned.
That this does work -- and the previous attempt doesn't work -- is quite
surprising. If the hash is expanded into a list, one would expect the
keys to be chomped also; but they aren't. So it falls into the usual
Perl DWIMmery -- useful, ad hoc, and undocumented.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
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 4068
**************************************