[13840] in Perl-Users-Digest
Perl-Users Digest, Issue: 1250 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 2 03:07:20 1999
Date: Tue, 2 Nov 1999 00:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <941529912-v9-i1250@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 2 Nov 1999 Volume: 9 Number: 1250
Today's topics:
Re: a tree of subdirectories in perl? (Jaime)
Re: a tree of subdirectories in perl? <uri@sysarch.com>
Re: a tree of subdirectories in perl? <lr@hpl.hp.com>
Re: a tree of subdirectories in perl? <lr@hpl.hp.com>
Re: Another 'or'? was [perl double-split] <ltl@rgsun40.viasystems.com>
Re: Book suggestions (Abigail)
Re: Book suggestions <uri@sysarch.com>
Re: comparing text with words (Abigail)
Re: comparing text with words <lr@hpl.hp.com>
Re: Database script help (Abigail)
Re: Date (Abigail)
Re: Extract string ? <Achin@inprise.com>
Re: It is always like this here? <paul@trantor.foundation.gov>
Re: making a variable length string <uri@sysarch.com>
Re: perl JS interpreter? counting keywords? <lr@hpl.hp.com>
Re: Range operators: two dots v.s. three dots (Jim Britain)
Re: Range operators: two dots v.s. three dots <skilchen@swissonline.ch>
Re: Sending html email <jeffreyko@mailexcite.com>
Re: string number conversion (Abigail)
Re: string number conversion (Abigail)
Re: string number conversion <uri@sysarch.com>
Re: string number conversion <lr@hpl.hp.com>
Re: string number conversion <uri@sysarch.com>
Re: string number conversion <lr@hpl.hp.com>
Re: Stripping live HTML into text (Mark)
Update table <lasse@nospam.ulvemo.com>
Re: What makes the web go? (brian d foy)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 02 Nov 1999 08:44:24 +0200
From: lsprilus@weizmann.weizmann.ac.il (Jaime)
Subject: Re: a tree of subdirectories in perl?
Message-Id: <lsprilus-0211990844240001@meg.weizmann.ac.il>
In article <380E46D1.9C3658A4@dcc.unicamp.br>, Joyce Ynoue
<981414@dcc.unicamp.br> wrote:
>Does anybody know how to implement in perl something like described
#! /usr/local/bin/perl
# JPrilusky, July 26 1996
#
# draw.tree <directory> <depth>
# a negative value for depth shows also files
$start = $ARGV[0] || ".";
$limit = $ARGV[1];
if ($limit < 0) {
$alsoFiles = 1;
$limit = $limit * -1;
}
$baseDir = `pwd`;
chop $baseDir;
if ($start =~ /^\//) { $baseDir = ""; $start = substr($start,1);}
$level = 0;
$deep = " ";
print "$baseDir/$start\n";
&list_dir($start);
sub list_dir {
return if ($level > $limit);
local($dirname) = shift;
local(@content);
opendir(d,"$baseDir/$dirname") || die "Can't opendir $baseDir/$dirname\n";
@content = sort(grep(!/^\.\.?$/,readdir(d)));
closedir(d);
while ($file = shift(@content)) {
$dfile = "$dirname/$file";
if (-d "$baseDir/$dfile") {
printf ("%s%s/\n",$deep,$file);
$level++;
$deep = $deep . " ";
&list_dir($dfile);
$level--;
$deep = substr($deep,3);
}
else {
printf ("%s%s\n",$deep,$file) if ($alsoFiles);
}
}
}
Jaime Prilusky
lsprilus@bioinfo.weizmann.ac.il
Jaime.Prilusky@weizmann.ac.il
------------------------------
Date: 02 Nov 1999 02:20:42 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: a tree of subdirectories in perl?
Message-Id: <x7zowx8ilx.fsf@home.sysarch.com>
>>>>> "J" == Jaime <lsprilus@weizmann.weizmann.ac.il> writes:
just a few comments:
J> #! /usr/local/bin/perl
no -w, no strict
J> $start = $ARGV[0] || ".";
J> $limit = $ARGV[1];
what if @ARGV has only 1 arg?
shift is more common here
$start = shift || '.' ;
$limit = shift || 0 ;
J> $limit = $limit * -1;
don't you know about assignment ops?
$limit *= -1;
or simpler:
$limit = -$limit ;
J> $baseDir = `pwd`;
use Cwd. don't run a process
J> chop $baseDir;
don't need that if using Cwd
J> if ($start =~ /^\//) { $baseDir = ""; $start = substr($start,1);}
J> local($dirname) = shift;
J> local(@content);
use my instead of local. this looks like perl4 code.
J> opendir(d,"$baseDir/$dirname") || die "Can't opendir
J> $baseDir/$dirname\n";
open checking, good! lower case handles, bad!
J> printf ("%s%s/\n",$deep,$file);
why printf?
print "$deep$file\n" ;
J> $level++;
J> $deep = $deep . " ";
$deep .= " ";
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Mon, 1 Nov 1999 23:37:26 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: a tree of subdirectories in perl?
Message-Id: <MPG.12883495a757057798a184@nntp.hpl.hp.com>
In article <lsprilus-0211990844240001@meg.weizmann.ac.il> on Tue, 02 Nov
1999 08:44:24 +0200, Jaime <lsprilus@weizmann.weizmann.ac.il> says...
> In article <380E46D1.9C3658A4@dcc.unicamp.br>, Joyce Ynoue
> <981414@dcc.unicamp.br> wrote:
> >Does anybody know how to implement in perl something like described
>
> #! /usr/local/bin/perl
> # JPrilusky, July 26 1996
> #
> # draw.tree <directory> <depth>
> # a negative value for depth shows also files
I guess you didn't read enough of this thread to realize that you were
solving a homework problem for these folks.
Oh, well. It's probably too late to help them by now. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 1 Nov 1999 23:52:03 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: a tree of subdirectories in perl?
Message-Id: <MPG.128837fa182ce63f98a186@nntp.hpl.hp.com>
In article <x7zowx8ilx.fsf@home.sysarch.com> on 02 Nov 1999 02:20:42 -
0500, Uri Guttman <uri@sysarch.com> says...
> >>>>> "J" == Jaime <lsprilus@weizmann.weizmann.ac.il> writes:
...
> J> printf ("%s%s/\n",$deep,$file);
>
> why printf?
>
> print "$deep$file\n" ;
>
> J> $level++;
> J> $deep = $deep . " ";
>
> $deep .= " ";
All the hacking around with $deep is unnecessary. Just use the global
variable $level (which could instead be passed to the recursions just as
$deep is now).
print " " x (3 * $level), $file, "\n";
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 2 Nov 1999 04:42:53 GMT
From: lt lindley <ltl@rgsun40.viasystems.com>
Subject: Re: Another 'or'? was [perl double-split]
Message-Id: <7vlq4d$a8f$1@rguxd.viasystems.com>
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
:>Designing a programming language is an exercise in psychology. As you
:>see, it is *a lot* of work comparing to the result: changing
:>99.9%-correct behaviour to correct behaviour. Those nasty creatures
:>they call "programmers" are lazy, and need much more incentive than
:>fixing 0.1% of cases to add an extra statement to a program.
I resemble that remark. ;-8
OK. OK already. :-8 But still, if you expect to win your debate
on this issue, you really should use an example more like the one
I posted. A problem with a reasonable likelihood of happening is a
better example than one with only 0.1% probability, for some
definitions of better. :-)
I'm sorry. Truly (I don't know the emoticon for "sincere"). I
really respect the value you bring to the whole Perl development
effort, and I feel bad about tweaking you on this (well, maybe only a
little bad, but still bad), but you are providing an easy target.
If I am aware enough of the problem to know that it exists, I add the
extra line of code (if I care enough about the possibility of the
exception ever happening). The existence of '??' could help people
be aware of the potential problem. I'll buy your argument about the
psychology of that. But once aware of the problem, I don't mind
adding the extra line of code (when I care enough to do it). Is
adding a new operator to the language syntax really the right thing
to do to promote awareness of "truth" values in Perl?
I think that more and frequent distinctions between definedness
and truth throughout the documentation is probably a better answer.
Since I am not providing patches to the documentation or the language
implementation, my opinion is worth the paper it is written on.
--
// Lee.Lindley /// I used to think that being right was everything.
// @bigfoot.com /// Then I matured into the realization that getting
//////////////////// along was more important. Except on usenet.
------------------------------
Date: 1 Nov 1999 23:18:09 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Book suggestions
Message-Id: <slrn81ssvd.66b.abigail@alexandra.delanet.com>
Joel Berger (joel_berger@manulife.com) wrote on MMCCLIII September
MCMXCIII in <URL:news:2mlT3.386$Ao3.125@198.235.216.4>:
,, Suggestions for a good book for a newbie?
Winnie-the-Pooh.
Abigail
--
perl -we '$_ = q ;4a75737420616e6f74686572205065726c204861636b65720as;;
for (s;s;s;s;s;s;s;s;s;s;s;s)
{s;(..)s?;qq qprint chr 0x$1 and \161 ssq;excess;}'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 02 Nov 1999 00:59:01 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Book suggestions
Message-Id: <x7bt9da0yi.fsf@home.sysarch.com>
>>>>> "A" == Abigail <abigail@delanet.com> writes:
A> Joel Berger (joel_berger@manulife.com) wrote on MMCCLIII September
A> MCMXCIII in <URL:news:2mlT3.386$Ao3.125@198.235.216.4>:
A> ,, Suggestions for a good book for a newbie?
A> Winnie-the-Pooh.
more accurate than perl for dummies and not as condescending to the
reader. good choice!
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 2 Nov 1999 00:20:58 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: comparing text with words
Message-Id: <slrn81t0l5.66b.abigail@alexandra.delanet.com>
Bart Lateur (bart.lateur@skynet.be) wrote on MMCCLIII September MCMXCIII
in <URL:news:381d8263.2202437@news.skynet.be>:
|| Larry Rosler wrote:
||
|| >The 'golf score' is often an indication of clarity and even of
|| >performance. In this case, using 'local $_' to eliminate all the
|| >repetitions of '$x =~', and using logical short-circuiting '||' instead
|| >of all those 'if' statements.
||
|| You can do :
||
|| for($x) {
|| /.../
|| }
||
|| too. I use it a lot, as soon as I need to do more than one thing with $x
|| in a row.
||
|| Of course, this won't work if you need to modify the value of a
|| read-only variable. So for example you can't do:
||
|| if(/($pat)/) {
|| for($1) {
|| tr/\r\n\t / /s;
|| print;
|| }
|| }
That's why I seldomly use for for such tricks.
if (/($pat)/) {
local $_ = $1;
tr/\r\n\t / /s;
print;
}
Takes even less lines.
Or even:
map {tr/\r\n\t / /s; print} /($pat)/;
Abigail
--
package Z;use overload'""'=>sub{$b++?Hacker:Another};
sub TIESCALAR{bless\my$y=>Z}sub FETCH{$a++?Perl:Just}
$,=$";my$x=tie+my$y=>Z;print$y,$x,$y,$x,"\n";#Abigail
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Mon, 1 Nov 1999 22:30:40 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: comparing text with words
Message-Id: <MPG.128824eb84235efd98a181@nntp.hpl.hp.com>
In article <slrn81t0l5.66b.abigail@alexandra.delanet.com> on 2 Nov 1999
00:20:58 -0600, Abigail <abigail@delanet.com> says...
...
> map {tr/\r\n\t / /s; print} /($pat)/;
tr/\r\n\t / /s, print for /($pat)/;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 2 Nov 1999 00:03:56 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Database script help
Message-Id: <slrn81svl7.66b.abigail@alexandra.delanet.com>
Jim (jim@jimmo.freeuk.com) wrote on MMCCLIII September MCMXCIII in
<URL:news:38200c68.18917744@news.freeuk.net>:
** Hello,
**
** Can you help ?
**
** We have written a perl script to read/write to a dbm database.
**
** We now need to "hold" the user name when a user logs on to our website
** to enable us to identify them.
**
** How do we retain the user name once the scrips has finished executing
** ?
** If the user needs to update his details within the database and not
** have to logon again something must retain his user name.
Your design is fundamentally flawed: you are trying to use a stateless
protocol (HTTP) to maintain state. Although there are some hacks that
make it work sometimes - they'll fail at inconvenient times.
None of this however, has anything to do with Perl.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 2 Nov 1999 00:22:14 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Date
Message-Id: <slrn81t0nh.66b.abigail@alexandra.delanet.com>
Mazhar Memon (mazhar@nmt.edu) wrote on MMCCLIII September MCMXCIII in
<URL:news:7vl23b$isf$1@newshost.nmt.edu>:
'' How do I get the current date in Perl?
my $date = "23 Feb 2008";
sleep $x; # For appropriate x.
Abigail
--
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Tue, 02 Nov 1999 13:46:13 +0800
From: Adrian Chin <Achin@inprise.com>
Subject: Re: Extract string ?
Message-Id: <381E7AA5.67C36199@inprise.com>
This works too, thanks.
if ($file =~ /.*\//)
{
$shift = "$'\n";
print "$shift";
}
~
~
Matthew Stevenson wrote:
> Adrian Chin wrote:
>
> > I have :
> >
> > vol1/extract/inst/sum.C:1:2:3
> > vol2/extract/algo.h:2:3:4
> > vol3/extr/rol/rojak/bunga/fungi.sh:1:2:3
> >
> > in a file call file.txt. How do I extract the colored string out to a
> > variable in perl ?
>
> This works, may not be the best...
>
> #!/usr/bin/perl -w
>
> while(<STDIN>){
> print "$2\n" if ( m#(\w+/)*(\w+\.\w+):# );
> }
>
> echo "inst/sum.C:1:2:3\nvol2/extract/algo.h:2:3:4\nblahblah" | pro.pl
> sum.C
> algo.h
>
> Matthew
>
> --
>
> Matthew Stevenson
> University of Auckland
> mj.stevenson@auckland.ac.nz
------------------------------
Date: 01 Nov 1999 22:53:48 -0700
From: Paul Rotering <paul@trantor.foundation.gov>
Subject: Re: It is always like this here?
Message-Id: <sa7yach1lsj.fsf@trantor.foundation.gov>
Ala Qumsieh <aqumsieh@matrox.com> writes:
> In a forum discussing the C language, for example, you wouldn't find
> people asking stupid questions (or you wouldn't find as many people, I
> should say). This is because people don't think of C as an easy
> language to grasp, and reading a book or two on C is the only way to
> start learning the language. Mysteriously, a lot of them think of Perl
> differently.
You are obviously not a denizen of comp.lang.c. Their definition of what's
on topic is considerably narrower than comp.lang.perl.misc's yet the
floating "are discussions of what's on topic on topic" thread is usually
present. As has been noted, that group has also become the help desk of
those who cannot be bothered to read the documentation.
--
>No, that book was "The lathe of Heaven" by U.K. Leguin.
Stay tuned for my fanfic sequels "The Horizontal Machining Center of
Valhalla" and "The Five-Axis Form Grinder of Purgatory".
--Bill Newcomb in a.r.k
------------------------------
Date: 02 Nov 1999 00:57:08 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: making a variable length string
Message-Id: <x7eme9a11n.fsf@home.sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> In article <x7k8o1a6p0.fsf@home.sysarch.com> on 01 Nov 1999 22:55:07 -
LR> 0500, Uri Guttman <uri@sysarch.com> says...
>> >>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
>>
LR> my $string = 1 x $num_ones . 0 x ($initial_length + 5 - $num_ones);
>>
>> i know this will make for a worse golf score, but i would quote the 1
>> and 0 as they are being used as strings (and x will stringify numbers)
>> so why not quote them so the maintainer will see them as strings too.
LR> As if I didn't make a conscious choice of how to show it! (They were
LR> explicit strings in the original post.) You have reinforced the
LR> pedagogic intent, about interchangeability of numbers and strings.
that is why i want to quote them, to emphasize their use as strings. it
is the same as using single vs double quotes when there is no
interpolation. no real functional difference but a very high difference in
human semantics. that is a major part of my coding philosophy, code what
you mean to say and not just to get the computer to do it. it follows
from my coding quiz (i should web that already. since i updated my site
it should be added too)
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Mon, 1 Nov 1999 23:30:22 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: perl JS interpreter? counting keywords?
Message-Id: <MPG.128832e1aec5e81198a183@nntp.hpl.hp.com>
In article <381E5943.E6203019@klab.caltech.edu> on Mon, 01 Nov 1999
19:23:47 -0800, Laurent Itti <itti@klab.caltech.edu> says...
...
You would get better results if you posted unrelated questions
separately.
> A second question is: is there any better/faster way to count how many
> times
> do various lists of keywords appear in a string than to loop over the
> lists,
> then loop over keywords for each list, then do a series of pattern
> matches
> for each keyword?
Please set your line lengths to 72 characters.
> my keywords presently look like:
>
> %sk = (
> 'cool' => 'cool|nice|super|rad|kick-ass',
> 'new' => 'new|novel|state-of-the-art',
> ...
> );
> and I would like a compound word count for each of the categories
> ('cool',
> 'new', and so on).
>
> thanks a lot!
>
> -- laurent itti
>
>
> I include my current code for the keyword match:
>
>
> sub score { # $data: string where to look for keywords
> my %s, $k;
That syntax is invalid. Please post code that compiles!
> foreach $k (keys %sk) {
> $s{$k} = kwmatch($_[0], $sk{$k});
> }
> return %s; # one count per keyword category
> }
>
> sub kwmatch { # $data, $kwlist
> my @kw = split(/\|/, $_[1]), $k, $nb = 0;
> foreach $k (@kw) {
> my $d = " ".$_[0]." ";
> while ($d =~ / \Q$k /) { $nb ++; $d = $'; }
> }
> return $nb;
> }
#!/usr/local/bin/perl -w
use strict;
my %sk = (
cool => 'cool|nice|super|rad|kick-ass',
new => 'new|novel|state-of-the-art',
none => 'no|matches|here',
);
sub score { # $data: string where to look for keywords
my %s;
for (keys %sk)
{ ++$s{$_} while $_[0] =~ /\b(?:$sk{$_})\b/g }
\%s # one count per keyword category
}
my $counts = score('This is a rad super new novel kick-ass string.');
print map "$_ -> $counts->{$_}\n" => keys %$counts;
__END__
Output:
new -> 2
cool -> 3
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 02 Nov 1999 06:42:48 GMT
From: jbritain@home.com (Jim Britain)
Subject: Re: Range operators: two dots v.s. three dots
Message-Id: <381e86ff.2090436@news>
On Tue, 2 Nov 1999 11:58:08 +0800, "John Lin" <johnlin@chttl.com.tw>
wrote:
>Hi,
> I see the two dot operator '..' and three dot operator '...' in perlop.
>Without examples, I can't understand the difference.
>
>for(a..z) { print }
>for(a...z) { print } # the same!
>
>while(<>) { print if 1..5 }
>while(<>) { print if 1...5 } # the same!
>
>Would you help? Thanks
The range operator is specially defined and otpimized for text
operations.
For the full info, and a clear explanation, type: perldoc perlop at
the command line, and use /range to search forward.. There's several
paragraphs. It is extremely useful for text block matching.
------------------------------
Date: Tue, 02 Nov 1999 07:32:29 GMT
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: Range operators: two dots v.s. three dots
Message-Id: <hswT3.28194$m4.101316478@news.magma.ca>
John Lin <johnlin@chttl.com.tw> wrote in message
news:7vlnis$j0c@netnews.hinet.net...
> I see the two dot operator '..' and three dot operator '...' in
> perlop.
> Without examples, I can't understand the difference.
>
> for(a..z) { print }
> for(a...z) { print } # the same!
>
In list context there is no difference between the two operators
> while(<>) { print if 1..5 }
> while(<>) { print if 1...5 } # the same!
>
In scalar context the relevant part of perlop says:
The range operator can test the right operand and become false
on the same evaluation it became true (as in awk), but it still
returns true once. If you don't want it to test the right
operand till the next evaluation (as in sed), use three dots
("...") instead of two.
This is useful if you want to do things like "get the lines between
lines starting with the same digit (character, substring, regexp or
whatever)" as in this mini example:
while(<DATA>) {
chomp();
my $seq_numb = $_ =~ /^(1|2|3)/ ... /^$1/;
if ($seq_numb ne "" and
$seq_numb > 1 and
$seq_numb !~ /E0$/) {
print "Sequence Number: $seq_numb",
" Matched String: $_", "\n";
}
}
__DATA__
123
aaa
aab
132
bbb
bbc
bbd
213
ccc
ccd
cce
231
ddd
312
eee
321
This should print:
Sequence Number: 2 Matched String: aaa
Sequence Number: 3 Matched String: aab
Sequence Number: 2 Matched String: ccc
Sequence Number: 3 Matched String: ccd
Sequence Number: 4 Matched String: cce
Sequence Number: 2 Matched String: eee
It doesn't print anything if the .. operator were used, because the
"ranges" matched in this case are all the lines starting with the
digits 1, 2 or 3.
------------------------------
Date: Mon, 1 Nov 1999 22:52:44 -0800
From: "newsgroup" <jeffreyko@mailexcite.com>
Subject: Re: Sending html email
Message-Id: <7vm1i4$7ej$1@usc.edu>
<traviscook@my-deja.com> wrote in message
news:7vl5nj$p8c$1@nnrp1.deja.com...
> I have a custom program that handles the smtp conversation on port 25.
> I had to do a custom one for a variety of reasons. I can send a
> regular 'text/plain' email with no problems. What isn't working
> correctly is sending out a 'text/html' email. The email is arriving
> fine, but I see all the header info and the html tags. So, obviously,
> the email type isn't being recognized. Can anyone help me with this?
>
> Travis
>
try add
MIME-Version: 1.0
Content-Type: text/html
to header or visit
http://www.hotwired.com/webmonkey/98/08/index3a_page3.html
------------------------------
Date: 1 Nov 1999 23:30:33 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: string number conversion
Message-Id: <slrn81stmk.66b.abigail@alexandra.delanet.com>
Tom Phoenix (rootbeer@redcat.com) wrote on MMCCLIV September MCMXCIII in
<URL:news:Pine.GSO.4.10.9911011723580.29670-100000@user2.teleport.com>:
?? On Fri, 29 Oct 1999, Brett W. McCoy wrote:
??
?? > sub frac2dec {
?? > my $fracnum = shift;
?? > (my $int, my $frac) = split(' ', $fracnum);
?? > my $decimal = eval $frac;
?? > return $int + $decimal;
?? > }
?? >
?? > print frac2dec('4 2/5');
??
?? That's an evil eval. Wouldn't this be better without it?
Nah. It would be better without the split.
sub frac2dec {
local $_ = shift;
s/\s+/+/;
eval;
}
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 1 Nov 1999 23:36:11 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: string number conversion
Message-Id: <slrn81su15.66b.abigail@alexandra.delanet.com>
Jeff Pinyan (jeffp@crusoe.net) wrote on MMCCLIV September MCMXCIII in
<URL:news:Pine.GSO.4.10.9911012137310.2694-100000@crusoe.crusoe.net>:
()
() How bad could explicit parsing be here? Fractions come in a few flavors:
()
() A B/C
() A
() B/C
()
() So you have three simple cases:
()
() sub frac2dec {
() my ($dec,$num,$den) = shift =~
() m!^([^\s/]+)?\s*(?:([^\s/]+)/(.*))?$!;
() return $dec unless $num;
() die "Illegal division by 0, etc..." unless $den;
() return $dec + $num/$den;
() }
()
() Of course, this doesn't work on non-fraction input, like "foo bar/blat" or
() something. Be more elegant if you desire. I tested mine, it appears to
() be working.
It gives a warning on '4/5'.
Abigail
--
sub f{sprintf'%c%s',$_[0],$_[1]}print f(74,f(117,f(115,f(116,f(32,f(97,
f(110,f(111,f(116,f(104,f(0x65,f(114,f(32,f(80,f(101,f(114,f(0x6c,f(32,
f(0x48,f(97,f(99,f(107,f(101,f(114,f(10,q ff)))))))))))))))))))))))))
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 02 Nov 1999 01:14:31 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: string number conversion
Message-Id: <x7904ha08o.fsf@home.sysarch.com>
>>>>> "A" == Abigail <abigail@delanet.com> writes:
A> () sub frac2dec {
A> () my ($dec,$num,$den) = shift =~
A> () m!^([^\s/]+)?\s*(?:([^\s/]+)/(.*))?$!;
A> () return $dec unless $num;
A> () die "Illegal division by 0, etc..." unless $den;
A> () return $dec + $num/$den;
A> () }
A> It gives a warning on '4/5'.
i thought i saw that but didn't try it. just put
$dec = 0 unless defined $dec
in there.
i have a feeling the regex could be better too. it allows non digits and
doesn't check for failure.
something like this looks better to me (tested)
sub frac2dec {
return $1 if $_[0] =~ /^(\d+)$/ ;
return unless $_[0] =~ m|^(?:(\d+)\s+)?(\d+)/(\d+)| ;
return unless $3 ;
return $1 + $2/$3 if $1 ;
return $2/$3 ;
}
cute, eh?
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Mon, 1 Nov 1999 22:48:15 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: string number conversion
Message-Id: <MPG.1288290e852f735998a182@nntp.hpl.hp.com>
In article <x7904ha08o.fsf@home.sysarch.com> on 02 Nov 1999 01:14:31 -
0500, Uri Guttman <uri@sysarch.com> says...
...
> sub frac2dec {
> return $1 if $_[0] =~ /^(\d+)$/ ;
> return unless $_[0] =~ m|^(?:(\d+)\s+)?(\d+)/(\d+)| ;
> return unless $3 ;
> return $1 + $2/$3 if $1 ;
> return $2/$3 ;
> }
>
> cute, eh?
sub frac2dec {
$_[0] =~ /^\d+$/ ? $_[0] :
$_[0] =~ m|^(\d+\s+)?(\d+)/(\d+)$| && $3 ?
($1 || 0) + $2/$3 : undef
}
cuter, eh?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 02 Nov 1999 02:11:12 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: string number conversion
Message-Id: <x73dup9xm7.fsf@home.sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> sub frac2dec {
LR> $_[0] =~ /^\d+$/ ? $_[0] :
LR> $_[0] =~ m|^(\d+\s+)?(\d+)/(\d+)$| && $3 ?
LR> ($1 || 0) + $2/$3 : undef
LR> }
LR> cuter, eh?
nested ?: are not cute. and you are not stripping the white space from
$1 even though perl will do the right math.
stealing some of your tricks my new version is:
sub frac2dec {
return $1 if $_[0] =~ /^(\d+)$/ ;
return unless $_[0] =~ m|^(?:(\d+)\s+)?(\d+)/(\d+)| && $3 ;
return ($1 || 0) + $2/$3 ;
}
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Mon, 1 Nov 1999 23:44:27 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: string number conversion
Message-Id: <MPG.12883632b765a0f698a185@nntp.hpl.hp.com>
In article <x73dup9xm7.fsf@home.sysarch.com> on 02 Nov 1999 02:11:12 -
0500, Uri Guttman <uri@sysarch.com> says...
> >>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
>
> LR> sub frac2dec {
> LR> $_[0] =~ /^\d+$/ ? $_[0] :
> LR> $_[0] =~ m|^(\d+\s+)?(\d+)/(\d+)$| && $3 ?
> LR> ($1 || 0) + $2/$3 : undef
> LR> }
>
> LR> cuter, eh?
>
> nested ?: are not cute.
De gustibus... I think they're just dandy!
BTW, these ?: are sequential, not nested. Nested are decidedly less
dandy.
> ... and you are not stripping the white space from
> $1 even though perl will do the right math.
And it will do it quietly, too. Laziness... (per The Larry).
> stealing some of your tricks my new version is:
>
> sub frac2dec {
> return $1 if $_[0] =~ /^(\d+)$/ ;
> return unless $_[0] =~ m|^(?:(\d+)\s+)?(\d+)/(\d+)| && $3 ;
> return ($1 || 0) + $2/$3 ;
> }
You're welcome. I stole the basic stuff from you first. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 02 Nov 1999 07:30:02 GMT
From: maggelet@mminternet.com (Mark)
Subject: Re: Stripping live HTML into text
Message-Id: <381e922c.34407803@news.mminternet.com>
The fastest way is sed.
sed -e :a -e 's/<[^>]*>//g;/</N;//ba' filename >outfile
from the sed one-liners page:
http://www.cornerstonemag.com/sed/sed1line.txt
- Mark
On Fri, 29 Oct 1999 22:34:25 GMT, "Ryan"
<ryan_richards_2000[NOSPAM]@yahoo.com> wrote:
>I need to come up with a solution to strip text from an html page and place
>it in a file on the local machine. I was thinking Java, Javascript, PERL
>etc. Any ideas would be most welcome!
>
>Ryan
>
>
------------------------------
Date: Tue, 02 Nov 1999 07:12:44 GMT
From: "Lasse" <lasse@nospam.ulvemo.com>
Subject: Update table
Message-Id: <M9wT3.2459$Y4.29925@dummy.bahnhof.se>
Hi
I'm trying to update one cell in a table, instead of using frames.
I know that I read something about this, but I cant remember if it can =
be done or not.
I'm writing perl / CGI aand don't want to be on the wrong track.
Please give me a hint of how to do, if possible.
regards Lasse
------------------------------
Date: Tue, 02 Nov 1999 01:23:31 -0500
From: brian@smithrenaud.com (brian d foy)
Subject: Re: What makes the web go?
Message-Id: <brian-0211990123310001@155.new-york-58-59rs.ny.dial-access.att.net>
In article <7vkkpn$fvr@junior.apk.net>, catfood@apk.net (Mark W. Schumann) wrote:
>In article <brian-0111990248320001@134.new-york-61-62rs.ny.dial-access.att.net>,
>brian d foy <brian@smithrenaud.com> wrote:
>>In article <7vjbbi$hfi@junior.apk.net>, catfood@apk.net (Mark W. Schumann) wrote:
>>> Perl is not Apache. Apache is not Perl.
>>
>>that's a little fuzzy, because my apache is perl ;)
>
>Hey, just because it's perl doesn't mean it's Perl.
>
>GeeeeeEEEEEeeeez. Newbies.
who's a newbie? i can write Perl scripts in Apache as well as
running them in Apache.
be careful with your replies...
--
brian d foy
Perl Mongers <URI:http://www.perl.org>
CGI MetaFAQ
<URI:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 1250
**************************************