[18875] in Perl-Users-Digest
Perl-Users Digest, Issue: 1043 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 2 11:10:31 2001
Date: Sat, 2 Jun 2001 08:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <991494611-v10-i1043@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 2 Jun 2001 Volume: 10 Number: 1043
Today's topics:
regular expressions to convert link <raphaelp@nr1webresource.com>
Re: regular expressions to convert link <godzilla@stomp.stomp.tokyo>
Re: regular expressions to convert link (Tad McClellan)
Re: Silly pipe() question (Abigail)
Re: slides (Abigail)
Re: Stepping through with tr/// (Abigail)
Re: UPDATE & for loop (bin)
Re: xslint <der.prinz@gmx.net>
Re: xslint (Eric Bohlman)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 2 Jun 2001 13:02:02 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: regular expressions to convert link
Message-Id: <9fagqi$s84$04$1@news.t-online.com>
Hi guys,
I'm having the following problem:
I need to make a link which originally looks like this in the variable
<a target="_blank" href="http://www.nr1webresource.com/forums/index.php"
onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
onMouseOver="swapImage('forums','forums_on'); show('l_forum');">
into something like this:
<a target="_blank"
href="javascript:external('http://www.nr1webresource.com/forums/index.php')"
onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
onMouseOver="swapImage('forums','forums_on'); show('l_forum');">
I don't have any clue as to how to do this, I read several regular
expression tutorials but there seems to be no answer to the problem... Could
any of you guys help out and provide a solution or at least a few hints?
TIA,
Raphael
------------------------------
Date: Sat, 02 Jun 2001 07:50:55 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: regular expressions to convert link
Message-Id: <3B18FD4F.CF55D0F6@stomp.stomp.tokyo>
Raphael Pirker wrote:
(snippage)
> I need to make a link which originally looks like this in the variable
> <a target="_blank" href="http://www.nr1webresource.com/forums/index.php"
> onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
> onMouseOver="swapImage('forums','forums_on'); show('l_forum');">
> into something like this:
> <a target="_blank"
> href="javascript:external('http://www.nr1webresource.com/forums/index.php')"
> onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
> onMouseOver="swapImage('forums','forums_on'); show('l_forum');">
Be careful not to use an expression, "...something like this:" for
your articles. If I chose to be ornery, I could provide an incorrect
answer and state, "There you go. This is something like what you want."
Programming is an exacting science. Use equally exacting terminology.
Below my signature you will find two methods to accomplish this.
One method is significantly more efficient than the other. Can
you guess which is more efficient?
My first method uses a regex:
$string =~ s/(href=")(.*)(")/$1javascript:external('$2')$3/;
This regex can be written in a number of different ways. This
is the method I chose to use. In essence, this regex means:
substitute:
href=" anything up to and including the next quote mark with this...
There is a note of caution. If the quote mark after index.php
was located elsewhere, this regex would mess up, especially
if you use a g switch for global. Should you encounter something
like this, use an anchor. In this case of a g switch, a question
mark ? would be appropriate anchor to use.
Read about and research use of anchors for regex methods.
I will also encourage you to look at use of substring instead
of use of a regex when possible.
Godzilla!
--
#!perl
print "Content-type: text/plain\n\n";
$string = qq(
<a target="_blank" href="http://www.nr1webresource.com/forums/index.php"
onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
onMouseOver="swapImage('forums','forums_on'); show('l_forum');">);
$string =~ s/(href=")(.*?)(")/$1javascript:external('$2')$3/;
print "Regex:\n\n$string\n\n\n";
$string = qq(
<a target="_blank" href="http://www.nr1webresource.com/forums/index.php"
onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
onMouseOver="swapImage('forums','forums_on'); show('l_forum');">);
$start = index ($string, "href=\"");
substr ($string, $start, 6, "http=\"javascript:external('");
substr ($string, index ($string, "\"", $start + 6), 1, "')\"");
print "Substring:\n\n$string";
exit;
PRINTED RESULTS:
(careful about word wrap)
________________
Regex:
<a target="_blank"
href="javascript:external('http://www.nr1webresource.com/forums/index.php')"
onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
onMouseOver="swapImage('forums','forums_on'); show('l_forum');">
Substring:
<a target="_blank"
http="javascript:external('http://www.nr1webresource.com/forums/index.php')"
onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
onMouseOver="swapImage('forums','forums_on'); show('l_forum');">
BENCHMARK COMPARISON:
_____________________
#!perl
print "Content-type: text/plain\n\n";
use Benchmark;
print "Run One:\n\n";
&Time;
print "\n\nRun Two:\n\n";
&Time;
print "\n\nRun Three:\n\n";
&Time;
sub Time
{
timethese (100000,
{
'name1' =>
sub {
$string = qq(
<a target="_blank" href="http://www.nr1webresource.com/forums/index.php"
onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
onMouseOver="swapImage('forums','forums_on'); show('l_forum');">);
$string =~ s/(href=")(.*)(")/$1javascript:external('$2')$3/;},
'name2' =>
sub {
$string = qq(
<a target="_blank" href="http://www.nr1webresource.com/forums/index.php"
onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
onMouseOver="swapImage('forums','forums_on'); show('l_forum');">);
$start = index ($string, "href=\"");
substr ($string, $start, 6, "http=\"javascript:external('");
substr ($string, index ($string, "\"", $start + 6), 1, "')\"");},
} );
}
exit;
PRINTED RESULTS:
________________
Run One:
Benchmark: timing 100000 iterations of name1, name2...
name1: 2 wallclock secs ( 3.07 usr + 0.00 sys = 3.07 CPU) @ 32573.29/s
name2: 2 wallclock secs ( 1.04 usr + 0.00 sys = 1.04 CPU) @ 96153.85/s
Run Two:
Benchmark: timing 100000 iterations of name1, name2...
name1: 3 wallclock secs ( 3.08 usr + 0.00 sys = 3.08 CPU) @ 32467.53/s
name2: 0 wallclock secs ( 1.04 usr + 0.00 sys = 1.04 CPU) @ 96153.85/s
Run Three:
Benchmark: timing 100000 iterations of name1, name2...
name1: 3 wallclock secs ( 3.02 usr + 0.00 sys = 3.02 CPU) @ 33112.58/s
name2: 1 wallclock secs ( 1.04 usr + 0.00 sys = 1.04 CPU) @ 96153.85/s
------------------------------
Date: Sat, 2 Jun 2001 07:55:57 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regular expressions to convert link
Message-Id: <slrn9hhl2d.b5a.tadmc@tadmc26.august.net>
Raphael Pirker <raphaelp@nr1webresource.com> wrote:
>
>I need to make a link which originally looks like this in the variable
>
><a target="_blank" href="http://www.nr1webresource.com/forums/index.php"
>onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
>onMouseOver="swapImage('forums','forums_on'); show('l_forum');">
>
>into something like this:
>
><a target="_blank"
>href="javascript:external('http://www.nr1webresource.com/forums/index.php')"
>onMouseOut="swapImgRestore('forums','forums_off'); hide('l_forum');"
>onMouseOver="swapImage('forums','forums_on'); show('l_forum');">
s/(href\s*=\s*")([^"]+)/$1javascript:external('$2')/i;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 2 Jun 2001 13:45:25 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Silly pipe() question
Message-Id: <slrn9hhrfl.igv.abigail@tsathoggua.rlyeh.net>
Benjamin Goldberg (goldbb2@earthlink.net) wrote on MMDCCCXXIX September
MCMXCIII in <URL:news:3B157045.EBEB80A5@earthlink.net>:
{}
{} Did it pollute the global namespace when the three-argument version of
{} open() was added to perl? No, because it didn't add a new name, just a
{} new method of using an old name.
pipe() already has a return value - success or not; you'd lose that.
You then need to do something like returning an empty list, and
checking the number of arguments returned.
Now pipe() acts like most (all?) "system" functions: return true on
success, false on failure. There's hardly a difference in key strokes
in where the variables go, I've a hard time imagining a situation where
you would want to use the return values of pipe() as argument to
another function, so there's not much to gain there. But losing the
consistency is a loss.
Furthermore, if pipe() would be argument less, returning both sides of
the pipe(), how should such a modified pipe act in scalar context?
Abigail
--
@;=split//=>"Joel, Preach sartre knuth\n";$;=chr 65;%;=map{$;++=>$_}
0,22,13,16,5,14,21,1,23,11,2,7,12,6,8,15,3,19,24,14,10,20,18,17,4,25
;print@;[@;{A..Z}];
------------------------------
Date: Sat, 2 Jun 2001 13:49:23 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: slides
Message-Id: <slrn9hhrn3.igv.abigail@tsathoggua.rlyeh.net>
antoine (tonio@punk-ass.co.uk) wrote on MMDCCCXXXI September MCMXCIII in
<URL:news:3B178B09.73C97E7C@punk-ass.co.uk>:
// Hi,
//
// I've just been informed that I'll have to give a 5 days Perl tutorial
// starting on monday and I have no time to prepare slides. Does anyone
// know where I could get some slides for this?
I'd say the right slides depend a lot on what other materials you have.
I gave a Perl course last week (also with a few days of notice), didn't
use any slides. Used the computer + beamer only once, when showing how
to use CPAN.pm. I did use the whiteboard all the time though. ;-)
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: Sat, 2 Jun 2001 10:25:18 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Stepping through with tr///
Message-Id: <slrn9hhfoe.igv.abigail@tsathoggua.rlyeh.net>
Tad McClellan (tadmc@augustmail.com) wrote on MMDCCCXXXI September
MCMXCIII in <URL:news:slrn9hgamj.a4u.tadmc@tadmc26.august.net>:
&& #!/usr/bin/perl -w
&& use strict;
&&
&& my $j = "51838182 21626382423273 71327353 422123523273," ;
&&
&& my %decoder = (
&& 2 => [qw/a b c/],
&& 3 => [qw/d e f/],
&& 4 => [qw/g h i/],
&& 5 => [qw/J k l/],
&& 6 => [qw/m n o/],
&& 7 => [qw/P q r/],
&& 8 => [qw/s t u/],
&& 9 => [qw/v w x/],
&& 0 => [qw/y z/],
&& );
&&
&& $j =~ s/(\d)(\d)/$decoder{$1}[$2-1]/g;
&&
&& print "$j\n" ;
&& ----------------------------
&&
&&
&& But that is not satisfyingly obfuscated...
@& = map {[split//]} q//, q//, qw/aacb eeedf hHgi Jlk nom rPrrq ustt vwx yz/;
$_ = "5888 2668437 7375 422537,";
s/\d/shift@{$&[$&]}/eg&&print;
Abigail
--
my $qr = qr/^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: 2 Jun 2001 07:54:14 -0700
From: givemeonly@hotmail.com (bin)
Subject: Re: UPDATE & for loop
Message-Id: <ac020fec.0106020654.61b1de59@posting.google.com>
> One thing is that perhaps you want something more like
>
> my $periodid = shift(@rows);
> my @park = @rows;
>
> With what you currently have, you will never have more than one thing in
> @park, which may be the source of your error. Another potential snafu is
> that fetchrow_array only returns the columns of a single row, you may
> actually be looking for fetchall_array, which returns an array reference to
> all the rows in the result set. Hope this helps --
Thank you for your answer but I think that I have found the problem. I
am trying to update values in a database and the period_id is not
unique. So it tries to update the parkdate with the same period_id
thus only the last date will appear in the database for x times. Is
there a way to UPDATE one row at a time and then to change the next
row.
for (my $i = &firstday(@park); $i <= &lastday(); $i += 604800){
my $old_park_date = localtime($i);
my $parkdate = UnixDate(($old_park_date), "%Y-%m-%d");
print $periodid . " " . $parkdate . "\n";
my $sql4 = "UPDATE temp_period SET start_park='$parkdate' WHERE
period_id='$periodid'";
my $sth4 = $dbh->prepare($sql4);
$sth4->execute or die "error in sql" .$dbh->errstr;
}
}# End loop;
------------------------------
Date: Sat, 2 Jun 2001 12:05:10 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: xslint
Message-Id: <3b18ba32$1@e-post.inode.at>
Tim <timster@worldnet.att.net> wrote:
> I want to download the xslint tool by Norman Walsh. The accompanying
> document says it needs XML::Parser and XML::DOM to run it. I downloaded
> XML::Parser from CPAN, but its README says that it needs the Expat
> module. I downloaded that. Then the Expat's README says that it needs
> 5 other modules, and so on...... Argh! Isn't there a document that
> shows ALL dependencies of ALL Perl modules? Is there an easier way to do
> this? In particular...the xslint module?
I don't know about xslint, but there is in fact an easier way to
install modules:
perl -MCPAN -e shell
If I am not mistaken, installing modules from the "CPAN shell" will
automatically install the modules/bundles they depend on.
cheers,
stefan
------------------------------
Date: 2 Jun 2001 13:43:29 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: xslint
Message-Id: <9faqi1$rdg$1@bob.news.rcn.net>
In comp.lang.perl.misc Stefan Weiss <der.prinz@gmx.net> wrote:
> Tim <timster@worldnet.att.net> wrote:
>> I want to download the xslint tool by Norman Walsh. The accompanying
>> document says it needs XML::Parser and XML::DOM to run it. I downloaded
>> XML::Parser from CPAN, but its README says that it needs the Expat
>> module. I downloaded that. Then the Expat's README says that it needs
>> 5 other modules, and so on...... Argh! Isn't there a document that
>> shows ALL dependencies of ALL Perl modules? Is there an easier way to do
>> this? In particular...the xslint module?
> I don't know about xslint, but there is in fact an easier way to
> install modules:
> perl -MCPAN -e shell
> If I am not mistaken, installing modules from the "CPAN shell" will
> automatically install the modules/bundles they depend on.
The problem here is that the latest version (2.30) of XML::Parser depends
on a version of Expat that isn't on CPAN (it's available from
SourceForge). Similar considerations apply to a number of the newer
XML::* modules.
------------------------------
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 1043
***************************************