[9586] in Perl-Users-Digest
Perl-Users Digest, Issue: 3180 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 16 18:08:23 1998
Date: Thu, 16 Jul 98 15:00:50 -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 Thu, 16 Jul 1998 Volume: 8 Number: 3180
Today's topics:
Re: Arrays <iadcon@lexmark.com>
Re: cgi module confusion (William R. Ward)
Re: Chomp() on win32 and unix perl (Jonathan Stowe)
client server programming sonigopi@hotmail.com
Re: dynamically changing values in html from script.... (-)
Re: find total file size / HD space left? (Steve Linberg)
Re: getting hostname and ip addr when you don't have ei (Bill Totten)
Re: HELP: Internet Database Design questions... <dcrombie@chirp.com.au>
Invoking a Programme from HTML. <conservative-party@iname.com>
Re: Invoking a Programme from HTML. (brian d foy)
Re: mail bomber source code for perl. (Jonathan Stowe)
Re: newbie date format (Jonathan Stowe)
Re: OFFTOPIC: Re: HELP: Internet Database Design questi (Steve Linberg)
Re: open (IN, "foo.txt") works, open (IN, "$foo") does (Joseph A. DiVerdi, Ph.D.)
Re: open (IN, "foo.txt") works, open (IN, "$foo") does (-)
Re: Perl call from win32 (Jonathan Stowe)
Re: Perl Setup on NT (Jonathan Stowe)
Re: perldb <barmar@bbnplanet.com>
Re: Please Help Me! (Matt's Script BB Problem) (I R A Aggie)
Re: Question - push() unique? (Steve Linberg)
Re: Question - push() unique? <tchrist@mox.perl.com>
Re: Question - push() unique? (Sean McAfee)
Re: real quick and easy - replace.... (Craig Berry)
Re: real quick and easy - replace.... (Craig Berry)
Re: Remote registry editing on NT (Tye McQueen)
Re: Setting up Perl database (Michael J Gebis)
Re: Silly things to do in Perl (or: is that Laptop wate (Jonathan Stowe)
Simultaneous Telnet/TCP sessions ? david2020@my-dejanews.com
Re: Simultaneous Telnet/TCP sessions ? (Steve Linberg)
Telnet Calls david2020@my-dejanews.com
Re: Telnet Calls (Kelly Hirano)
Re: What is awk better at than perl? (Larry quote) (Ilya Zakharevich)
Re: What is awk better at than perl? (Larry quote) (Ilya Zakharevich)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 16 Jul 1998 16:44:40 -0400
From: "hww" <iadcon@lexmark.com>
Subject: Re: Arrays
Message-Id: <35ae65d3.0@usenet.lexmark.com>
What is your "MAX" anyway?
Shaun Sides wrote in message ...
> Quoting The Wildman - in comp.lang.perl.misc you wrote:
>
>> I'm having a little trouble with arrays. Okay, a LOT. I don't understand
how
>> they work in perl at all. I'm trying to do something like this:
>> for ($i = 0;$i < MAX;$i++) {
>> $array[$i] = $i;
>> }
>>
>> But of course it isn't working. You can see what my coding background is,
>> too, I suppose. :D
>
>Weird that it isn't working for you. I just did
>
>perl -we 'for ($i = 0; $i < 5; $i++) {$array[$i] = $i} print "@array\n"'
>
>and it output
>
>0 1 2 3 4
>
>I even left out the semicolons. ;-)
>
>--
>Shaun L. Sides arch@abts.net
> Free Randal Schwartz and Ric Flair!
>
>Oxymoron: NT security
------------------------------
Date: 16 Jul 1998 14:09:59 -0700
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: cgi module confusion
Message-Id: <waak95d1p08.fsf@ese.UCSC.EDU>
"Bob Gwynne" <gwynne@utkux.utk.edu> writes:
> >For a comparison of these modules that I did for a talk last year, see
> >this URL:
> > http://www.bayview.com/mindsrc-talk/
> >
>
> Bill:
> The link doesn't work at this time. In addition, the genome links
> aren't working.
> Investing in Lincoln Stein's Official Guide to Programming with CGI.pm is
> worthwhile.
I've been having a lot of problems lately with my system - please try
again later.
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
-----------------------------------------------------------------------------
"Language is a virus from outer space." --William S. Burroughs
------------------------------
Date: Thu, 16 Jul 1998 21:57:38 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Chomp() on win32 and unix perl
Message-Id: <35ae4f82.4882393@news.btinternet.com>
On Wed, 15 Jul 1998 22:26:59 GMT, Marc Haber wrote :
>
>Well, can you recommend a decent X server for WinNT that is free?
>
Mi/X from MicroImages Inc at:
http://www.microimages.com/freestuf/mix/
Is reasonably good though some of Solstice will crash it.
>Also, how to behave when the Linux box is a 386DX that does not run X
>for obvious performance reasons?
>
If you really think you can use NFS or Samba on said box then you
might check out PFE32 which will save in either Unix or DOS mode.
>>But chomp() was the topic under discussion . . .
>
>You are so right. I am merely pointing out that there are situations
>when you are "forced" to do as "we" do.
>
But there is not point in making things difficult for yourself.
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Thu, 16 Jul 1998 20:54:32 GMT
From: sonigopi@hotmail.com
Subject: client server programming
Message-Id: <6olpa8$k4b$1@nnrp1.dejanews.com>
Is there a good book on client/server programming in perl with many, many
full example?
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Thu, 16 Jul 1998 21:51:54 GMT
From: root.noharvest.\@not_even\here.com (-)
Subject: Re: dynamically changing values in html from script....
Message-Id: <35ae7526.223985055@nntp.idsonline.com>
visualsolutions@easynet.on.ca (Sue & Mike) Said this:
>
> Hi,
>
> I am writing a script to control a form that accepts shipping
>information. One of the requirements is that if the country is
>Canada, I display the provinces or if the country is USA, then display
>the states in the same spot.
>
> Can this be accomplished via a Perl cgi script or is this something
>I have to take care of using some client side java script????
>
To have it "magically" appear on the very same page depending on the
country code, it will probably have to be javascript - but I would
suggest against doing that since some browsers don't support
javascript and some people may have it "turned off".
The best thing to do is make a "branch" somewhere where you split off
US and Canadian orders into two different forms.... maybe on the
"Complete Your Order" action, you print a simple page that says "Click
here if your order will be shipped to Canada" and "All others click
here". Then you can produce a shipping form specifically for each
setting.
For order forms and any "shopping cart" type stuff, you should avoid
anything like java, javascript or any other "feature" that is not
widely supported among all the "major" browser variations. You are
trying to make money here, not impress or wow people, so keep that
part of your site simple.
------------------------------
Date: Thu, 16 Jul 1998 16:08:07 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: find total file size / HD space left?
Message-Id: <linberg-1607981608070001@projdirc.literacy.upenn.edu>
In article <6old6e$j9u@enews2.newsguy.com>, "Ronald Chen" <rchen@wyle.com>
wrote:
> How do I find out the total size of the files in a particular directory and
> its subdirectory under dos? and the total harddisk space left? It's
> similar to the "dir/s" command under dos, but all I need is those two info.
> :)
This is a dos question posted to comp.lang.perl.misc? Try
comp.os.arcane.outdated.ms-dos. :)
Seriously, post your question in a dos group.
_____________________________________________________________________
Steve Linberg National Center on Adult Literacy
Systems Programmer &c. University of Pennsylvania
linberg@literacy.upenn.edu http://www.literacyonline.org
------------------------------
Date: 16 Jul 1998 16:30:24 -0400
From: biell @ udel . edu (Bill Totten)
Subject: Re: getting hostname and ip addr when you don't have either
Message-Id: <6olnt0$moh$1@copland.udel.edu>
In article <6o119m$n86$1@nnrp1.dejanews.com>, <chrisoc@ans.net> wrote:
>What is the easiest and most platform-independent way to
>get the current hostname and IP address from inside a Perl
>script, when you don't have either one? If this were in
>a shell script I'd ping myself and grep and awk the output.
>I dislike escaping into shell calls from Perl and want to see
>what folks who think easily in Perl can show me about this.
>I cannot depend on having any modules installed on the box.
Well, Sys/Hostname.pm is pretty much a standard. If you do not want
to use the module, you can try
chomp($hostname=`hostname`);
then use `gethostbyname' to get the ip.
Or, you can look in the environment for the name of the host, I think
that is what Sys/Hostname.pm tries first.
--
Totten, William David (Bill) Computer and Information Science Major
totten @ pobox . com University of Delaware (Newark, DE; USA)
http://pobox.com/~totten/ Friends don't let friends use emacs
------------------------------
Date: Thu, 16 Jul 1998 22:48:36 +1000
From: Duncan Crombie <dcrombie@chirp.com.au>
Subject: Re: HELP: Internet Database Design questions...
Message-Id: <35ADF69E.2C3D3CB0@chirp.com.au>
For faster development use PHP3 (http://www.php.net/) with PostgreSQL, mySQL
or similar free database. I have found nothing easier.
Duncan Crombie
dcrombie@chirp.com.au
Babu Zaneer wrote:
>
> FYI.
> ASP contains (or was containing) dangerous bugs like showing up the entire asp
> file. This will reveal even the password for the database ( if you are
> supporting DB operations!).
> This bug was happenning if you put a dot (.) after the .asp extension. MS
> corrected it . Then it was happening when ::$DATA was appended to the URL. Seems
> that MS corrected this too ( What next?).
> Ofcourse for faster development asp is a better solution.
>
> jose wrote:
>
> > I was wondering when someone would answer this Unix person..
> >
> > I for one have seen NT w/IIS and ASP running fine, it's a solution that
> > works fine, because it's a MS solution to a common problem, designing a web
> > site that produces dynamic content and not something that changes once in a
> > while.
> >
> > So the web is floating with Unix boxes and that doesn't mean we have forget
> > about the others. For the UNIX person "-", you might want to look at some
> > other technologies floating around the web..
> >
> > Access and ASP, do work.
> >
> > Craig Bloom wrote in message <35A7F6BA.CD772C46@bones.org>...
> > >Geez... the guy just wants to add a little database functionality, and it
> > >doesn't even sound mission-critical. These Unix snobs really irk me
> > >sometimes. Why overcomplicate the matter for someone who is just getting
> > >started? I agree... NT, IIS, ASP and Access for quick development and fast
> > >results. And it is a nice introduction to database manipulation for those
> > >who haven't put their foot in the water yet. Later move it to MSSQL Server
> > >if you need it to be more robust. The transition should be fairly
> > painless.
> > >
> > >OR you can waste many hours learning your way around the unix operating
> > >system, teaching yourself perl and stuffing data into (real efficient, yeah
> > >right) flat file databases. Boy, tough choice.
> > >
> > >OK, now you can tell us again how much smarter you are because you use
> > unix.
> > >
> > >
> > >
> > >No-name guy wrote:
> > >
> > >> Catherine Skidmore <eppie@interport.net> Said this:
> > >>
> > >> >Avi Goldenberg wrote:
> > >> >
> > >> >> 1) What are the current technologies needed to achieve the minimum of
> > >> >> data storage, retrieval, and manipulation? (I prefer to stay NT as
> > >> >> opposed to UNIX)
> > >> >
> > >> >ooh. Access and ASP. or Access and Cold Fusion.
> > >>
> > >> Oh my GOD. No.
> > >>
> > >> >
> > >> >> 2) What do I need to look for in a hosting service to allow me to
> > >> >> achieve #1?
> > >> >
> > >> >an NT Box running IIS.
> > >> >
> > >>
> > >> Argh. New to computing? Must be.
> > >
> > >
> > >
------------------------------
Date: Thu, 16 Jul 1998 23:06:10 +0200
From: "Michael W. Lancaster" <conservative-party@iname.com>
Subject: Invoking a Programme from HTML.
Message-Id: <35AE6B42.159FD64D@iname.com>
Thursday, 16th July, 1998
Accosts,
I should wish to initiate the execution of a CGI/PERL programme when an
HTML page is loaded, automatically rather than through a process (such
as clicking on a hyper-text link). My U. R. L. is:--
http://www.serve.com/lordgovernor/
I have tried using three statements but to no avail;
<!--exec cgi="/lordgovernor/cgi/script.cgi"-->
<!--exec cgi="/full/path/to/cgi/script.cgi"-->
<!--include virtual="/lordgovernor/cgi/script.cgi"-->
I understand that this is more of an HTML question and I apologise for
that. I do hope that some one may be of assistance to me. Thank you in
advance.
Michael W. Lancaster.
--
Conservative Party - Michael W. Lancaster
http://www.serve.com/lordgovernor/
http://www.tory.org.uk/
------------------------------
Date: Thu, 16 Jul 1998 17:49:46 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Invoking a Programme from HTML.
Message-Id: <comdog-ya02408000R1607981749460001@news.panix.com>
Keywords: from just another new york perl hacker
In article <35AE6B42.159FD64D@iname.com>, "Michael W. Lancaster" <conservative-party@iname.com> posted:
>I have tried using three statements but to no avail;
>
><!--exec cgi="/lordgovernor/cgi/script.cgi"-->
><!--exec cgi="/full/path/to/cgi/script.cgi"-->
><!--include virtual="/lordgovernor/cgi/script.cgi"-->
see the Server Side Include section of the CGI Meta FAQ.
good luck :)
--
brian d foy <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>
------------------------------
Date: Thu, 16 Jul 1998 21:57:43 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: mail bomber source code for perl.
Message-Id: <35ae69ce.11614220@news.btinternet.com>
On Thu, 16 Jul 1998 01:51:18 GMT, Bob Trieger wrote :
>Matthew Flinchbaugh <matthew@nofear.hjsoft.com> wrote:
>-> hey does any one have the perl source code for a mail bomber?
>-> for Linux
>-> ?
>
>troll of the month award?
>
FMOTW at least.
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Thu, 16 Jul 1998 21:57:44 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: newbie date format
Message-Id: <35ae6c8f.12298421@news.btinternet.com>
On Thu, 16 Jul 1998 16:34:51 +0100, F.Quednau wrote :
>F.Quednau wrote:
>>
>> See man printf
>>
>Although I have to say that printf and its possibilities should be
>covered in some part of the Perl documentation. Why ?
>-
All the format conversions are documented in the perlfunc man page for
sprintf.
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Thu, 16 Jul 1998 17:09:24 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: OFFTOPIC: Re: HELP: Internet Database Design questions...
Message-Id: <linberg-1607981709240001@projdirc.literacy.upenn.edu>
In article <6ojl4j$iku$1@news.infonex.net>,
cabneySP4M@SP4M.SP4Mcyberpass.net (C. Abney) wrote:
> If you *really* want to know why you shouldn't want to do anything using
> NT, or IIS, or any of MS offalings, just point your browser at:
>
> http://www.any.site.stupid.enough.to.serve.asps/default.asp::$DATA
>
> and you will understand that what you don't see is often what you get
> when you buy from MS. Using a computer on the web is /not/ the act of a
> pedestrian. Frightening. Kind of makes one want to stick with perl if
> only to stay away from VBscript ( among its other weaknesses. I don't
> really know if this works for _any_ scripted page on IIS or not, I am
> only trying to bring the discussion a little closer to on topic. :)
In all fairness, you can retrieve Perl source this way too, or any
scripted page running under IIS. It's not just a vb problem, it's an IIS
problem. But it *is* huge.
_____________________________________________________________________
Steve Linberg National Center on Adult Literacy
Systems Programmer &c. University of Pennsylvania
linberg@literacy.upenn.edu http://www.literacyonline.org
------------------------------
Date: Thu, 16 Jul 1998 15:56:22 -0600
From: diverdi@XTRsystems.com (Joseph A. DiVerdi, Ph.D.)
Subject: Re: open (IN, "foo.txt") works, open (IN, "$foo") does not???
Message-Id: <diverdi-1607981556230001@tulip8.verinet.com>
In article <oguptv9t.fsf@mailhost.panix.com>, Jonathan Feinberg
<jdf@pobox.com> wrote:
>Juergen.Puenter@materna.de (J|rgen P|nter) writes:
>
>> open (FHIN, "$file") || die "Error 1: $!\n";
>
>You might want to be explicit about your filemodes; it helps in
>maintenance. Also, your error message is not informative. Finally,
>you may wish to omit the trailing newline in your die() so that perl
>will tell you the line number.
>
> open (FHIN, "<$file") || die "Can't open '$file' for read: $!";
>
>See if these suggestions help you sort out your problem.
Jonathan offers some excellent suggestions. If you follow them I suspect
that you will find a trailing character (newline, etc.) in your $file
variable.
--
Joseph A. DiVerdi, Ph.D. 970.221.3982 (voice)
diverdi@XTRrsystems.com (email) 970.224.3723 (fax)
http://www.XTRsystems.com
%PGPKey=('BB1469AB',[1024,'24DA 2D00 ABB0 D26F 4E14 56C9 0CEF 1053 BB14 69AB'])
------------------------------
Date: Thu, 16 Jul 1998 21:57:25 GMT
From: root.noharvest.\@not_even\here.com (-)
Subject: Re: open (IN, "foo.txt") works, open (IN, "$foo") does not???
Message-Id: <35ae768a.224341080@nntp.idsonline.com>
Juergen.Puenter@materna.de (J|rgen P|nter) Said this:
>Yes, I checked that $file in these cases contains the proper path
>without any \n or other unwanted stuff and that I really chdir'ed
>to where I thought I chdir'ed. All appears to be exactly what I
>want but still the script dies.
>
>Die always says 'File or directory not found'. Of course, the file
>is there, as is the directory. Both permissions are 777. And as I
>said, both _can be read_ if $file is hardcoded. BTW, -w has nothing
>to complain about my script.
>
>Should this turn out to be unrelated to Perl, I apologize, but at
>the moment I'm totally puzzled and don't even know where to look
>for an answer.
>
Try passing the FULL path information into the script. If you have a
form, enter the full path, if you are urlencoding it do it like this:
http://www.blah.com/cgi-bin/script?file=/home/user/path/file
It's possible that somehow the chdir is your problem. You don't have
to change the "working directory" in order to open a file.... open
(FILE, "/full/path/file") works, as does open(FILE,
"./relative/to/current/dir/file")
------------------------------
Date: Thu, 16 Jul 1998 21:57:41 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Perl call from win32
Message-Id: <35ae59c8.7512202@news.btinternet.com>
On Tue, 14 Jul 1998 09:59:47 -0700, Orson Ka'ili wrote :
>Scenario:
>
>I have a win32 perl script that gets triggered by an event. This in turn
>should call a paging programming running on a unix system. The paging
>program itself can be accessed via an http call (CGI) on a browser or
>from the unix command line. What is the best way to make the call to the
>paging program and how?
>From CPAN : libwww-perl (aka LWP) this is very well documented with
examples etc.
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Thu, 16 Jul 1998 21:57:47 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Perl Setup on NT
Message-Id: <35ae73fa.14107211@news.btinternet.com>
On Wed, 15 Jul 1998 22:30:55 -0400, tdean wrote :
>steve :
>If I am at the C:\ and type in perl c:\perl\bin\perlscript.pl, yes it works
>what I want is to be at the c:\ and type perl perlscript.pl
>sure I can cd\perl\bin and type perl perlscript.pl and that works, but I
>thought by having c:\Perl;C;\perl\bin on the end of the path it would be
>able to find it.Perhaps the c:\perl;c:\perl\bin should be at the beginning
>of the path?
>
check out what it says about the -S flag in the perlrun manpage er
perldoc.
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Thu, 16 Jul 1998 21:24:50 GMT
From: Barry Margolin <barmar@bbnplanet.com>
Subject: Re: perldb
Message-Id: <Ccur1.24$P34.367253@cam-news-reader1.bbnplanet.com>
In article <shtilEw75H3.Cpn@netcom.com>, Yuri Shtil <shtil@netcom.com> wrote:
>I am trying to run a perl script under the perldb emacs package.
>I use Getopt::Std module to parse arguments. The problem is that perldb
>does not like quoted strings, so -c "foo bar" does not become foo bar, but
>"foo. I tried perl -d, and it works. I guess the shell does it's job,
>but perldb does not.
>
>ANy clues ?
Run the command with no arguments, and when you get to the Perl debugger
prompt, set the arguments with something like:
@ARGV=("-c", "foo bar")
--
Barry Margolin, barmar@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
------------------------------
Date: Thu, 16 Jul 1998 15:02:21 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Please Help Me! (Matt's Script BB Problem)
Message-Id: <fl_aggie-1607981502210001@aggie.coaps.fsu.edu>
In article <35AE2B09.1C72@min.net>, jdporter@min.net wrote:
+ 1. Contact Matt directly. He wrote the crap; the onus is on him.
He's stated, in the documentation, and in several other forums that
he may or may not correct bugs in his script archive. Reading between
the lines: its free software, and if it works for you, great, if not,
then dump into the trash.
James
------------------------------
Date: Thu, 16 Jul 1998 16:06:42 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Question - push() unique?
Message-Id: <linberg-1607981606420001@projdirc.literacy.upenn.edu>
In article <6olhae$ajf$1@service3.uky.edu>, aarond@alpha.ewl.uky.edu
(Aaron B. Dossett) wrote:
> John Paul Hernandez (jph@sjrwmd.state.fl.us) wrote:
> > is there a function or some other elegant way to push a value onto an
> > array IF that value does not already exist in the array?
> >
> > something like, push(@a,$v) unless $v exists is @a ?? i looked at
> > exists, and that seems to work only for a hash.
>
> Is there a reason you couldn't just use a hash instead of an array?
Right. If you want this kind of functionality, you probably really want a
hash. Post an example of what you're trying to do if you think you
really need an array. There's no way that I know of to see if a certain
value is present in an array other than iterating through it to see.
_____________________________________________________________________
Steve Linberg National Center on Adult Literacy
Systems Programmer &c. University of Pennsylvania
linberg@literacy.upenn.edu http://www.literacyonline.org
------------------------------
Date: 16 Jul 1998 20:12:15 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Question - push() unique?
Message-Id: <6olmqv$oi1$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
John Paul Hernandez <jph@sjrwmd.state.fl.us> writes:
:is there a function or some other elegant way to push a value onto an
:array IF that value does not already exist in the array?
:something like, push(@a,$v) unless $v exists is @a ?? i looked at
:exists, and that seems to work only for a hash.
:do i really need to use a foreach loop and verify each array element
:before pushing?
*Searching* an array for something is a bad idea. Arrays aren't designed
to be searched. That you should be trying to do so calls into question
whether you you are employing the wrong data structure. A few forays
into the FAQ would reveal much about this--perlfaq4, to be precise.
:any modules?
A module is not a substitute for learning Perl. Until you start
thinking in terms of hashes, you aren't thinking in Perl. Here are
some examples. Their explanation is left as an exercise for the reader.
One you understand and embrace them them, you will be on the way to
better thinking in Perl.
EG #1:
%seen = ();
foreach $item (@list) {
push(@uniq, $item) unless $seen{$item}++;
}
EG #2:
%seen = ();
@unique = grep { ! $seen{$item} ++ } @list;
EG #3:
%seen = ();
while (<>) {
next unless /^From:?\s/i .. /^$/;
while (/([^<>(),;\s]+\@[^<>(),;\s]+)/g) {
print "$1\n" unless $seen{$1}++;
}
}
EG #4:
foreach $linkpair (@{$ht_tree->extract_links(qw<a img>)}) {
my($link,$elem) = @$linkpair;
push(@urls, $fqurl)
unless $seen{ $fqurl = url($link,$base)->abs->as_string }++;
}
EG #5:
for (split(/:/, $ENV{'PATH'})) {
next if /^\.?$/;
s![^/+]*$!man! && -d && !$seen{$_}++ && do {
($dev,$ino) = stat(_);
! $seen{$dev,$ino}++
} && push(@manpath,$_);
}
print join(":", @manpath), "\n";
EG #6:
%seen = ();
sub filefrob {
my $filename = shift;
my ($dev, $ino) = stat $filename;
if (! $seen{$dev, $ino}++) {
frobnicate($file);
}
}
EG #7:
foreach $filename (@files) {
($dev, $ino) = stat $filename;
push( @{ $seen{$dev,$ino} }, $filename);
}
foreach $devino (sort keys %seen) {
($dev, $ino) = split(/$;/o, $devino);
if (@{$seen{$devino}} > 1) {
# now the list of filenames for each unique
# file is stored in @{$seen{$devino}}
}
}
Get the picture yet? :-)
--tom
--
Besides, it's good to force C programmers to use the toolbox occasionally. :-)
--Larry Wall in <1991May31.181659.28817@jpl-devvax.jpl.nasa.gov>
------------------------------
Date: Thu, 16 Jul 1998 20:33:58 GMT
From: mcafee@joust.rs.itd.umich.edu (Sean McAfee)
Subject: Re: Question - push() unique?
Message-Id: <Wstr1.4026$24.23305930@news.itd.umich.edu>
In article <35AE07D5.96894181@sjrwmd.state.fl.us>,
John Paul Hernandez <jph@sjrwmd.state.fl.us> wrote:
>is there a function or some other elegant way to push a value onto an
>array IF that value does not already exist in the array?
>something like, push(@a,$v) unless $v exists is @a ?? i looked at
>exists, and that seems to work only for a hash.
push(@a, $v) unless grep { $_ eq $v } @a;
(Assuming we're dealing with strings; use == instead of eq for numbers,
or some kind of equals() method if you're dealing with objects, etc.)
As mentioned by others, though, you probably want something hash-like.
(I tried to write a quick-and-dirty module that would do what you want,
but the current limitations on tied arrays in Perl make it unfeasible.)
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: 16 Jul 1998 21:28:53 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: real quick and easy - replace....
Message-Id: <6olral$6p1$1@marina.cinenet.net>
joe (joe@rhein.to) wrote:
: Hello what is the function for replacing characters in a string... I cant
: find anything on this in my "learning perl book"
Then -- and I mean this entirely as helpful advice, not a criticism -- you
really do need a better book. Replacing characters (and larger chunks of
text) is one of the things Perl is best at, and any book that doesn't
cover this early and well is doing you no good.
In the meantime, the packaged documentation (available via perldoc,
bundled web pages, or the like depending on your platform) may come to
your aid. Look for s/// and tr/// in 'perlop', and substr in 'perlfunc'.
Best of luck!
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 16 Jul 1998 21:33:28 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: real quick and easy - replace....
Message-Id: <6olrj8$6p1$2@marina.cinenet.net>
merzky@physik.hu-berlin.de wrote:
: In article <6okct4$7fb$1@usenet36.supernews.com>,
: "joe" <joe@rhein.to> wrote:
: > Hello what is the function for replacing characters in a string... I cant
: > find anything on this in my "learning perl book"
:
: Really? Leaarning perl? page 88? 'Substitutions'? Hmm, I would bring it
: back then, it's not complete obviously...:)
:
: $string =~ tr/[a-z]/[A-Z]/g; # replace set of chars by diff. set (man tr)
Replacing [ by [ and ] by ] seems a bit like a make-work program for the
interpreter. And the g option must be from some beta version of Perl I
haven't seen yet. :)
How tr really works is:
$string =~ tr/a-z/A-Z/;
(of course, that's just a way of writing a non-locale-respecting version
of uc.)
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 16 Jul 1998 16:41:26 -0500
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: Remote registry editing on NT
Message-Id: <6ols26$bj2@fohnix.metronet.com>
maxwelzy@email.uc.edu (Zach Maxwell) writes:
) Does anyone have a slick way to do remote registry manipulation
) in PERL scripting?
I'd suggest you get Win32::TieRegistry (and the latest
Win32API::Registry) from CPAN. They were uploaded just recently.
Win32::TieRegistry used to be called Tie::Registry. I haven't
announced them yet since they should be included in a future
release of libwin32.
Win32::TieRegistry makes using the Registry (remotely or not) easy
in Perl. For details, see:
http://www.perl.com/CPAN/authors/Tye_McQueen/Win32-TieRegistry-0.20.readme
I used it to implement my RegistryPoint script that lets you do
batch changes to remote or local registries via files that look
like below. I should be releasing it an about a month. This
one installs RemoteCmd service remotely. RegistryPoint can even
install to copies of NT that aren't even booted if a local or
remote computer can access its files.
-copy
System32\OEMNSVRC.INF
"//Server/ThirdParty/Microsoft/NtSResKit/Common/NetAdmin/"
System32\RCMD.EXE
"//Server/ThirdParty/Microsoft/NtSResKit/i386/NetAdmin/"
System32\RCMDSVC.EXE
"//Server/ThirdParty/Microsoft/NtSResKit/i386/NetAdmin/"
-ccs
Services\RemoteCmd\
{
"Linkage\\" => { "Disabled\\" => {}, },
"Parameters\\" => {},
"Security\\" => $CCS->{"Services\\RpcSs\\Security\\"},
"\\Type" => [ "0x00000010", REG_DWORD ],
"\\Start" => [ "0x00000003", REG_DWORD ],
"\\ErrorControl" => [ "0x00000001", REG_DWORD ],
"\\ImagePath" =>
[ "\%SystemRoot\%\\System32\\rcmdsvc.exe", REG_EXPAND_SZ ],
"\\DisplayName" => [ "Remote Command Server", REG_SZ ],
"\\DependOnService" => [ ["LanmanServer"], REG_MULTI_SZ ],
"\\DependOnGroup" => [ [], REG_MULTI_SZ ],
"\\ObjectName" => [ "LocalSystem", REG_SZ ],
}
-sw
Microsoft\Ncpa\CurrentVersion\ConfigChanged\
{}
Microsoft\RemoteCmd\
{
"CurrentVersion\\" => {
"NetRules\\" => {
"\\InfName" => [ "OEMNSVRC.INF", REG_SZ ],
"\\InfOption" => [ "RCMD", REG_SZ ],
},
"\\ServiceName" => [ "RemoteCmd", REG_SZ ],
"\\RefCount" => [ "0x00000000", REG_DWORD ],
"\\SoftwareType" => [ "service", REG_SZ ],
"\\MajorVersion" => [ "0x00000003", REG_DWORD ],
"\\MinorVersion" => [ "0x00000005", REG_DWORD ],
"\\Title" => [ "Remote Command Server", REG_SZ ],
"\\Description" => [ "Microsoft Remote Command Server", REG_SZ ],
"\\InstallDate" => [ time, REG_DWORD ],
},
}
I include this because it is the handiest example I have of
doing complicated additions to a Registry using the syntax that
Win32::TieRegistry allows [except that I usually change the
delimiter from "\\" to "/" to make things easier. Except for the
first line of each block above, those are just Perl expressions
that get turned into a subtree of a Registry.
Enjoy,
--
Tye McQueen Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
------------------------------
Date: 16 Jul 1998 20:04:33 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Setting up Perl database
Message-Id: <6olmch$m47@mozo.cc.purdue.edu>
JLEHMANN <JLEHMANN@dsccc.com> writes:
}I'm looking to create a service where buyers and sellers can meet up.
}Sellers will submit record(s) of their goods, and buyers will search the
}database for record(s) they're interested in, and get the seller's
}email.
}I'm thinking perl is the language to do this with. In what ways could I
}set up this database that would hold thousands of entries?
}I believe:
}- A text file could be used but would not be very robust or quick
}- a DBMS must be implemented, such as Mini SQL.
}(set me straight if i'm out of line or am missing some options)
Sort of between these is something like DB_File. I asked about this a
few weeks ago, and have done some quick prototyping with using MLDBM
and DB_File, as was suggested to me.
Then all hell broke loose elsewhere so I haven't had a
chance to finish. But the effort seemed worthwhile, and I'm looking
forward to getting back to it.
See the camel for DB_File info, and CPAN for MLDBM.
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: Thu, 16 Jul 1998 21:57:36 GMT
From: Gellyfish@btinternet.com (Jonathan Stowe)
Subject: Re: Silly things to do in Perl (or: is that Laptop waterproof?)
Message-Id: <35ae4219.1477647@news.btinternet.com>
On Wed, 15 Jul 1998 14:16:55 -0400, Steve Linberg wrote :
>In article <35A5F598.985CCD6B@nortel.co.uk>, "F.Quednau"
><quednauf@nortel.co.uk> wrote:
>
>> Oh *shish*, you're all a bunch of perfectionists :)
>
>That's *sheesh*, not *shish*. :)
>
A right kebabing if I ever saw one.
/J\
Jonathan Stowe
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
------------------------------
Date: Thu, 16 Jul 1998 20:27:12 GMT
From: david2020@my-dejanews.com
Subject: Simultaneous Telnet/TCP sessions ?
Message-Id: <6olnmv$hs1$1@nnrp1.dejanews.com>
Can anybody show me a script that can generate 100s of simultaneous telnet/tcp
sessions to a host? I tried using PERL + fork(), but, it seems that it's not
working right when I do the simultaneous calls.
Thanks for the help.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Thu, 16 Jul 1998 16:53:28 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Simultaneous Telnet/TCP sessions ?
Message-Id: <linberg-1607981653280001@projdirc.literacy.upenn.edu>
In article <6olnmv$hs1$1@nnrp1.dejanews.com>, david2020@my-dejanews.com wrote:
> Can anybody show me a script that can generate 100s of simultaneous telnet/tcp
> sessions to a host? I tried using PERL + fork(), but, it seems that it's not
> working right when I do the simultaneous calls.
Gosh. This doesn't answer your question, but why on earth would you want
to do that? I hope you aren't planning to run hundreds of telnet calls to
*my* server!
_____________________________________________________________________
Steve Linberg National Center on Adult Literacy
Systems Programmer &c. University of Pennsylvania
linberg@literacy.upenn.edu http://www.literacyonline.org
------------------------------
Date: Thu, 16 Jul 1998 20:29:09 GMT
From: david2020@my-dejanews.com
Subject: Telnet Calls
Message-Id: <6olnqk$hu4$1@nnrp1.dejanews.com>
Can anybody provide me with a script that can generate hundreds of
simultaneous telnet sessions?
I tried using fork(), but it seems that it's taking a lot of resources.
thanks.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 16 Jul 1998 14:01:11 -0700
From: hirano@Xenon.Stanford.EDU (Kelly Hirano)
Subject: Re: Telnet Calls
Message-Id: <6olpmn$sh@Xenon.Stanford.EDU>
In article <6olnqk$hu4$1@nnrp1.dejanews.com>,
<david2020@my-dejanews.com> wrote:
>Can anybody provide me with a script that can generate hundreds of
>simultaneous telnet sessions?
>
>I tried using fork(), but it seems that it's taking a lot of resources.
of course it's using lots of resources. you said "hundreds of simultaneous
telnet sessions". each session is a process -- not just a process, a big perl
process.
--
Kelly William Hirano Stanford Athletics:
hirano@cs.stanford.edu http://www.gostanford.com/
hirano@alumni.stanford.org (WE) BEAT CAL (AGAIN)! 100th BIG GAME: 21-20
------------------------------
Date: 16 Jul 1998 20:00:30 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: What is awk better at than perl? (Larry quote)
Message-Id: <6olm4u$e83$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Uri Guttman
<uri@sysarch.com>],
who wrote in article <x7yattn3jj.fsf@sysarch.com>:
> JP> One thing is that in awk, the input record separator can be a
> JP> regular expression. I sure wish Perl had this.
> this wish has been discussed before. since perl's re can do so many
> powerful things, it can lead into deep re recursion that will not return
> in your lifetime. having an re as the IRS doesn't do any good then. just
> read the file in as a string and split it on the re if you want. the IRS
> is meant to be fast and simple for most cases, not powerful and slower
> for some.
Wrong. $/ will be RE-enabled some unspecified time in the future (not
in 5.005 - this is definite).
Ilya
------------------------------
Date: 16 Jul 1998 20:02:07 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: What is awk better at than perl? (Larry quote)
Message-Id: <6olm7v$egu$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Mark-Jason Dominus
<mjd@op.net>],
who wrote in article <6olhq7$rg$1@monet.op.net>:
> In article <opus-1507981940170001@dave.magibox.net>,
> Brock Sides <opus@magibox.net> wrote:
> >So what is it that awk is (or was) better at?
>
> ... | awk '{print $1}'
I do not know awk, but knowing Perl, I would try
| perl -lane 'print $F[0]'
Ilya
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3180
**************************************