[22989] in Perl-Users-Digest
Perl-Users Digest, Issue: 5209 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 10 09:05:51 2003
Date: Thu, 10 Jul 2003 06:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 10 Jul 2003 Volume: 10 Number: 5209
Today's topics:
All instances of regexp <grzes@gnu.univ.gda.pl>
Re: All instances of regexp <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: All instances of regexp <wasell@bahnhof.se>
Re: All instances of regexp <john.thetenant-s@moving-picture.com>
Re: All instances of regexp <grzes@gnu.univ.gda.pl>
Re: Alternative to use vars <abigail@abigail.nl>
Re: Automatic page forwarding in cgi perl script <ch.accart@magic.fr>
Re: Automatic page forwarding in cgi perl script <flavell@mail.cern.ch>
Re: comparing floating point numbers <kalinabears@hdc.com.au>
Re: comparing floating point numbers <mothra@nowhereatall.com>
Re: comparing floating point numbers (Greg Bacon)
Emacs modules for Perl programming (Jari Aalto+mail.perl)
Re: Fastest way to build a hash <REMOVEsdnCAPS@comcast.net>
Re: Fastest way to build a hash (=?ISO-8859-1?Q?Stefan_Fischerl=E4nder?=)
Re: Fastest way to build a hash (=?ISO-8859-1?Q?Stefan_Fischerl=E4nder?=)
Re: Fastest way to build a hash <minceme@start.no>
Re: Fastest way to build a hash (=?ISO-8859-1?Q?Stefan_Fischerl=E4nder?=)
Re: Find string in web page (Kirk Larsen)
Re: Hanging pipes in CGI Perl <cbaegert-pas-de-spam@europeanservers.net>
Re: Help with Perl Script (Helgi Briem)
Re: Help with Perl Script <wsegrave@mindspring.com>
Re: hi people <tassilo.parseval@rwth-aachen.de>
Re: How to do SSL FTP? <cat@no-spam.com>
Re: Matt's Simple Search - a new angle? (Toby Newman)
Re: perl restaurant menu <mbudash@sonic.net>
Re: string question <abigail@abigail.nl>
Re: string question <charlie_baratski@yahoo.com>
Re: Total Butt Heads in this news group <john.thetenant-s@moving-picture.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 10 Jul 2003 11:31:35 +0200
From: Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
Subject: All instances of regexp
Message-Id: <Pine.LNX.4.53.0307101131060.24218@gnu.univ.gda.pl>
How to, having a given string, find all instances of a given regular
expression? Is there a function to do it?
For example:
@nums =3D findall(/\d\d*/,"foo 16 bar 18 e2fdsjkhto859kfd")
fills @nums with ( "16", "18", "2", "859" ).
Is there any similar function? (I'm new to Perl).
--=20
Grzes=B3aw
------------------------------
Date: Thu, 10 Jul 2003 09:58:02 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: All instances of regexp
Message-Id: <Xns93B47949C4F43elhber1lidotechnet@62.89.127.66>
Grzegorz Borowiak wrote:
> How to, having a given string, find all instances of a given regular
> expression? Is there a function to do it?
>
> For example:
>
> @nums = findall(/\d\d*/,"foo 16 bar 18 e2fdsjkhto859kfd")
>
> fills @nums with ( "16", "18", "2", "859" ).
>
> Is there any similar function? (I'm new to Perl).
my @nums = 'foo 16 bar 18 e2fdsjkhto859kfd' =~ m/(\d+)/g;
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Thu, 10 Jul 2003 12:14:22 +0200
From: Thomas Wasell <wasell@bahnhof.se>
Subject: Re: All instances of regexp
Message-Id: <MPG.19775a969a32d29698970b@news.bahnhof.se>
In article <Pine.LNX.4.53.0307101131060.24218@gnu.univ.gda.pl>, Grzegorz
Borowiak <grzes@gnu.univ.gda.pl> wrote:
>How to, having a given string, find all instances of a given regular
>expression? Is there a function to do it?
>
>For example:
>
>@nums =3D findall(/\d\d*/,"foo 16 bar 18 e2fdsjkhto859kfd")
>
>fills @nums with ( "16", "18", "2", "859" ).
>
>Is there any similar function? (I'm new to Perl).
@nums = ( "foo 16 bar 18 e2fdsjkhto859kfd" =~ /\d\d*/g );
(The parenthesis is only for emphasis; you can drop it.)
Read all about it in:
perldoc perlop
perldoc perlre
--
Thomas Wasell | "I'd love to go out with you, but I never go out on
wasell@bahnhof.se | days that end in `Y.'"
------------------------------
Date: Thu, 10 Jul 2003 11:05:20 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: All instances of regexp
Message-Id: <20030710110520.0f60ddf7.john.thetenant-s@moving-picture.com>
On Thu, 10 Jul 2003 11:31:35 +0200
Grzegorz Borowiak <grzes@gnu.univ.gda.pl> wrote:
>
> How to, having a given string, find all instances of a given regular
> expression? Is there a function to do it?
>
> For example:
>
> @nums = findall(/\d\d*/,"foo 16 bar 18 e2fdsjkhto859kfd")
>
> fills @nums with ( "16", "18", "2", "859" ).
>
> Is there any similar function? (I'm new to Perl).
>
>
> --
> Grzes³aw
it's the g modifier you want to use.
being new to Perl, you'll naturally
want to read the docs for this. run
"perldoc perlop" and read the "Regexp
Quote-Like Operators" section. then
read the entire doc :) then read
"perldoc perl" and browse the docs
listed there.
#!/usr/bin/perl
use warnings;
use strict;
my $string = 'foo 16 bar 18 e2fdsjkhto859kfd';
my @matches = $string =~ /\d+/g;
print "@matches\n";
-------------
output:
16 18 2 859
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail
------------------------------
Date: Thu, 10 Jul 2003 13:26:51 +0200
From: Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
Subject: Re: All instances of regexp
Message-Id: <Pine.LNX.4.53.0307101323500.19220@gnu.univ.gda.pl>
On Thu, 10 Jul 2003, John Strauss wrote:
> On Thu, 10 Jul 2003 11:31:35 +0200
> Grzegorz Borowiak <grzes@gnu.univ.gda.pl> wrote:
> >
> > How to, having a given string, find all instances of a given regular
> > expression? Is there a function to do it?
> >
> > For example:
> >
> > @nums = findall(/\d\d*/,"foo 16 bar 18 e2fdsjkhto859kfd")
> >
> > fills @nums with ( "16", "18", "2", "859" ).
> >
> > Is there any similar function? (I'm new to Perl).
> >
> >
> > --
> > Grzes?aw
>
>
> it's the g modifier you want to use.
> being new to Perl, you'll naturally
> want to read the docs for this. run
> "perldoc perlop" and read the "Regexp
> Quote-Like Operators" section. then
> read the entire doc :) then read
> "perldoc perl" and browse the docs
> listed there.
Thx a lot to all you who helped me. Perl doc is very large and I didn't
know where to search it.
--
Grzes?aw
------------------------------
Date: 10 Jul 2003 07:14:10 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Alternative to use vars
Message-Id: <slrnbgq4i2.q8r.abigail@alexandra.abigail.nl>
Martien Verbruggen (mgjv@tradingpost.com.au) wrote on MMMDC September
MCMXCIII in <URL:news:slrnbgpd8d.rlm.mgjv@martien.heliotrope.home>:
__
__ So, summarising...
__
__ C<my()> creates a new non-package variable with lexical scope, and
__ existence.
__ C<local()> saves the current value of a package (global) variable and
__ restores it on leaving the current scope.
You can also localize hash and array elements - even if the hash or
array are lexicals.
Abigail
--
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
------------------------------
Date: Thu, 10 Jul 2003 09:45:39 +0200
From: Christian Accart <ch.accart@magic.fr>
Subject: Re: Automatic page forwarding in cgi perl script
Message-Id: <bej5j2$qqr$2@s1.read.news.oleane.net>
Try this:
print ("Location:
http:\/\/localhost\/ElectronicMedicalRecord\/OrderEntry\/Orders.html\n\n");
Jürgen Exner wrote:
> Max wrote:
>
>>print ("Location:
>>http://localhost/ElectronicMedicalRecord/OrderEntry/Orders.html\n\n");
>>
>>Why won't this work?
>
>
> Works just fine for me.
> It prints the text
> Location:
> http://localhost/ElectronicMedicalRecord/OrderEntry/Orders.html
>
> to STDOUT. Did you expect it to do anything else?
>
> jue
>
>
--
----------------------------------------------------
Christian Accart
Département imprimés numériques SEPSI-IRIS FRance
Tél: 33+ (0)1 60 13 86 86
Fax: 33+ (0)1 60 13 86 81
----------------------------------------------------
------------------------------
Date: Thu, 10 Jul 2003 12:06:58 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Automatic page forwarding in cgi perl script
Message-Id: <Pine.LNX.4.53.0307101203140.31457@lxplus078.cern.ch>
On Thu, Jul 10, Christian Accart yelled out atop a fullquote:
> Try this:
Aha, another triumph for top-posting...
> print ("Location:
> http:\/\/localhost\/ElectronicMedicalRecord\/OrderEntry\/Orders.html\n\n");
It's a sure-fire bogosity indicator, isn't it, folks?
I suppose you didn't learn anything from the previous postings on
this thread. As such, it doesn't look as if Usenet is of any benefit
to you; nor you to it.
I'll be interested to see you prove me wrong. I'd welcome it, in
fact, but I don't expect it'll happen.
------------------------------
Date: Thu, 10 Jul 2003 22:05:14 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: comparing floating point numbers
Message-Id: <3f0d5782$0$23125$5a62ac22@freenews.iinet.net.au>
"Thens" <thens@nospam.com> wrote in message
>
> I wanted to know under what circumstances may adding 0.1 at both ends
can fail.
>
I haven't dug up an example where this fails - but I see no reason to assume
that such examples don't exist.
You might be interested in reading an article by Tom Phoenix at:
http://www.samag.com/documents/s=1277/sam02040001/
It's not terribly deep - but it *is* an interesting and informative
discussion of this issue.
Cheers,
Rob
------------------------------
Date: Thu, 10 Jul 2003 05:24:19 -0700
From: "Mothra" <mothra@nowhereatall.com>
Subject: Re: comparing floating point numbers
Message-Id: <3f0d5b1f$1@usenet.ugs.com>
"Thens" <thens@nospam.com> wrote in message
news:20030710101239.5a111e91.thens@nospam.com...
> Hi,
>
> I have a problem comparing floating point numbers. After a lot of
googling and docs I found the issue to be because of the internal floating
point representation.
>
[snipped]
Here is what I use to compare two floating numbers.
until ( equal( $tmp_rise_2, $tmp_rise_3, 8 ) ) {
do stuff....
}
sub equal {
#
#
# FUNCTIONAL SEQUENCE for equal
#
# _GIVEN
#
# Two floating point numbers and Accuracy
#
# _THEN
#
# Use sprintf to format the numbers to Accuracy
# number of decimal places
#
# _RETURN
#
# True if the numbers are equal
#
my ( $A, $B, $dp ) = @_;
return sprintf( "%.${dp}g", $A ) eq sprintf( "%.${dp}g", $B );
}
hope this helps
Mothra
------------------------------
Date: Thu, 10 Jul 2003 12:58:57 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: comparing floating point numbers
Message-Id: <vgqoohhphmfb14@corp.supernews.com>
In article <20030710101239.5a111e91.thens@nospam.com>,
Thens <thens@nospam.com> wrote:
: [...]
:
: While searching the group archive, I found this can be achieved by
: checking for a small delta like
:
: $delta = 0.0001
:
: if ( abs ( $num1 - $num2 ) < $delta ) {
: # Now they are eual
: }
:
: I wanted to know under what circumstances may adding 0.1 at both
: ends can fail.
That depends on the nature of your computation. Remember that computers
use finite-precision arithmetic, the way you structure computations can
hurt you, e.g., dividing by a very small number or subtracting numbers
close values can produce serious rounding errors.
See "What Every Computer Scientist Should Know About Floating-Point
Arithmetic" at
http://docs.sun.com/source/806-3568/ncg_goldberg.html
Even checking for membership in some epsilon-neighborhood isn't
always sufficient:
Incidentally, some people think that the solution to such
anomalies is never to compare floating-point numbers for
equality, but instead to consider them equal if they are within
some error bound E. This is hardly a cure-all because it raises
as many questions as it answers. What should the value of E be?
If x < 0 and y > 0 are within E, should they really be
considered to be equal, even though they have different signs?
Furthermore, the relation defined by this rule,
a ~ b <=> |a - b| < E
is not an equivalence relation because a ~ b and b ~ c does
not imply that a ~ c.
ibid.
Greg
--
While the federal government is frustrating when it treats economic
problems with nonchalance, it is terrifying when it gets involved.
-- Bob Novak
------------------------------
Date: 10 Jul 2003 09:56:14 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1057830497@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Unix Windows port (for Unix die-hards):
install http://www.cygwin.com/ which includes native Emacs 21.x.
XEmacs port is bundled in XEmacs setup.exe available from
XEmacs site.
o Pure Native Windows port
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/ => Emacs resource page
Emacs Perl Modules
Cperl -- Perl programming mode
ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
http://www.perl.com/CPAN-local/misc/emacs/cperl-mode/
<ilya@math.ohio-state.edu> Ilya Zakharevich
CPerl is major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Grep through all Perl manpages (.pod)
o Follow POD references e.g. [perlre] to next pod with RETURN
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o Update `$VERSION' variable with YYYY.MMDD on save.
o Load source code into Emacs, like Devel::DProf.pm
o Prepare script (version numbering) and Upload it to PAUSE
o Generate autoload STUBS (Devel::SelfStubber) for you
Perl Module (.pm)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in Tiny Tools Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up dattabases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to to do the search, You can adjust
recursive grep options, set search case sensitivity, add user grep
options etc.
You can find latest `igrep.el' module at
<http://groups.google.com/groups?group=gnu.emacs.sources> The
maintainer is Jefin Rodgers <kevinr@ihs.com>.
TinyCompile -- To Browse grep results in Emacs *compile* buffer
TinyCompile is a minor mode for *compile* buffer from where
you can collapse unwanted lines or shorten file URLs:
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Thu, 10 Jul 2003 05:02:22 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Fastest way to build a hash
Message-Id: <Xns93B43D68554D7sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
fischerlaender@gmx.de (Stefan Fischerländer) wrote in
news:ff9bee6c.0307091528.5d0b71a1@posting.google.com:
> I've got the following situation:
>
> My data is stored in a file; 5 bytes form one record. The bytes 0 to 3
> are a long integer, which is regarded as the key, wheras byte 4 is the
> value. I have to read this data structure into a hash.
Okay, this is the fastest I've come up with yet:
open IN, $input_file or die "Can't read $input_file: $!\n";
$/ = \5; # set input record length to 5 bytes
my %hash;
$hash{$_} = chop while <>;
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPw05oGPeouIeTNHoEQLEJQCeOrZcMu9ceouRfivT5bz9eets4p0AoOLK
bBOBbyl+MuwqMJotm3qZJaDn
=67OR
-----END PGP SIGNATURE-----
------------------------------
Date: 10 Jul 2003 04:01:45 -0700
From: fischerlaender@gmx.de (=?ISO-8859-1?Q?Stefan_Fischerl=E4nder?=)
Subject: Re: Fastest way to build a hash
Message-Id: <ff9bee6c.0307100301.4403e8d7@posting.google.com>
Benjamin Goldberg <ben.goldberg@hotpop.com> wrote in message news:<3F0CD454.F9F30C23@hotpop.com>...
> How fast/slow is the following program:
> open(IN,"<file") or die;
> keys(%hash) = (-s IN) / 5; # try /4, /3, /2, /1 instead of /5.
> while(read IN, $buf, 4) {
> $hash{$buf} = getc IN;
> }
> close(IN);
> __END__
First, I have to apologize; the numbers I gave you about the running
time were wrong: My initial version takes 3.1 seconds to read about
400.000 recods.
Your program is definitely faster: It needs only 2.2 seconds to read
the same amount of data into the hash.
> Note that I left out the unpack(), since doing so makes the hash keys
> smaller, and thus use less memory, and also, they're'll be fewer hash
> collisions, which should also speed up the program.
This is what made the program faster, not the pre-allocation of memory
for the hash.
Thank you for your answer.
Stefan
------------------------------
Date: 10 Jul 2003 04:22:29 -0700
From: fischerlaender@gmx.de (=?ISO-8859-1?Q?Stefan_Fischerl=E4nder?=)
Subject: Re: Fastest way to build a hash
Message-Id: <ff9bee6c.0307100322.3c427741@posting.google.com>
"Eric J. Roode" <REMOVEsdnCAPS@comcast.net> wrote in message news:<Xns93B3DAF493414sdn.comcast@206.127.4.25>...
> > Untested, but my first thought is:
> >
> > $/ = undef;
> > $raw = <IN>; # slurp whole file
> > %hash = $raw =~ /(....)(.)/gs; # split into 4, 1 byte pairs
>
> On second thought, splitting the whole file up into pairs and then
> assigning it to a hash is a waste, I think. Perhaps:
>
> $/ = undef;
> $raw = <IN>;
> $hash{$1} = $2 while $raw =~ /(....)(.)/gs;
Both programs work, but unfortunately they need exactly as long as my
initial program needs.
Thank you for your ideas anyway.
Stefan
------------------------------
Date: Thu, 10 Jul 2003 12:36:22 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: Fastest way to build a hash
Message-Id: <bejmk6$4g7$1@troll.powertech.no>
Stefan Fischerländer <fischerlaender@gmx.de> wrote:
> I've got the following situation:
>
> My data is stored in a file; 5 bytes form one record. The bytes 0 to 3
> are a long integer, which is regarded as the key, wheras byte 4 is the
> value. I have to read this data structure into a hash.
>
> What I'm doing at the moment is:
> open(IN,"<file");
> while(read(IN, $buf, 5))
> {
> $hash{unpack("L", substr($buf,0,4))} = substr($buf,4,1);
> }
> close(IN);
>
> This takes about 5 seconds to read a file with about 100.000 records,
> which is to long for my needs. (Celeron 800, IDE 7200rpm)
( snip )
> Does anyone have any ideas how to build this hash faster? It would
> also be possible to change the format of the data file. I already did
> experiments with store and retrieve from the Storable module and with
> a permanent hash with DB_File. In both cases the data file grew, while
> the script was even slower.
You should store the data in a way that requires minimal processing to
build the hash. I tried using keys and values separated with newlines,
and built a similar hash in a little over 1 second with:
open my $fh, "hash.dat" or die;
undef $/;
my %hash = split /\n/, <$fh>;
--
Vlad
------------------------------
Date: 10 Jul 2003 06:02:56 -0700
From: fischerlaender@gmx.de (=?ISO-8859-1?Q?Stefan_Fischerl=E4nder?=)
Subject: Re: Fastest way to build a hash
Message-Id: <ff9bee6c.0307100502.18ed553@posting.google.com>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnbgpi40.rlm.mgjv@martien.heliotrope.home>...
> my ($key, $val) = unpack "La1", $buf;
> $hash{$key} = $val;
As fast/slow as my initial code.
> %hash = %hash, unpack "La1", $buf;
Much slower!
> open(IN, "file") or die $!;
> my $n_bytes = -s IN;
> my $pack_template = "La1" x ($n_bytes/5);
> read(IN, $buf, $n_bytes); # do error checking
> %hash = unpack $pack_template, $buf;
This one is faster. With an additional
keys(%hash) = (-s IN)/5;
runtime decreases from 3.2 to 1.9 seconds.
> %hash = do {
> local ($/, *IN);
> open(IN, "file") or die $!;
> my $n_bytes = -s IN;
> my $pack_template = "La1" x ($n_bytes/5);
> unpack $pack_template, <IN>;
> };
A little bit slower than the code above: 2.4 seconds.
Thank you for your various ideas!
Stefan
------------------------------
Date: 10 Jul 2003 06:04:29 -0700
From: spamme@kirklarsen.com (Kirk Larsen)
Subject: Re: Find string in web page
Message-Id: <4628ab88.0307100504.3c4f6f9e@posting.google.com>
Can't seem to get it to work. It just outputs nothing. Am I doing
something wrong, or is there another way? I did print out my search
string var and verified that it is in the source I'm searching, so
that's not the problem. Thanks again!
gbacon@hiwaay.net (Greg Bacon) wrote in message news:<vgovst6ppdil2d@corp.supernews.com>...
> In article <4628ab88.0307091019.17e73755@posting.google.com>,
> Kirk Larsen <spamme@kirklarsen.com> wrote:
>
> : Sounds simple enough. I need to retrieve the source from a web page
> : and then find a link in that web page that ends with a string which I
> : have stored in a variable. Can someone please post or direct me to a
> : sample of how to do this? Thanks!
>
> Try this on for size:
>
> % cat try
> #! /usr/local/bin/perl
>
> use strict;
> use warnings;
>
> use HTML::Parser;
> use LWP::UserAgent;
> use URI::URL;
> use Data::Dumper;
>
> sub make_parser {
> my $inside;
> my %attr;
> my $text;
> my @links;
>
> my $record = sub {
> my $state = Dumper {
> inside => $inside,
> attr => \%attr,
> text => $text,
> };
>
> my @cond = (
> [ sub { $state }, "not inside" ],
> [ sub { %attr }, "no attr" ],
> [ sub { $attr{href} }, "no href" ],
> );
>
> my $ok = 1;
> for (@cond) {
> my($check,$msg) = @$_;
>
> unless ($check->()) {
> warn "$0: $msg:\n$state ";
> $ok = 0;
> }
> }
>
> push @links => [ $text || '<empty>', $attr{href} ] if $ok;
>
> $inside = 0;
> %attr = ();
> $text = '';
> };
>
> my $start_h = sub {
> my $tag = shift;
> return unless $tag eq 'a';
>
> if ($inside) {
> warn "$0: already inside";
> $record->();
> }
>
> my $attr = shift;
> return unless $attr->{href};
>
> %attr = %$attr;
> $inside = 1;
> };
>
> my $text_h = sub {
> return unless $inside;
>
> $text .= shift;
> };
>
> my $end_h = sub {
> my $tag = shift;
> return unless $tag eq 'a';
>
> return unless $inside;
>
> $record->();
> };
>
> my $p = HTML::Parser->new(
> api_version => 3,
> start_h => [ $start_h, "tagname, attr" ],
> text_h => [ $text_h, "dtext" ],
> end_h => [ $end_h, "tagname" ],
> );
>
> ($p, sub { @links });
> }
>
> sub usage () { "Usage: $0 search-pattern\n" }
>
> ## main
> die usage unless @ARGV;
>
> my $pat = shift;
> my $lookfor = eval { qr/$pat/ };
> die "$0: bad pattern: $pat" unless $lookfor;
>
> my $url = "http://www.cpan.org/";
> my $ua = LWP::UserAgent->new;
>
> my($p,$links) = make_parser;
>
> # Request document and parse it as it arrives
> my $res = $ua->request(
> HTTP::Request->new(GET => $url),
> sub { $p->parse($_[0]) }
> );
>
> my $base = $res->base;
> for ($links->()) {
> my($text,$href) = @$_;
>
> next unless $text =~ /$lookfor$/;
>
> my $url = url($href, $base)->abs;
>
> $text =~ s/\s+/ /g;
> print "$text:\n $url\n";
> }
> % ./try 's$'
> Perl modules:
> http://www.cpan.org/modules/index.html
> Perl scripts:
> http://www.cpan.org/scripts/index.html
> Perl recent arrivals:
> http://www.cpan.org/RECENT.html
> CPAN sites:
> http://www.cpan.org/SITES.html
> CPAN sites:
> http://mirrors.cpan.org/
> CPAN modules, distributions, and authors:
> http://search.cpan.org/
> CPAN Frequently Asked Questions:
> http://www.cpan.org/misc/cpan-faq.html
> Perl Mailing Lists:
> http://lists.cpan.org/
> Perl Bookmarks:
> http://bookmarks.cpan.org/
> % ./try '('
> ./try: bad pattern: ( at ./try line 95.
>
> Hope this helps,
> Greg
------------------------------
Date: Thu, 10 Jul 2003 11:36:52 +0200
From: Christophe Baegert <cbaegert-pas-de-spam@europeanservers.net>
Subject: Re: Hanging pipes in CGI Perl
Message-Id: <bejc3p$1s1d$1@biggoron.nerim.net>
Does anybody knows a reason why this program hangs ?
Christophe Baegert a écrit :
> Hello,
>
> Bob Walton wrote:
>
>
>>*please* copy/paste working code, don't just type it in!!!
>
>
> Sorry, this is my prog A.
> -----------------------------------------------------------------------------
> #!/usr/local/bin/perl
> use warnings;
> $|=1;
> print "Content-type: text/html\n\ntest";
> $text="To: xxxx\@yyyyy.zzz\nFrom: xxxx\@yyyyy.zzz\nSubject: test\n\ntest";
>
> open(MAIL,'|/home/xxx/cgi-bin/B.pl') or die "error : $!";
> print MAIL $text;
> close MAIL;
> -----------------------------------------------------------------------------
>
> This is my prog B.
> -----------------------------------------------------------------------------
> #!/usr/local/bin/perl
>
> open(FILE,'>/tmp/file') or die "$!";
> while($line=<STDIN>){
> print FILE $line;
> }
> close FILE;
> -----------------------------------------------------------------------------
>
> It runs well under bash, but it displays nothing, without error and without
> exiting under CGI.
>
> When I comment the last three lines of prog A, it runs well even under CGI.
>
> Regards,
>
> Christophe.
------------------------------
Date: Thu, 10 Jul 2003 09:35:29 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Help with Perl Script
Message-Id: <3f0d3305.1470030078@news.cis.dfn.de>
On Wed, 9 Jul 2003 11:32:53 -0500, "William Alexander Segraves"
<wsegrave@mindspring.com> wrote:
>Let's see if I understand your logic. You have a problem
>which you steadfastly refuse to describe to me. I am not
>able to glean enough relevant clues from your posting
>to improve on your definition of the problem; so I
>am an unhelpful nitwit.
Bill, this message was a joke, a sarcastic paraphrasing
of the earlier one from *Robert*.
It goes to show what can happen when people
forget or refuse to use smileys.
------------------------------
Date: Thu, 10 Jul 2003 05:46:55 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Help with Perl Script
Message-Id: <bejgoc$1ln$1@slb9.atl.mindspring.net>
"Helgi Briem" <helgi@decode.is> wrote in message
news:3f0d3305.1470030078@news.cis.dfn.de...
> On Wed, 9 Jul 2003 11:32:53 -0500, "William Alexander Segraves"
> <wsegrave@mindspring.com> wrote:
<snip>
>
> Bill, this message was a joke, a sarcastic paraphrasing
> of the earlier one from *Robert*.
>
Thanks, Helgi.
I was just trying to show what can happen when people use twisted logic to
duck the responsibility for their own inadequacies.
> It goes to show what can happen when people
> forget or refuse to use smileys.
Indeed. I should have used a smiley myself. :-)
Cheers.
Bill Segraves
------------------------------
Date: 10 Jul 2003 07:39:31 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: hi people
Message-Id: <bej57j$a97$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Irfan Shaikh:
> can some body tell me confiduring newsgroup in my netscape outlook.
^^^^^^^^^^^^^^^^
Eh? ;-)
> I added this site in newsgroup but when I am saying subscribe it give
> me an error saying that cant reach to host?
Sorry, this is way off-topic for this group. Please consult google or so
to get some help on this error message. You've probably given a wrong
newsserver.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Thu, 10 Jul 2003 20:38:05 +1000
From: Cat <cat@no-spam.com>
Subject: Re: How to do SSL FTP?
Message-Id: <3F0D420D.7919644D@no-spam.com>
"J. Gleixner" wrote:
>
> Brian wrote:
> > I am able to use Net::FTP fine. I have new requirements to create
> > secure FTP using SSL. SSH or SCP is not suitable due to FTP server.
> > How do I create SSL FTP?
> >
> > Thanks.
> >
> Net::SFTP
Really?
Ref: http://search.cpan.org/author/BTROTT/Net-SFTP-0.05/lib/Net/SFTP.pm
Net::SFTP is a pure-Perl implementation of the Secure File Transfer Protocol (SFTP)--file transfer built on top of the SSH protocol.
Net::SFTP uses Net::SSH::Perl to build a secure, encrypted tunnel through which files can be transferred and managed.
------------------------------
Date: 10 Jul 2003 05:17:11 -0700
From: google@asktoby.com (Toby Newman)
Subject: Re: Matt's Simple Search - a new angle?
Message-Id: <25a29397.0307100417.5caa7b5e@posting.google.com>
Simon Andrews <simon.andrews@bbsrc.ac.uk> wrote in message news:<3F0BCFA5.5060203@bbsrc.ac.uk>...
> >>Toby Newman wrote:
>
> [about wanting to use Matts search script]
>
> >>>I'd like it to search through *.wiki files (they're just text files)
> >>>in '/home/wiki/', i.e. not inside my public_html folder.
> >>>
> >>>It doesn't seem to work!
>
> [snip parameters used]
>
> >>>
> >>>I get no results.
> >>>
> >>>Why could this be?
> >>>
>
> From: "Cat" <cat@no-spam.com>
> >>Do you have permission to view the contents of /home/wiki ?
> >>Do you get any results with ls /home/wiki/*.wiki ?
> >>Are you executing the script from a web page ?
>
>
> > Toby Newman wrote:
> >
> > Hi! Thank you for your response.
> >
> > I have asked Matt but he does not reply! I am hoping someone in this
> > discussion group will have a clue for me :)
>
>
> Toby,
>
> Just to explain a couple of the responses you've had to your original
> post, and the general lack of specific help.
>
> You're using a script from Matts script archive. Those scripts are
> a continual source of problems here. They were written a long time
> ago and have been shown to contain many bugs, and in some cases
> potential sectrity holes. Where bugs have been pointed out to Matt
> he has failed to provide updated versions of his scripts and
> continued to distribute the old code. You are unlikely to get help
> fixing Matts scripts as the regulars here have been over this ground
> too many times :-)
>
> On a positive note, a while back the London Perl Mongers group
> decided to rewrite Matts scripts from scratch, providing their
> own alternatives which were a drop in replacement for the originals
> but which fixed the bugs and were more secure. Even Matts site
> now acknowedges that people should be using these versions of the
> scripts.
>
> You can get a new version of the search program from:
>
> http://sourceforge.net/projects/nms-cgi/
>
> You may find that this version will fix the problem you're having
> or it may not, but you're much more likely to get help here if
> you're using the NMS version of the script as a least there should
> be no major bugs in it. You may find that even if it doesn't work
> it may give more informative error messages than the original.
>
> As an aside, I'm not familiar with the layout of Wiki documents, but
> it's possible that the search script is looking for certain HTML tags
> to define which parts of each document to search. If these aren't
> present in the Wiki pages then the script may fail because of that.
>
> Are you able to check your server error logs when the script runs?
> Are there any messages reported?
>
> Hope this gets you a bit further.
>
> Cheers
>
> Simon.
Simon, thankyou for your reasoned and helpful response. I'd like to
apologise to the group for picking the MSA scab and making it sore!
Maybe I can redeem myself with the below :)
I switched to the NMS script and after a litte tweaking I got it
working perfectly. I also made some changes to the script so that it
doesn't return file extensions nor the / slash between the $baseurl
and the $paths.
For example, this may be helpful for working with php pages such ask
where $baseurl is:
http://www.blah.com/page.php?action=
and $paths is:
view.wiki
The original script would return:
http://www.blah.com/page.php?action=/view.wiki
but now will return
http://www.blah.com/page.php?action=view
The changes I made were:
if (!$emulate_matts_code)
{
my @base = sort {$hits[$b] <=> $hits[$a]} (0 .. $#hits);
@titles = @titles[@base];
@paths = @paths[@base];
for my $i (0 .. $#hits)
{
print_result($baseurl, $paths[$i], $titles[$i])
if ($hits[$i] >= $hit_threshhold);
print "<a href=";#begin link
print ($baseurl);#output pages URL
$paths[$i] =~ s/\.wiki//gi;#stip extension from path
print ($paths[$i]);#output path
print ">link</a>";#close link
}
}
'tis all. Thanks for the help folks!
Toby Newman
------------------------------
Date: Thu, 10 Jul 2003 07:12:27 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: perl restaurant menu
Message-Id: <mbudash-33C077.00123010072003@typhoon.sonic.net>
In article <Xns93B3EBC5AEB1Amreedreedassociatesc@216.168.3.44>,
Mark Reed <mreed@reedassociates.com> wrote:
> johndageek@yahoo.com (John D) wrote in
> news:c608545f.0307080925.458c0db1@posting.google.com:
>
> > Mark Reed <mreed@reedassociates.com> wrote in message
> > news:<Xns93B1C8BA3E302mreedreedassociatesc@216.168.3.44>...
> >
> >> Does anyone have a perl script that can be used to manage an online
> >> restaurant menu?
> >>
> >> Im looking for examples to study and cant find any on the net at the
> >> popular archives.
>
> > Please take a shot at it and we can help you out with any perl
> > probelms you may encounter.
> >
> > A little more definition might help also.
> > "Manage an online resteraunt menu"
> > -do you want code to run an online store?
> > -do you want code to display a menu only
> > -do you want a page to be displayed based upon a database
> > (implying a method to maintain the database entries)
> > -do you have experience with databases, cgi, javascript and web
> > servers?
>
> I'm basically looking for the ability to have one public page where it
> displays the menu by category. For example:
>
> Appetizers-----
> item 1 description Price
> item 2 etc...
>
> Lunch
> Item 1 etc...
>
> it would be a simple display of a restaurants menu.
>
> The second part would be an admin back end where the restaurant owner can
> manage the menu - add items, change items, delete items... etc..
>
> The only experience i have with Perl or MySql is setting up canned
> scripts from the net - and after searching everywhere, to my surprise, I
> cannot find any canned scripts for this.
>
> Where would you suggest I start? I assume a book on Perl basics, or
> would PHP be better for this?
if you don't already know how to do this kind of thing, it's probably a
good project to start with.
start with the db. the mysql db should look something like this:
"Category" table:
categoryID int(11) not null primary key auto_increment,
category varchar(50),
categoryDisplayOrder int(3)
"Item" table:
itemID int(11) not null primary key auto_increment,
categoryID int(11),
item varchar(50),
itemDescription mediumtext,
itemPrice decimal(7,2),
itemDisplayOrder int(3)
(the 'displayOrder' fields are to ordering the categories and items
within the categories.)
next: simplest, though not the easiest for the restaurant owner's admin
section: get phpmyadmin.
finally, a php or perl script would be easy to write to display the
menu. psuedocode (no html):
SELECT * FROM CATEGORY ORDER BY categoryDisplayOrder, category
foreach (categoryResultrow) {
print categoryResultrow->category
print "\n"
thisCategoryID = categoryResultrow >categoryID;
SELECT * FROM ITEM WHERE categoryID=thisCategoryID ORDER BY
itemDisplayOrder, item
foreach (itemResultrow) {
print itemResultrow->item
print "\t"
print itemResultrow->itemDescription
print "\t"
print itemResultrow->itemPrice
print "\n\n"
}
}
NOTE: this is NOT meant to be working code or a complete solution - just
something to get you started.
hth-
--
Michael Budash
------------------------------
Date: 10 Jul 2003 07:18:33 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: string question
Message-Id: <slrnbgq4q9.q8r.abigail@alexandra.abigail.nl>
john62@electronmail.com (john62@electronmail.com) wrote on MMMDC
September MCMXCIII in <URL:news:3f0cee2b$1_2@127.0.0.1>:
\\ i am a perl novice, and i have a really simple question.
\\ what is the easiest way to tell if a string begins with "Re:
\\ " (without the quotes)?
if ("Re:" eq substr $str => 0, 3) {
...
}
Abigail
--
($;,$_,$|,$\)=("\@\x7Fy~*kde~box*Zoxf*Bkiaox"," "x25,1,"\r");
{vec($_=>1+$"=>$^F<<$^F)=ord($/^substr$;=>$"=int rand 24=>1);
print&&select$,,$,,$,,$|/($|+tr/ //c);redo if y/ //>$^F**2};
------------------------------
Date: Thu, 10 Jul 2003 03:43:58 -0500
From: "J. Smith" <charlie_baratski@yahoo.com>
Subject: Re: string question
Message-Id: <vgq9qatj61rqe6@corp.supernews.com>
Why use "while/last" when you mean "if"?
--Because I didn't mean "if". <-ESP? I meant "while".
Why use "$&" when by definition its value is "Re:"?
--Yes. It's definition is "Re:", but not until it returns true, and I wanted
to see it. I printed out exactly what I wanted to see. john62 doesn't HAVE
to do that.
Why use \" in a ""ed string, when you could use qq{} or similar?
--It's my preference. I Ran it in a console window. It would've died.
Go have sex or something Sam. You need to relax.
And please answer this poor man's question.
I'm obviously not qualified.
"There's more than one way to do it"
"Sam Holden" <sholden@flexal.cs.usyd.edu.au> wrote in message
news:slrnbgq3pt.h76.sholden@flexal.cs.usyd.edu.au...
> On Thu, 10 Jul 2003 01:18:09 -0500,
> J. Smith <charlie_baratski@yahoo.com> wrote:
> > while($string =~ /^Re:/) {
> >
> > print "$string contains \"$&\"\n";
> > # Do other stuff...
> >
> > last;
> >
> > }
>
> Why use "while/last" when you mean "if"?
>
> Why use "$&" when by definition its value is "Re:"?
>
> Especially considering the notes in the perlvar documentation
> about this var.
>
> TIMTOWTDI and all, that method is just madness.
>
> Why use \" in a ""ed string, when you could use qq{} or similar?
>
> snip TOFU - please don't do that.
>
> --
> Sam Holden
>
------------------------------
Date: Thu, 10 Jul 2003 12:50:32 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: Total Butt Heads in this news group
Message-Id: <20030710125032.4bd0d759.john.thetenant-s@moving-picture.com>
On Mon, 7 Jul 2003 20:21:13 -0500
tadmc@augustmail.com (Tad McClellan) wrote:
>
> Robert <yyyy@yyy.com> wrote:
>
> > Subject: Total Butt Heads in this news group
>
>
> That is true.
>
> History has shown that you don't hang around here for long though.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
if all of us affirmed our butt-headedness and nitwittedness
in every posting, this newsgroup would be a better place.
there's no point denying it, now that we've been outted.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 5209
***************************************