[7763] in Perl-Users-Digest
Perl-Users Digest, Issue: 1388 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 29 10:09:21 1997
Date: Sat, 29 Nov 97 07:00:37 -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 Sat, 29 Nov 1997 Volume: 8 Number: 1388
Today's topics:
Re: ACK! What am I doing wrong??!! <sk@iessoft.com>
Environmental variable venkat5@hotmail.com
Re: Environmental variable (Jason Gloudon)
failed substitution , snailgem@aol.com
Re: failed substitution (Jason Gloudon)
Re: hash of hashes or hash? <dformosa@st.nepean.uws.edu.au>
Re: hash of hashes or hash? (John Moreno)
Help please !!! <thidinh@erols.com>
Re: Help please !!! (Avram Grumer)
how to hide .pl file venkat5@hotmail.com
Re: Is this database solution feasable? (Peter J. Schoenster)
Re: Newbie having RE problems. (Keith Willis)
Perl for the AS/400 <prog@wallybox.cei.net>
Re: PERL Hourly Rates (Tushar Samant)
Re: Perl Plug-In for Netscape? (Tad McClellan)
Re: perl shorter than csh challenge!! <merlyn@stonehenge.com>
Re: perl shorter than csh challenge!! (Bryan Wilkinson)
Re: perl shorter than csh challenge!! (Abigail)
posting to a newsgroup <ctt@usa.net>
Q: Learning perl with no progr. experience av3@xs4all.nl
Re: Resource Kit Anomaly (Peter J. Schoenster)
Re: sort() corrupts data when using an "illogical" func <dformosa@st.nepean.uws.edu.au>
Re: sort() corrupts data when using an "illogical" func (Abigail)
Re: truncating a string <rjk@coos.dartmouth.edu>
What 'or' before die? || vrs. or (David Hawkins)
Re: What 'or' before die? || vrs. or <rjk@coos.dartmouth.edu>
Re: Which platform ? <athena@radiks.net>
Re: Windows 95 flock problem (hapless newbie question) <benjamin.geer@worldnet.att.net>
Re: Writing to files <rjk@coos.dartmouth.edu>
Re: Writing to files (Peter J. Schoenster)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 29 Nov 1997 00:17:49 -0500
From: "Shafayat Kamal" <sk@iessoft.com>
Subject: Re: ACK! What am I doing wrong??!!
Message-Id: <65o8qc$7cr@world1.bawave.com>
Hi again!
I tried the below line and it got rid of the = or == lines but it still
doesn't completely fill one whole line, in other words it still looks like
this:
ABH545ABH545ABH545ABH545ABH545ABH545ABH545ABH545ABH545ABH
ABH545ABH545ABH545ABH545ABH545ABH545ABH545ABH545ABH545
ABH545ABH545ABH545ABH545ABH545ABH545ABH545ABH545ABH545AB
however, it does correctly insert the "==" at the end. Anyone have any
suggestions?! I'm very desperate to try anything at this point!
>while (read FILE, $str, 1024) {
> print MAIL (encode_base64 $str);
>}
Regards,
Shafayat Kamal
http://www.iessoft.com/scripts/index.shtml
------------------------------
Date: Sat, 29 Nov 1997 05:21:06 -0600
From: venkat5@hotmail.com
Subject: Environmental variable
Message-Id: <880801891.5720@dejanews.com>
Keywords: query_string,environmental variables
Hello,
I am unable to get the QUERY_STRING variable in %ENV. can anyone please
mail me the reason for this?
I am working on Perl5.001 under WindowsNT4
Regards.
venkat.
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 29 Nov 1997 14:31:51 GMT
From: jgloudon@bbn.remove.com (Jason Gloudon)
Subject: Re: Environmental variable
Message-Id: <65p90n$s0t$2@daily.bbnplanet.com>
venkat5@hotmail.com wrote:
: Hello,
: I am unable to get the QUERY_STRING variable in %ENV. can anyone please
: mail me the reason for this?
: I am working on Perl5.001 under WindowsNT4
you did say $ENV{'QUERY_STRING'}?
Jason Gloudon
------------------------------
Date: Sat, 29 Nov 1997 02:53:15 -0500
From: , snailgem@aol.com
Subject: failed substitution
Message-Id: <347FC9EA.204F@aol.com>
I have opened a file and put it in an array:
@myfile=<FILEHANDLE>;
then I do some greps on it, etc.
Now I want to modify someting in the file before I close it:
@myfile =~ s/$find_pat/$replace_pat/g;
and I get this message:
Use of uninitialized value at ./change.pl line 33, <FILEHANDLE> chunk 82
(#1)
(W) An undefined value was used as if it were already defined. It
was
interpreted as a "" or a 0, but maybe it was a mistake. To suppress
this
warning assign an initial value to your variables.
Both $find_pat and $replace_pat are defined.
This leaves @myfile as undefined. Is this because it's an array, and you
need a scalar on the left side in a substitution?
How would I go about this then?
Thanks.
------------------------------
Date: 29 Nov 1997 14:29:42 GMT
From: jgloudon@bbn.remove.com (Jason Gloudon)
Subject: Re: failed substitution
Message-Id: <65p8sm$s0t$1@daily.bbnplanet.com>
: @myfile =~ s/$find_pat/$replace_pat/g;
Yes. You can't use s/// on an array. You need to do this in a loop.
I would advise against reading the entire file into memory
if the operations you needed to perform could be done independently for each
line.
the
while(<FILE>){
}
construct has many uses.
Jason Gloudon
------------------------------
Date: 29 Nov 1997 01:24:49 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: hash of hashes or hash?
Message-Id: <880766599.347379@cabal>
In <347E74AC.348C3DF1@sonnets.dot.com> designky <designky@sonnets.dot.com> writes:
>I am writing a database program and is wondering which to use. I want to be
>able to extract stat for any year, month, day, and hour easily. Here are two of
>the models that I am thinking of using:
> model 1 : $hash{yymmdd}[hour] = hits
> or
> model 2 : $hash{yy}{mm}{dd}[hour] = hits
>Which is a better model to use?
Neather. There both year 2k noncomplient. Which style is better depeands
on the nature of your input set. If you have few few stats then the first
is better, however if you have a lot I beleave that the second would be
better.
While finding the largest one with the first system requires looping threw
all the hashes and subhashes, finding the largest of the first hash
requiers looping threw the whole hash.
--
Please excuse my spelling as I suffer from agraphia see the url in my header.
Never trust a country with more peaple then sheep. I do not reply to mungged
Support NoCeM http://www.cm.org/ addresses.
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: Fri, 28 Nov 1997 22:03:01 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: hash of hashes or hash?
Message-Id: <1d0g6zm.fyqxe5md0utdN@roxboro-180.interpath.net>
? the platypus {aka David Formosa} wrote:
> designky <designky@sonnets.dot.com> writes:
>
> >I am writing a database program and is wondering which to use. I want to
> >be able to extract stat for any year, month, day, and hour easily. Here
> >are two of the models that I am thinking of using:
> > model 1 : $hash{yymmdd}[hour] = hits
> > or
> > model 2 : $hash{yy}{mm}{dd}[hour] = hits
>
> >Which is a better model to use?
>
> Neather. There both year 2k noncomplient. Which style is better depeands
> on the nature of your input set.
And whether it is y2k compliant or not (and whether it needs to be) is
also depends upon the input set and upon the value held in yy. Unlike
something like not checking the result of a open this isn't something
that should be automatically condemned because it's not necessarily a
bad thing.
--
John Moreno
------------------------------
Date: Fri, 28 Nov 1997 23:05:31 -0500
From: "PH" <thidinh@erols.com>
Subject: Help please !!!
Message-Id: <65o4dq$2go$1@winter.news.erols.com>
I just begin to test a .pl file on my NT Workstation with PWS4.0 beta. I
always get this error message: "The specified module could not be found. "
I don't understand what is mean of this message ! I think I setup everything
correct because I can run a counter which was copied on a free site. The
test.pl is simple:
print "HTTP/1.0 200 OK\n";
print "Content-Type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Hello World</TITLE>\n";
print "</HEAD>\n";
print "<BODY>\n";
print "<H4>Hello World</H4>\n";
print "<P>\n";
print "Your IP Address is $ENV{REMOTE_ADDR}.\n";
print "<P>"; print "<H5>Have a nice day</H5>\n";
print "</BODY>\n";
print "</HTML>\n";
Thx for any help.
Dinh
------------------------------
Date: Sat, 29 Nov 1997 02:59:35 -0500
From: avram@interport.net (Avram Grumer)
Subject: Re: Help please !!!
Message-Id: <avram-2911970259350001@avram.port.net>
In article <65o4dq$2go$1@winter.news.erols.com>, "PH" <thidinh@erols.com> wrote:
> I just begin to test a .pl file on my NT Workstation with PWS4.0 beta. I
> always get this error message: "The specified module could not be found. "
Does the error message specify which line the error was found in? I just
tried running it with the "-w" switch on, and it ran, giving only the
error "Use of uninitialized value. File 'Untitled'; Line 12", line 12
being the one with "$ENV{REMOTE_ADDR}" in it. ("Untitled" was the name of
the window in which I had pasted the script; I'm running MacPerl
5.1.5r4.)
I've had trouble in the past with interpolated quotes containing <FOO>. I
think they get mistaken for filehandles.
Try replacing the double quotes with single quotes, like this:
print '<HTML>' . "\n";
Or another way:
$foo = q|
HTTP/1.0 200 OK
Content-Type: text/html
<HTML>
<HEAD>
<TITLE>Hello World</TITLE>
</HEAD>
<BODY>
<H4>Hello World</H4>
<P>
Your IP Address is ==IP_ADDRESS==.
<P>
<H5>Have a nice day</H5>
</BODY>
</HTML>
|;
$foo =~ s/==IP_ADDRESS==/$ENV{REMOTE_ADDR}/;
print $foo;
> print "HTTP/1.0 200 OK\n";
> print "Content-Type: text/html\n\n";
> print "<HTML>\n";
> print "<HEAD>\n";
> print "<TITLE>Hello World</TITLE>\n";
> print "</HEAD>\n";
> print "<BODY>\n";
> print "<H4>Hello World</H4>\n";
> print "<P>\n";
> print "Your IP Address is $ENV{REMOTE_ADDR}.\n";
> print "<P>"; print "<H5>Have a nice day</H5>\n";
> print "</BODY>\n";
> print "</HTML>\n";
--
Avram Grumer avram@interport.net
http://www.users.interport.net/~avram/
Give a man a fish, and you feed him for a day.
Teach him how to fish, and you can sell him equipment.
------------------------------
Date: Sat, 29 Nov 1997 00:34:24 -0600
From: venkat5@hotmail.com
Subject: how to hide .pl file
Message-Id: <880784036.29684@dejanews.com>
Keywords: hide,.pl
I want to hide the .pl program from being read from others. Is there any
way to do it? I am using Perl 5 under WindowsNT 4.0 Please reply me at
venkat5@hotmail.com Regards. venkat.
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Sat, 29 Nov 1997 13:30:22 GMT
From: pschon@baste.magibox.net (Peter J. Schoenster)
Subject: Re: Is this database solution feasable?
Message-Id: <3480176e.47982565@news.magibox.net>
ii@fairhope.com (Tom) wrote:
>I have a datafile of comma delimited fields. The data file stucture
>John Doe:123 First Lane:(222)222-3333:\n
>Lisa Smith:321 Street:(111)111-1111\n
>It all works fine right now with currently about 10 fields for each
>person. However, I now need to expand this to about 250 fields. Which
>is the most efficient way to read and write to such datafile when the
>size of each record is this large?
>
>I current use this simple method:
>
>while ($rec = <FILE>)
>{
> ($name:$street: ....) = split(/:/,$rec);
As per the other reply there is no limit; I have not run into one.
You are talking about searching for flat files. I have used
agrep(yes, there is an agrep) to search and then I analyze those
results. I would be that your method is just as fast but I don't
know.
I have long used text files and Berkley dbms. I have just started to
use mSQL 2.0. It's better. I highly suggest you look into using some
rdbms. Many web hosting companies offer mSQL as part of their package
(iserver.com does).
There is 'seek' but I have never really used it. This cgi script
might interest you (it was one of the first I saw about flat file
"databases"):
http://www.rede.com/sign/kuoi-search.html
"The file being searched is over 31,000 lines and more than 1.2
Megabytes. Each line is a record, and the fields are separated by
tabs. "
It is not mine as you will see when you get to that page.
You might also want to see what John Donohue has done with some Java
and flat file "databases":
http://www.panix.com/~wizjd/java/index.html
Peter
------------------------------
Date: Fri, 28 Nov 1997 11:28:52 GMT
From: keith_willis.junk@non-hp-unitedkingdom-om1.om.hp.com (Keith Willis)
Subject: Re: Newbie having RE problems.
Message-Id: <347ea83f.162091835@elf.bri.hp.com>
On Mon, 24 Nov 1997 15:56:49 +0800, Robin Marshall
<robin@highway1.com.au> wrote:
> I was wondering if anyone could help me with a problem I am having. I
>have a gargantuan data file which is a comma-delimited database of
First off, why the devil is it a comma-sep file when it should be in a
true database? :-)
>intersections and road crashes. Unfortunately some of the rows use ST
>for street, while others use STR and so on, hence creating a number of
>unique names for a single street. What I want to do is extract this word
>from a string in the form:
>
>"ALBANY HIGHWAY "
>"ALBANY HWY "
>"NORTH ALBANY HIGHWAY "
I was involved in a data migration exercise at a previous contract
where company names and addresses were coming across from a legacy
system. We were able to cleanse the addresses by using a Post Office
supplied Post-Code package. This either turned a postcode into a
normalised address or took an address in one of a number of arbitrary
forms, postcoded it, and returned the address in a normalised form.
You may find that there is something similar available in au, although
I realise that you are talking about thoroughfares rather than
properties.
More useful to you perhaps is the cleansing that we undertook on the
company names. We built a relatively small database table of common
words used in company names together with a standard form of that word
like LIMITED => LTD, COMPANY => CO, CO. => CO, and so on. Each word
in each incoming name was looked up in the list of words, and if found
the corresponding standard form was substituted.
Ob. perl: Parsing the words from your input, looking them up in a dbm
tied hash, and substituting the required standard form would be a
doddle in perl :-)
----------------------------------------------------------------------
The above message reflects my own views, not those of Hewlett Packard.
When emailing me, please note that there is no '.junk' in my address.
------------------------------
Date: Fri, 28 Nov 1997 12:20:24 -0800
From: Tim <prog@wallybox.cei.net>
Subject: Perl for the AS/400
Message-Id: <347F2788.5E00@wallybox.cei.net>
Has anyone installed Perl on their AS/400. I've downloaded all the
files at CPAN and restored them to the 400, but I can't compile any of
it. We're using C/400 and OS/400 v3r2. Is it possible to use Perl with
this combination.
When I try to compile CRTPERLMOD I get the errors referred to in the
documentation regarding "spawn" and "wait". I've seached the QCLE and
there are no such animals. Does this mean that there is no hope for me?
Any help and/or assistance would be greatly appreciated.
------------------------------
Date: 28 Nov 1997 23:47:54 -0600
From: scribble@shoga.wwa.com (Tushar Samant)
Subject: Re: PERL Hourly Rates
Message-Id: <65oaaa$1v8@shoga.wwa.com>
fl_aggie@thepentagon.com writes:
>In article <65kqbt$pb6@shoga.wwa.com>, scribble@shoga.wwa.com (Tushar
>Samant) wrote:
>
>+ fearless@io.com writes:
>+ >I think about the old FORTRAN code I used to write. I took one programming
>+ >class the first time through college -- Introductory FORTRAN, I believe it
>+ >was called -- and got a D+. Of course, there WAS this girl . . .
>+
>+ That's the difference between Fortran and Perl I think -- I got *better*
>+ at Perl because of the girl.
>
>Hey, you guys quit bashing fortran, willya? Good fortran, like good perl,
>requires a lot of programmer discipline...
I would be the first to give Fortran the same chance as Perl. But the
girl is unavailable.
------------------------------
Date: Fri, 28 Nov 1997 20:14:38 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl Plug-In for Netscape?
Message-Id: <eqtn56.ib3.ln@localhost>
Eric Hilding (eric@hilding.com) wrote:
: I've looked around but just can't seem to find the
: info on an alleged Perl 'Plug-In' for Netscape. Any
: references would be appreciated. Tnx.
Where did you hear the allegations?
I've not heard of such a thing.
What do you want to do that you need a plugin for?
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 28 Nov 1997 20:54:19 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: i0l1@ugrad.cs.ubc.ca (William Wei Liong Young)
Subject: Re: perl shorter than csh challenge!!
Message-Id: <8cyb289wyc.fsf@gadget.cscaper.com>
>>>>> "William" == William Wei Liong Young <i0l1@ugrad.cs.ubc.ca> writes:
William> set str = `grep c filename`
William> set cvalue = $str[ 3 ]
William> Can anyone do the same in perl using only 2 lines (and that includes opening
William> any filehandles)?
No. Don't even challenge me like that. Too easy.
@ARGV = qw(filename) and ($cvalue) = map /c = (\d+)/, <>;
King of the one liners! Undefeated again!
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 276 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Sat, 29 Nov 1997 01:32:55 GMT
From: nardo@pobox.com (Bryan Wilkinson)
Subject: Re: perl shorter than csh challenge!!
Message-Id: <34806f1c.6349850@news.supernews.com>
here it is, in two lines of perl
open(FILE, $file_name);
eval('$'.(grep(/^c/, <FILE>))[0]);
and with backticks it can be done in one line:
eval('$'.(grep(/^c/, `cat $file_name`))[0]);
>my limited yet growing experience in perl has shown me that pretty
>much anything done in a csh shell script can be done in fewer or the
>same lines of code in a perl script ( fewer lines...not speed, efficiency,
>blah, blah). but i think i have come across two lines of csh code which
>I can't seem to write in 2 lines of perl code (using currently 'built-in'
>perl, not extra modules).
>
>Here is situation:
>
>We have a text file with arbitrary number of lines:
>
>a = 1
>b = 2
>c = 3
>d = 4
>.
>.
>.
>
>In a csh script, to get the value of c (assuming all the values on the left
>side of the equal sign are unique):
>
>set str = `grep c filename`
>set cvalue = $str[ 3 ]
>
>Can anyone do the same in perl using only 2 lines (and that includes opening
>any filehandles)?
>
>just thought I would throw this quite unimportant, rather insignificant
>question to the group. obviously, using back ticks in your perl code
>doesn't count :), and the more confusing the two lines the better ;)
------------------------------
Date: 29 Nov 1997 11:12:51 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: perl shorter than csh challenge!!
Message-Id: <slrn67vu91.gha.abigail@betelgeuse.wayne.fnx.com>
Bryan Wilkinson (nardo@pobox.com) wrote on 1551 September 1993 in
<URL: news:34806f1c.6349850@news.supernews.com>:
++
++ here it is, in two lines of perl
++
++ open(FILE, $file_name);
++ eval('$'.(grep(/^c/, <FILE>))[0]);
++
++ and with backticks it can be done in one line:
++
++ eval('$'.(grep(/^c/, `cat $file_name`))[0]);
One line, no backticks, no eval:
perl -wane '$cvalue = $F [2] if $F [0] eq "c"' filename
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Sat, 29 Nov 1997 20:17:03 -0500
From: Chu Tsz-Tat <ctt@usa.net>
Subject: posting to a newsgroup
Message-Id: <3480BE8F.76A4@usa.net>
anybody know how to post message to a newsgroup using perl scripts?
i'm quite new to perl, so i dont know how to do?
can itbe done by 'sendmail'?
thanks
------------------------------
Date: Sat, 29 Nov 1997 12:31:24 +0100
From: av3@xs4all.nl
Subject: Q: Learning perl with no progr. experience
Message-Id: <347FFD0C.42B2@xs4all.nl>
Hi,
i wanna start learning perl. The thing is: i have no programming
experience whatsoever (yeah, writing print "" statements). I'm looking
for a place on the web to start, and if non excistent, a book.
Thank you.
Arjen van Drie.
------------------------------
Date: Sat, 29 Nov 1997 13:34:16 GMT
From: pschon@baste.magibox.net (Peter J. Schoenster)
Subject: Re: Resource Kit Anomaly
Message-Id: <34801903.48387327@news.magibox.net>
Phil Houstoun <pjhousto@cse.dnd.ca> wrote:
>Hi there,
> Has anybody else who has received the Resource Kit found that HTML
>indexes of files contained in the CPAN archive on the CD are a tad
>messed up? I've got URLs in the index.html files that point to the
>basenames of compressed (.Z) files, so when you try to follow the
>links you get the 'File Not Found' message, e.g. the first URL in
>/CPAN/scripts/admin/index.html points to adduser, which doesn't exist,
>but adduser.Z does. In addition, my /CPAN/CPAN.html is a link (ln -s,
>that is) to a compressed file which, of course, loads the browser with
>gibberish. Thanks.
Is this resource kit worth buying? I saw it for $112.00 at some
discount computer store online.
Why do they not tell us what is in the book(s)? I wonder if O'Reilly
has the source code on their website? It seems that O'Reilly is
putting less and less of their books on the web. I bet someone thinks
that "hey, we are giving this stuff away when we should be charging".
I've got at least 10 of their books. Ijust got an offer in the mail
that if I buy 10 books... come one who are they kidding? I will not
buy 10 O'Reilly books in the next year, no way! I think that they
have some new marketing people and I don't like what i feel.
But I would love to hear what modules etc. are discussed in the book
and what is this thing about the Java/Perl that Larry Wall wrote.
Thanks.
Peter
------------------------------
Date: 29 Nov 1997 01:47:41 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: sort() corrupts data when using an "illogical" function to sort.
Message-Id: <880767971.255635@cabal>
In <65nf7k$mik@shoga.wwa.com> scribble@shoga.wwa.com (Tushar Samant) writes:
>I guess nobody is guaranteeing anything when the comparison is
>"illogical". But I was wondering -- if the sort is exactly like
>we see quicksort described in textbooks, what could possibly go
>wrong?
It isn't. What is called when the qsort is called is something that that
sorts what is given, often its not a quick sort, it could be a merge sort
or a heap sort or any other sort the peaple would implement.
--
Please excuse my spelling as I suffer from agraphia see the url in my header.
Never trust a country with more peaple then sheep. I do not reply to mungged
Support NoCeM http://www.cm.org/ addresses.
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: 29 Nov 1997 02:31:00 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: sort() corrupts data when using an "illogical" function to sort.
Message-Id: <slrn67uvmi.gha.abigail@betelgeuse.wayne.fnx.com>
Tushar Samant (scribble@shoga.wwa.com) wrote on 1550 September 1993 in
<URL: news:65nf7k$mik@shoga.wwa.com>:
++ I guess nobody is guaranteeing anything when the comparison is
++ "illogical". But I was wondering -- if the sort is exactly like
++ we see quicksort described in textbooks, what could possibly go
++ wrong? You are only swapping elements, you can't get into an
The C library qsort() requires that the compare function you give
is consistent. It's behaviour is undefined if you don't. That is:
comp (a, b) == comp (a, b) and
comp (a, b) == - comp (b, a) and
comp (a, b) == comp (b, c) => comp (a, b) == comp (a, c)
That means that if 2 < 3 and 3 < 4, then you better have 2 < 3,
3 > 2 and 2 < 4 all the time.
If you want to shuffle your array, there's an algorithm in the
FAQ. And Knuth's TAoCP has one too.
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Sat, 29 Nov 1997 00:30:07 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: truncating a string
Message-Id: <347FA85F.4D81@coos.dartmouth.edu>
> $string = substr($string,0,10);
The above code is safer than my suggestion,
substr($string, 10) = '';
which causes an error if the string is shorter than 10 characters.
Chipmunk
------------------------------
Date: 28 Nov 1997 18:17:38 -0800
From: dhawk@best.com (David Hawkins)
Subject: What 'or' before die? || vrs. or
Message-Id: <65nu02$gb5$1@shell3.ba.best.com>
Picked up 'Learning Perl', 2nd edition and noticed that when files are
opened the form is open(XXX,"filename") || die "file not found";
[from memory, don't have it in front of me.] instead of
open(YYY,"filename") or die "file not found";
I thought the later form "or" was now preferable because of
a presidence problem?
later, david
--
David Hawkins dhawk@best.com http://www.river.org/~dhawk
"The bicycle is just as good company as most husbands and, when
it gets old and shabby, a woman can dispose of it and get a new
one without shocking the entire community."
-- Ann Strong, Minneapolis Tribune, 1895
------------------------------
Date: Sat, 29 Nov 1997 01:56:23 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: What 'or' before die? || vrs. or
Message-Id: <347FBC95.5B68@coos.dartmouth.edu>
David Hawkins wrote:
>
> Picked up 'Learning Perl', 2nd edition and noticed that when files are
> opened the form is open(XXX,"filename") || die "file not found";
> [from memory, don't have it in front of me.] instead of
> open(YYY,"filename") or die "file not found";
>
> I thought the later form "or" was now preferable because of
> a presidence problem?
The precedence problem only exists when you don't include the
parentheses:
open XXX, "filename" || die "file not found";
is equivalent to:
open XXX, ("filename" || die "file not found");
On the other hand:
open XXX, "filename" or die "file not found";
is equivalent to:
open(XXX, "filename") or die "file not found";
Whether you use || or 'or' is up to you. Just be sure to include the
parentheses if you use ||.
Chipmunk
------------------------------
Date: Sat, 29 Nov 1997 01:08:25 -0600
From: "Cesar A. Marrero" <athena@radiks.net>
To: emehenk@rioja.ericsson.se_nojunk_
Subject: Re: Which platform ?
Message-Id: <347FBF69.C787325C@radiks.net>
According to "Programming Perl, 2nd Edition", the contents
of the platform can be found in $^O (see page 403):
print " --- $^O ---\n";
or, (in my opinion, much more readable):
use English;
print " --- $OSNAME ---\n";
My home PC prints out " --- MSWin32 ---" ...
I haven't tried this on my Ultra SPARC at work ... enjoy.
-------
Cesar A. Marrero, President
ATHENA Enterprises
athena@radiks.net
-------
Henrik Soderstrom wrote:
> Hi,
> I am writing a few little things in perl that I want to use
> both under W95 and unix (linux and solaris).
>
> Can anyone recommend a way to detect, from within a
> perl program, which platform it's running on.
>
> TIA /Henrik
------------------------------
Date: Fri, 28 Nov 1997 21:02:09 -0500
From: "Benjamin Geer" <benjamin.geer@worldnet.att.net>
Subject: Re: Windows 95 flock problem (hapless newbie question)
Message-Id: <65nso9$kss@mtinsc02.worldnet.att.net>
Martien Verbruggen wrote in message <65l5t7$pi$2@comdyn.comdyn.com.au>...
>In article <65hllc$r83@mtinsc02.worldnet.att.net>,
> "Benjamin Geer" <benjamin.geer@worldnet.att.net> writes:
>> I'm really stumped. The program is so small that I'm attaching it.
>
>> begin 666 message3.pl
>> M(R!M97-S86=E,RYP; T*(R!B>2!"96YJ86UI;B!'965R#0HC(#(U+4YO=BTY
>
>Please don't 'attach' it. Just include it in your message body. Most
>people don't want to have to decode what you post just to be able to
>read it.
Here's a repost with the code included in the message body:
Using code lifted from "Learning Perl for Win32", I'm writing a little CGI
script, under Windows 95, that takes form input and appends it to a file.
The program runs fine, as long as this line is commented out :
flock(MESSAGES, $LOCK_EX) || die("Can't flock $filename : $!");
Otherwise, the program seems to hang there, and the browser gets an
incomplete page. Perhaps flock is never getting the lock on the file? This
happens even with a freshly created file.
I'm using ActiveState's Perl 5.003 Build 312 and Microsoft's Personal Web
Server.
Here's the program:
use strict;
use CGI qw(:standard);
use Fcntl qw(O_RDWR O_CREAT);
my(
$filename,
$message,
$LOCK_EX,
);
$LOCK_EX = 2;
$filename = "messages.txt";
print header, start_html("Save a message");
if (param()) { # form has already been filled out
my $message = param("message");
sysopen(MESSAGES, $filename, O_RDWR|O_CREAT, 0666) || die("Can't open
$filename : $!");
flock(MESSAGES, $LOCK_EX) || die("Can't flock $filename : $!");
seek(MESSAGES, 0, 2) || die("seek failed on $filename : $!");
print MESSAGES ("$message\n");
close(MESSAGES) || die("Can't close $filename: $!");
print p("Your message has been saved.");
print end_html;
} else {
print start_multipart_form();
print p("Message:");
print p(textarea("message", "", 10, 50));
print p(submit("Save"), reset("Reset"));
print end_form, end_html;
}
Benjamin Geer
benjamin.geer@worldnet.att.net
------------------------------
Date: Sat, 29 Nov 1997 02:11:42 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Writing to files
Message-Id: <347FC02C.63CB@coos.dartmouth.edu>
paul@pkamf.demon.co.uk wrote:
>
> Hi Guru's
>
> I want to open a file, search for two 'markers' then insert text - a
> variable - between the two. Do I open the file so:
>
> open(FILE,+<filename); ?
You need quotes, and you should always check the return value of open:
open(FILE, '+<filename') or
die "Unable to open filename: $!";
> or will this zap everything in the file?
It will open the file for reading and writing, with the current contents
intact.
> Will
>
> $_ =~ /"marker"/ work... then {print $var;}
>
> or someting similar work or am I missing something?
The quotes are unnecessary, unless you are actually trying to match
quotes there in the string.
Unfortunately, opening the file for random access (with '+<') will not
work for what you want to do, because you are changing the number of
bytes in the file.
I would suggest doing something like this:
perl -pie 's/(marker1)(marker2)/$1$var$2/g;'
> (Apart from locating the end of the marker ie the other string to mark
> the boundary fot text insertion.)
Are the two markers next to each other, or could there be other text in
between? If there is other text in between, what do you want to do with
it?
Chipmunk
------------------------------
Date: Sat, 29 Nov 1997 13:39:01 GMT
From: pschon@baste.magibox.net (Peter J. Schoenster)
Subject: Re: Writing to files
Message-Id: <34801a51.48721067@news.magibox.net>
paul@pkamf.demon.co.uk wrote:
>Hi Guru's
>
>I want to open a file, search for two 'markers' then insert text - a
>variable - between the two. Do I open the file so:
>
>open(FILE,+<filename); ?
>
>or will this zap everything in the file?
>
>Will
>
>$_ =~ /"marker"/ work... then {print $var;}
I have done a lot of this. You use html comments <!--hello bob--> as
you're markers. I create data files to hold the variables. The html
designer can change any data outside of the commnents.
I've got some examples here:
http://www.rede.com/samples/index.html
I use data files to contain the variables for updates and what not.
When you change a variable in the page then the page is rewritten to
reflect the change as opposed to using a wasteful ssi to call the
datafile every time.
Peter
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 1388
**************************************