[8690] in Perl-Users-Digest
Perl-Users Digest, Issue: 2307 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 13 10:07:35 1998
Date: Mon, 13 Apr 98 07:00:32 -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 Mon, 13 Apr 1998 Volume: 8 Number: 2307
Today's topics:
[Q] find largest value in key of associative array? <schan_ca@rocketmail.com>
Re: [Q] find largest value in key of associative array? <jdf@pobox.com>
Re: [Q] find largest value in key of associative array? <ludlow@us.ibm.com>
Re: [Q] find largest value in key of associative array? <ludlow@us.ibm.com>
Re: [Q] find largest value in key of associative array? (Abigail)
Re: Bill Gates should be invited to O'Reilly's "Free So <jdporter@min.net>
Re: Bill Gates should be invited to O'Reilly's "Free So (Chris Nandor)
Re: Can't locate Net/SMTP.pm (Chris Nandor)
How to lock SDBM_File, GDBM_File or NDBM_File similiar <tneohcb@pc.jaring.my>
Re: If "=~" means match what is doesn't match? <samiss@cc.tut.fi>
Re: IMAGEPUSH problems with MSIE <jhi@alpha.hut.fi>
Re: IMAGEPUSH problems with MSIE <grinch@whoville.com>
Re: Info Regarding Perl 5.005 <marko@lexis-nexis.com>
Re: keys in hashs (Mark-Jason Dominus)
Re: MacPerl Book Online in HTML <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
Re: MacPerl standalone apps (Chris Nandor)
Need a Free Perl Data Base to the Web <smile_@cindy.fe.up.pt>
Re: perl and CGI <gary@ashton-jones.com.au>
Re: Perl Compiler for NT <dformosa@st.nepean.uws.edu.au>
Purging files to a NO. of lines? nathan@cyberservices.com
Re: Question concerning reg exp's in a while statement (Louie)
Re: sendmail substitute for Macperl using "use Net::SMT (Chris Nandor)
Re: Sorting problem <gary@ashton-jones.com.au>
Re: unique string/integer from string variable? md5? <jdporter@min.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 13 Apr 1998 11:03:40 GMT
From: "Stephen_Chan" <schan_ca@rocketmail.com>
Subject: [Q] find largest value in key of associative array?
Message-Id: <01bd66cb$a9542460$1ff8aecc@direct.ca.direct.ca>
What's the fastest way to find the largest key value
in an associative array? eg:
%aa
key value
---- ------
1 some_content_1
23 some_content_1
5 some_content_1
48 some_content_1
. .
. .
N some_content_N
In the above list, assume there's 10000 pairs and the
4634th key/value pair holds the largest key value of
34235. Do I have to manually iterate through to find it?
Thanks
Stephen
------------------------------
Date: 13 Apr 1998 09:02:28 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: [Q] find largest value in key of associative array?
Message-Id: <vhsdkeff.fsf@mailhost.panix.com>
"Stephen_Chan" <schan_ca@rocketmail.com> writes:
> What's the fastest way to find the largest key value
> in an associative array?
I'd guess that the best way is to keep track of the current max key
while you're constructing the hash in the first place. If this isn't
possible, then
$max = 0; #or whatever is a small number in your application
foreach (keys %thehash) { $_ > $max and $max = $_ };
should give the max key. If it were useful to have all of the keys
sorted, you might
($min,$max) = (@sorted_keys = sort {$a <=> $b} keys %thehash)[0,-1];
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Mon, 13 Apr 1998 08:11:28 -0500
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: [Q] find largest value in key of associative array?
Message-Id: <35320F00.E7CEC9F7@us.ibm.com>
Stephen_Chan wrote:
>
> What's the fastest way to find the largest key value
> in an associative array? eg:
>
> %aa
>
> key value
> ---- ------
> 1 some_content_1
> 23 some_content_1
> 5 some_content_1
> 48 some_content_1
> . .
> . .
> N some_content_N
>
> In the above list, assume there's 10000 pairs and the
> 4634th key/value pair holds the largest key value of
> 34235. Do I have to manually iterate through to find it?
Alphabetically:
$largest_key = (sort keys %hash)[-1];
Numerically:
$largest_key = (sort {$a <=> $b} %hash)[-1];
Items to look up in the docs/faq:
sort
slice
hash
keys
cmp vs <=>
--
James Ludlow (ludlow@us.ibm.com)
This isn't tech support, and all opinions are my own.
------------------------------
Date: Mon, 13 Apr 1998 08:18:02 -0500
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: [Q] find largest value in key of associative array?
Message-Id: <3532108A.98169CAD@us.ibm.com>
James Ludlow wrote:
>
> Stephen_Chan wrote:
> >
> > What's the fastest way to find the largest key value
> > in an associative array? eg:
> >
> > %aa
> >
> > key value
> > ---- ------
> > 1 some_content_1
> > 23 some_content_1
> > 5 some_content_1
> > 48 some_content_1
> > . .
> > . .
> > N some_content_N
> >
> > In the above list, assume there's 10000 pairs and the
> > 4634th key/value pair holds the largest key value of
> > 34235. Do I have to manually iterate through to find it?
>
> Alphabetically:
> $largest_key = (sort keys %hash)[-1];
>
> Numerically:
> $largest_key = (sort {$a <=> $b} %hash)[-1];
Of course, I meant $largest_key = (sort {$a <=> $b} keys %hash)[-1];
^^^^
If only the spell checker could have caught that. ;)
Sorry.
I suppose I should also point out that the [-1] is a "dash one" and not
"dash lowercase L". Just to avoid any possible confusion.
--
James Ludlow (ludlow@us.ibm.com)
This isn't tech support, and all opinions are my own.
------------------------------
Date: 13 Apr 1998 13:54:32 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: [Q] find largest value in key of associative array?
Message-Id: <6gt5eo$jjh$1@client2.news.psi.net>
Stephen_Chan (schan_ca@rocketmail.com) wrote on MDCLXXXVI September
MCMXCIII in <URL: news:01bd66cb$a9542460$1ff8aecc@direct.ca.direct.ca>:
++ What's the fastest way to find the largest key value
++ in an associative array? eg:
++
++ %aa
++
++ key value
++ ---- ------
++ 1 some_content_1
++ 23 some_content_1
++ 5 some_content_1
++ 48 some_content_1
++ . .
++ . .
++ N some_content_N
++
++ In the above list, assume there's 10000 pairs and the
++ 4634th key/value pair holds the largest key value of
++ 34235. Do I have to manually iterate through to find it?
Uhm, in general, yes.
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Mon, 13 Apr 1998 12:26:30 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Bill Gates should be invited to O'Reilly's "Free Software Summit" (was Re: RMS should be invited to O'Reilly's "Free Software Summit")
Message-Id: <353205DB.63E0@min.net>
Pat Luther wrote:
>
> 1. That camel was NOT public domain before. It did not EXIST before. It
> was created by Edie Freedman specifically for the book.
> 2. It was adapted from a 19th century engraving, which is STILL non-
> proprietary (to quote the Tuscany Trading Company, which publishes
> books with images from the Dover Pictorial Archive that these were
> taken from "You may use the designs and illustrations from
> these books for graphics and craft applications free and without
> special permission."
>
> Sources: The colophon in the back of both O'Reilly perl books, and the
> Tuscany Trading Company web site: http://tuscanytrading.com/books/dover1.htm
The colophon states that Edie Freedman designed the *cover* of the book,
and that Edie *used* an old engraving of a camel. To me that says this
camel did in fact exist before. And that therefore this camel is still
public domain.
I think it's probably more accurate to say (as Chris did) that the use
of
a camel image to represent Perl would be a violation of trademark.
John Porter
------------------------------
Date: Mon, 13 Apr 1998 12:57:30 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Bill Gates should be invited to O'Reilly's "Free Software Summit" (was Re: RMS should be invited to O'Reilly's "Free Software Summit")
Message-Id: <pudge-1304980857200001@dynamic283.ply.adelphia.net>
In article <3531c2cc.0@news.uni-ulm.de>, borchert@mathematik.uni-ulm.de wrote:
# On 11 Apr 1998 03:16:12 -0700, Russ Allbery <rra@stanford.edu> wrote:
# > In comp.lang.perl.misc, Ben Bullock <ben@hayamasa.demon.co.uk> writes:
# > > I should say that the perl FAQ does not meet several free software
# > > criteria.
# >
# > Starting with the really major problem that it's not software....
#
# Documentation is an essential part of software.
So is distribution, so is a name, so is an idea, so are lots of things
that are not (necessarily :) themselves software.
--
Chris Nandor mailto:pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10 1FF7 7F13 8180 B6B6'])
#== New Book: MacPerl: Power and Ease ==#
#== Publishing Date: Early 1998. http://www.ptf.com/macperl/ ==#
------------------------------
Date: Mon, 13 Apr 1998 12:38:52 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: Can't locate Net/SMTP.pm
Message-Id: <pudge-1304980838420001@dynamic283.ply.adelphia.net>
In article <32FD5AF8.271A@callisto.si.usherb.ca>,
eslcafe@callisto.si.usherb.ca wrote:
# my Unix server kicks back this message (below) when I run the debug
# (perl -c xyz.pl) in telnet. I checked the latest download of perl (unix)
# - it's not there! Now what?! Is there another add-on download.
#
# ____________________________________________________
# Can't locate Net/SMTP.pm in @INC (@INC contains:
# /usr/local/lib/perl5/aix/5.0040
# 4 /usr/local/lib/perl5 /usr/local/lib/perl5/site_perl/aix
# /usr/local/lib/perl5/s
# ite_perl /usr/local/lib/perl5/aix .)
# ____________________________________________________
#
# Please answer by e-mail if you have a SOLUTION.
You need to install it. MacPerl just happens to include libnet. Try
using the CPAN module:
perl -MCPAN -e shell
CPAN> install Bundle::libnet
Or go to your favorite CPAN archive and download it and install it. If
you have no favorite, try:
http://www.perl.com/CPAN/modules/by-module/Bundle/
Hope this helps,
--
Chris Nandor mailto:pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10 1FF7 7F13 8180 B6B6'])
#== New Book: MacPerl: Power and Ease ==#
#== Publishing Date: Early 1998. http://www.ptf.com/macperl/ ==#
------------------------------
Date: Mon, 13 Apr 1998 20:34:50 +0800
From: Simon Tneoh Chee-Boon <tneohcb@pc.jaring.my>
Subject: How to lock SDBM_File, GDBM_File or NDBM_File similiar to tying of DB_File?
Message-Id: <3532066A.357C@pc.jaring.my>
Hello,
I saw an example of locking DB_File database by using tie() and
flock() in Programming Perl edition 2, when I want to try this on
SDBM_File, GDBM_File or NDBM_File, I found that they don't have
$obj->fd method, so I failed to use flock(FILEHANDLE, OPERATION)
to lock the database. I look at the manual for these databases,
but can't find anything about their available methods. I wonder
how can I get the filehandle when tying these databases, so that
I can lock it? Or they already handle the file locking themselves?
Thanks.
--
Simon Tneoh Chee-Boon
Application Developer Hitechniaga Sdn. Bhd.
tneohcb@pc.jaring.my 60-3-9660966
http://www.tneoh.zoneit.com/simon/
------------------------------
Date: 13 Apr 1998 11:57:47 +0300
From: Sami Sandqvist <samiss@cc.tut.fi>
Subject: Re: If "=~" means match what is doesn't match?
Message-Id: <m3hg3yqet0.fsf@ehdo.ton.tut.fi>
Ronald J Kimball <rjk@coos.dartmouth.edu> writes:
> Be sure to note what else the documentation has to say about this:
>
> (If the right argument is an expression rather than a
> search pattern, substitution, or translation, it is interpreted as a
> search pattern at run time. **This is less efficient than an explicit
> search, since the pattern must be compiled every time the expression is
> evaluated--unless you've used /o.**) [my emph]
>
> You're right, it's not an error, but it is inefficient.
Yes, I read that part of the documentation. I also had it copied in my
reply but decided to save "bandwidth" and just give a reference to the
docs. The person asking the question needs to read them anyway and
will then know about the performance issue. If someone is not willing
to read the docs, his code is not going to be very efficient anyway.
Now that I read it again, the emphasised part seems strange. How am I
supposed to use /o with an expression like "Phone:"? Just curious.
Sami
--
#!/bin/perl -w
$_="17601114363329121422010036040100073622335669010008"; $a=q #Magic?#;
grep/Perl!/,sort("J".."h");print"Sami Sandqvist - samiss@cc.tut.fi";s/k/u/g;
@b=split//,$a; s/(\d\d)/$b[$1]/eg;print"$_\n";
------------------------------
Date: 13 Apr 1998 16:04:10 +0300
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: IMAGEPUSH problems with MSIE
Message-Id: <oeewwctzxdh.fsf@alpha.hut.fi>
rsudduth@comweb.net writes:
> Does anyone know the correct headers to output to the
> MSIE family browsers to allow imagepush via a perl script.
> We have Netscape 3.0 and Netscape 4.0 family browser running
> fine but IE is another story.
What does your question have to with Perl? If your CGI were in COBOL
you would ask in a COBOL newsgroup? Here Perl is just a tool.
A tool. You do not ask in a hammer newsgroup how to build a doghouse,
you go to the doghouse newsgroup. Therefore and thusly, please ask in
the comp.infosystems.www.authoring.cgi, or possibly to an even more
fitting newsgroup, comp.infosystems.www.{browsers,servers}.ms-windows.
--
$jhi++; # http://www.iki.fi/~jhi/
# There is this special biologist word we use for 'stable'.
# It is 'dead'. -- Jack Cohen
------------------------------
Date: Mon, 13 Apr 1998 09:39:59 -0400
From: "Grinch" <grinch@whoville.com>
Subject: Re: IMAGEPUSH problems with MSIE
Message-Id: <6gt3qj$2t4@fridge.shore.net>
rsudduth@comweb.net wrote in message <6gs4mj$fdr$1@nnrp1.dejanews.com>...
>Does anyone know the correct headers to output to the
>MSIE family browsers to allow imagepush via a perl script.
Well, this doesn't really answer your question, exactly, but it may help.
Have you tried using the "CGI::Push" module from CPAN? I haven't used it
myself, but I assume it would be easier than trying to roll your own.
You can find CPAN stuff at <URL: http://www.perl.com >
HTH!
-grinch
----
"Of course coffee doesn't make the world go around. It
just makes it go faster." - me
Sherm Pendley
grinch@whoville.com
http://www.whoville.com
------------------------------
Date: 13 Apr 1998 09:55:40 -0400
From: Mark Osbourne <marko@lexis-nexis.com>
Subject: Re: Info Regarding Perl 5.005
Message-Id: <vpesonhltb7.fsf@lexis-nexis.com>
Randal Schwartz <merlyn@stonehenge.com> writes:
> And you should *definitly* upgrade to 5.005 when it comes out. Turns
> out there's a CERT-ifiable security bug in all versions of 5.004, so
> 5.005 is now the only Perl that is known-security-bug-free.
Could someone post the relevant URL to the CERT advisory or bulletin?
I took a look at the CERT site and couldn't find any reported
vulnerability for Perl 5.004. Last one I could find dealt with sperl
or suidperl in 5.003.
If/when this problem is reported, it will probably give me all the
ammunition I need to get our systems upgraded to the latest version of
Perl.
Thanks in advance.
--
-- Mark Osbourne O-
-- marko@lexis-nexis.com
------------------------------
Date: 13 Apr 1998 09:55:27 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: keys in hashs
Message-Id: <6gt5gf$jdr$1@monet.op.net>
In article <35319260.524144494f47414741@radiogaga.harz.de>,
Martin Vorlaender <MARTIN@RADIOGAGA.HARZ.DE> wrote:
>Ambiguous use of {shift} resolved to {"shift"} at bareword.pl line 4.
As mentioned elsewhere in this thread, that's a bug.
------------------------------
Date: Mon, 13 Apr 1998 06:22:01 -0700
From: "Creede Lambard" <$_=qq!fearless\@NOSPAMio.com!;y/A-Z//d;print>
Subject: Re: MacPerl Book Online in HTML
Message-Id: <6gt3hg$qfi@bgtnsc03.worldnet.att.net>
lvirden@cas.org wrote in message <6gr6bp$aou$1@srv38s4u.cas.org>...
> I myself enjoy reading books which present complete code examples,
rather
> than code fragments, particularly if the code does something useful
for
> me.
I can't agree more. Seeing a command or function in a program is like
seeing a word in context. I still keep a copy of Learning Perl 1st ed.
at my desk. It contains some very useful code examples (especially for
one who has not yet completely mastered his Unix). Some of the examples
(espeically dealing with recursion) have made their way into my own
humble code. Perl 5 By Example sits right beside it.
--
<URL:mailto:lvirden@cas.org> Quote: In heaven, there is no panic,
<*> O- <URL:http://www.teraform.com/%7Elvirden/> only planning.
Unless explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
------------------------------
Date: Mon, 13 Apr 1998 12:31:56 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: MacPerl standalone apps
Message-Id: <pudge-1304980831460001@dynamic283.ply.adelphia.net>
In article <6gs20i$att$1@gaia.ns.utk.edu>, "Bob Gwynne"
<gwynne@utkux.utk.edu> wrote:
# Chris Nandor has a MacPerl book temporarily available at
#
# http://freebie.cfcl.com/macperl/ptf_book/HTML/
My book with Vicki Brown is going to be at that address indefinitely, even
after the book comes out. Of course, all things in life are temporary ...
:)
--
Chris Nandor mailto:pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10 1FF7 7F13 8180 B6B6'])
#== New Book: MacPerl: Power and Ease ==#
#== Publishing Date: Early 1998. http://www.ptf.com/macperl/ ==#
------------------------------
Date: Mon, 13 Apr 1998 12:09:26 +0100
From: smile_ <smile_@cindy.fe.up.pt>
Subject: Need a Free Perl Data Base to the Web
Message-Id: <3531F265.4950AEDD@cindy.fe.up.pt>
Need a Free Perl Data Base to the Web, if you can help me send me one.
Thanks
_
||| =:-) =:-) =:-) =:-) =:-) (-:= (-:= (-:= (-:= (-:= |||
=:-) Nickname's: Smile_, _HD, PRomeu (-:=
. . =:-) Name: Pedro Romeu Baixinho Rodrigues (-:= . .
=:-) Home Page: http://ae.fe.up.pt/~smile_/ (-:=
| =:-) E-mail: smile_@irc.fe.up.pt (-:= |
=:-) Pager: 799237@pager.telechamada.pt (-:=
\___/ =:-) =:-) =:-) =:-) =:-) (-:= (-:= (-:= (-:= (-:= \___/
------------------------------
Date: Mon, 13 Apr 1998 20:07:17 +1000
From: Gary Ashton-Jones <gary@ashton-jones.com.au>
To: "Per Gransxe" <gransoe@get1+1net.dk>
Subject: Re: perl and CGI
Message-Id: <3531E3D5.4860659F@ashton-jones.com.au>
Goto www.perl.com page, scroll down to Perl Reference sidebar and click
on CGI to get more tutorial material than you probably ever wanted. The
main hurdle you will have, though, is finding an ISP or Webmaster who
will let you install your Perl-CGI scripts on their machine. OTOH if you
have a webserver running on your own machine you can try out the scripts
with no restrictions.
Per Gransxe wrote:
> Hi everybody
>
> I need some info on how to pipe data from a html-page via forms to a
> perl script.
> Enviroment variables and standard input and so on...
>
> Can somebody for example send me a sample of a script and a html-code
> simply showing how to add two numbers (from <INPUT>-tags) and print
> the result on a new page.
>
> Please post your answers by email as well posting to: gransoe@get2net
> . dk
>
> Hope to hear from you sooooon,
>
> Per.
------------------------------
Date: 13 Apr 1998 11:04:34 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: Perl Compiler for NT
Message-Id: <892465474.955386@cabal>
In <6gnv96$br@fridge.shore.net> "Grinch" <grinch@whoville.com> writes:
>Abigail wrote in message <6gmksk$23d$4@client3.news.psi.net>...
>>Not in the normal sense of "interpretor".
>On the other paw, it's not really a compiler in the normal sense of the
>word, either, because it doesn't produce hardware-specific machine code.
>Even the actual Perl "compiler" produces either C code,
Complies that complie to C are not uncommen. On my system there is a
pascal compiler that compiles to C, and a lisp complier that compiles to
C.
It is far easyer to write a languge that compiles to C rather then
writeing a complier for each diffrent type of meachean (Barring of cause
all the diffrences of C probgrams).
--
I'm a perl programer if you need perl programing hire me. Buy easter bilbies.
Please excuse my spelling as I suffer from agraphia see the url. Support NoCeM
http://www.cit.nepean.uws.edu.au/~dformosa/Spelling.html http://www.cm.org/
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: Mon, 13 Apr 1998 08:44:24 -0600
From: nathan@cyberservices.com
Subject: Purging files to a NO. of lines?
Message-Id: <6gt4ro$omh$1@nnrp1.dejanews.com>
I am writing a script to purge log files. Two options are:-
Purge file, retain last xxx lines
Purge file, retain last xxx kbytes
I don't think I can rely on system commands since the scripts will run on
different platforms (NT and Unix) so 'tail' is out.
The 'retain xxx kbytes' could be implemented using a 'read' and 'write'
command (although I might need to adjust for the start of the next
line).
The problem is with the 'retain last xxx lines'. I don't think I can rely
on holding all lines, or even xxx lines, in memory. What if the request
was to 'retain last 20 million lines'?
The best I have come up with so far is to do two passes through the file.
One pass to count the number of lines, another pass to throw
away all but the last xxx lines.
Anybody have any other suggestions?
p.s. This must be a perl 4 implementation.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Mon, 13 Apr 1998 10:10:57 GMT
From: $louie@visca.com (Louie)
Subject: Re: Question concerning reg exp's in a while statement
Message-Id: <3531e431.9140280@news.jet.es>
Tom Phoenix <rootbeer@teleport.com> wrote:
>On Sun, 12 Apr 1998, Louie wrote:
>
>> 12 while (<IN>) {
>> 13 s/\n/ /g; # Replace unwanted newlines with space.
>
>Nothing wrong with that, but it would almost certainly be faster
>with tr///.
All right. Thanks for the tip.
>
>> 24 while (<OUT>) {
>> 25 s/^ +<p/<p/g; # Eliminate whitespace before <p> tags.
>
>That doesn't do what the comment says. Maybe you meant this:
>
> s/\s+<p/<p/gi;
>
>...which is different in three important ways. (So, maybe you only want
>one or two of those differences.)
Am I correct in saying the differences are:
1) it deletes 1 or more of all space characters (" ", "\n", "\t",
etc.) which precede "<p", rather than merely the space;
2) it doesn't restrict this to the space character being the first
character of the line (or we could say, "first character following a
newline") and
3) it ignores case?
In my case, I don't believe these changes are significant.
>
>> My question is why line 25 won't work if it's within the initial while
>> (<IN>) statement.
>
>In what way does it not work?
It doesn't eliminate all the white space in front of the <p> tag. If
the text is:
------BEGIN TEXT-----
<p>Some text that I
don't
want wrapped like this.</p>
<p>More badly wrapped
text with
three spaces in front of the
"<p>" tag.</p>
-------END TEXT------
...and the code is:
-----BEGIN CODE------
while (<IN>) {
tr/\n/ /;
s{</p>}{</p>\n\n}g;
s{(</h\d>)}{$1\n\n}g;
s/ +<p/<p/gi;
print OUT "$_";
}
----END CODE-------
the result is:
----BEGIN RESULT------
<p>Some text that I don't want wrapped like this.</p>
<p>More badly wrapped text with three spaces in front of the "<p>"
tag.</p>
-----END RESULT---------
Note that in the result there are only two spaces in front of the <p>
tag; the line: s/ +<p/<p/gi; has eliminated one of three spaces
(s/\s+<p/<p/gi; does the same)....
...LATER (after an embarrassingly long time)...
NO! s/ +<p/<p/gi; eliminated all three spaces. What it didn't do is
eliminate the two spaces that were created by the line "tr/\n/ /;". I
confirmed this by putting a large number of spaces in front of <p>;
after running the program they were all eliminated, but the 2 spaces
added by the newline/space substitution were still there.
I found that the program deletes all spaces (thereby doing what I
wanted in the first place) if I undefine the INPUT_RECORD_SEPARATOR
($/ = undef;). This...
-----BEGIN CODE--------
while (<IN>) {
$/ = undef; # Undefine the INPUT_RECORD_SEPARATOR
tr/\n/ /; # Replace newlines with space.
s{</p>}{</p>\n\n}g; # Make paragraphs after closing </p>'s...
s{(</h\d>)}{$1\n\n}g; # ...and after all header tags.
s/ +<p/<p/gi; # Eliminate leading whitespace before <p> tags.
print OUT "$_";
}
-----END CODE---------
...produces this:
----BEGIN GOOD RESULT------
<p>Some text that I don't want wrapped like this.</p>
<p>More badly wrapped text with three spaces in front of the "<p>"
tag.</p>
-----END GOOD RESULT---------
Am I correct in assuming that Perl doesn't consider the two spaces
that were created in substitution for the linebreaks to form part of
the "<p>" line during runtime? If not, could someone explain to me
what is going on here?
Thanks.
--
Louie
louie@visca.com
http://www.visca.com/
------------------------------
Date: Mon, 13 Apr 1998 12:37:11 GMT
From: pudge@pobox.com (Chris Nandor)
Subject: Re: sendmail substitute for Macperl using "use Net::SMTP"
Message-Id: <pudge-1304980837010001@dynamic283.ply.adelphia.net>
In article <32FD5C80.5837@callisto.si.usherb.ca>,
eslcafe@callisto.si.usherb.ca wrote:
# I'm trying to overcome the lack of a sendmail programme for Macperl.
# Someone suggested using "use Net::SMTP".
Yep.
# From what I can see, it must be a syntax error in the script. The
# server accepts the smpt call but ... you'll see ...
Not really a syntax error. There are two problems below. The first is
that you are using -w. Mac::Types and Mac::InternetConfig are not -w
clean; they will give warnings if you use -w. This is not a problem, for
most purposes, because the script will still run perfectly well. They are
only warnings, not errors.
# Net::SMTP=GLOB(0x24dc2d8)>>> RCPT TO:<$email>
# Net::SMTP=GLOB(0x24dc2d8)<<< 550 5.1.1 user
# $email@antoine-girouard.qc.ca not known
Did you happen to notice this?
# $smtp->to('$email');
If you don't understand why the above is a problem yet, you need to review
your perl docs, particularly perldata (available under the MacPerl help as
"data structures"). Basically, you can't use single quotes there. You
shouldn't have any quotes at all. Remove them and try again.
Hope this helps,
--
Chris Nandor mailto:pudge@pobox.com http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10 1FF7 7F13 8180 B6B6'])
#== New Book: MacPerl: Power and Ease ==#
#== Publishing Date: Early 1998. http://www.ptf.com/macperl/ ==#
------------------------------
Date: Mon, 13 Apr 1998 19:47:41 +1000
From: Gary Ashton-Jones <gary@ashton-jones.com.au>
To: olm@mail1.csun.edu
Subject: Re: Sorting problem
Message-Id: <3531DF3D.B69DCF2D@ashton-jones.com.au>
The perl man page perlfunc.html notes the difference between numerical
sorting which uses the 'space invaders' operator '<=>' and ascii sorting
using 'cmp'.
There's also a good treatment of sorting in 'Effective Perl Programming'
(a downloadable PDF file of the relevant section is at
http://www.effectiveperl.com/EP.03.pdf but buy the book. It's a 'must
have'.)
Hope this helps.
Ovanes Manucharyan wrote:
> I am having problems sorting ascii.
> My sorting sub is included at the bottom. I got this off Tom
> Christiansen's help page about sorting.
>
> It works fine for numbers, but whenever I try to use it to sort other
> ascii, it doesn't do it completely.
>
> It's supposed to sort the array that is passed into it.
>
> sub sortdata {
> @f = ();
> for (@biglist) { push @f, (split ':')[-1] }
> @new = @biglist[ sort { $f[$a] <=> $f[$b] } 0 .. $#biglist ];
> }
>
> Can anyone help me?
> --
> ----------------------------------------------------
> Ovanes Manucharyan olm@csun.edu
> California State University, Northridge
> ----------------------------------------------------
------------------------------
Date: Mon, 13 Apr 1998 13:49:07 GMT
From: John Porter <jdporter@min.net>
Subject: Re: unique string/integer from string variable? md5?
Message-Id: <35321935.79A5@min.net>
Otis Gospodnetic wrote:
>
> I have a variable that contains a string (the string is actually a
> URL). Is there an algorithm, or better yet, a module, that can take
> my string variable and 'convert' it to some shorter string or
> integer?
> Something that will be unique, so that no two URL strings end up
> having the same value once I convert them to this shorter string or
> int.
>
> I am basically trying to assign each new URL a new and unique ID
> that
> is shorter than the URL address, so it takes less space, and maybe
> an int, for lookup performance.
> What should I look for? MD5 module?
What you want is a hash function. Do you know about hashing
functions? If the space of possible input strings is not limited,
then producing a perfect hashing function is probably impossible.
But if you know in advance what all the possible strings will
look like, you can produce a perfect hashing function (one which
is guaranteed to give a unique hash value for each input string).
>From your description, I'd guess that all URLs from the entire
world wide web are possible inputs, and/or all the scripts at
your site along with their GET arguments. In this case, you
may be able to get a good hashing function, but probably not a
perfect one.
If there are at least one million possible input strings, then
you'll need at least 6 digits of hash key, if every string must
have a unique value. And that means you'll probably have a
very sparsely populated hash space; and that means you won't
want to use a perl array. Use a perl hash instead. And that
means the hash keys don't need to be integers. And that means
you don't need a numeric hashing function; rather, a function
which compresses the URL string down to something which will meet
your stated needs: "unique" and "takes less space".
I'm sure you can come up with a compression routine optimized
for URLs. :-)
hth,
John Porter
------------------------------
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 2307
**************************************