[17188] in Perl-Users-Digest
Perl-Users Digest, Issue: 4600 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 12 18:16:01 2000
Date: Thu, 12 Oct 2000 15:15:26 -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: <971388926-v9-i4600@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 12 Oct 2000 Volume: 9 Number: 4600
Today's topics:
perl variables in html? <jbarnett@axil.netmate.com>
Re: perl variables in html? (Brett W. McCoy)
Re: perl variables in html? <nlymbo@mindspring.com>
Perl Watching Perl? rathmore@tierceron.com
Perl/Windows problem <cliffwilliams@eurobell.co.uk>
Re: Perl/Windows problem <godzilla@stomp.stomp.tokyo>
Re: re-start problem <ejw@windsor.igs.net>
Re: reading in file as uneven multi-dimensional array <kelley.a.kent@intel.com>
Re: reading in file as uneven multi-dimensional array <lr@hpl.hp.com>
Re: Reg exp help <cliffwilliams@eurobell.co.uk>
Re: Reg exp help <lr@hpl.hp.com>
Re: regular expression <cliffwilliams@eurobell.co.uk>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 12 Oct 2000 14:36:05 -0500
From: "Jack Barnett" <jbarnett@axil.netmate.com>
Subject: perl variables in html?
Message-Id: <suc4nfha4jt0d9@corp.supernews.com>
Say you have a small perl cgi script that opens an html and prints it out,
is there any way to put variables in the html and have them print out?
Small example (I didn't check the syntax on this, and didn't try to run it,
but you can get the basic idea).
#!/usr/bin/perl -w
my $file = "/tmp/page.html";
my $string1 = "This is string one";
my $string2 = "This is string two";
print ("Content-type: text/html\n\n");
open (PAGE, "<$file");
while (<PAGE>)
{ print ($_); }
close (PAGE);
exit();
PAGE.HTML file:
<HTML>
<HEAD><TITLE>Page Name</TITLE></HEAD>
<BODY>
<H2>Welcome</H2>
Hi, welcome to my first web page! I would like to tell you about:<BR><BR>
<B>$string1</B><BR>
<B>$string2</B><BR>
</BODY>
</HTML>
This (or somthing like it, I didn't check sytnax), prints out the html page,
and for "$string1" it has "$string1", is there any simple way of doing this
so that "$string1" would be converted into "This is string one" ? Maybe
though a module or something?
I know how it would work if I did something like (didn't check syntax on
this one either)
while (<PAGE>)
$_ =~ s/\$string1/$string1/g;
$_ =~ s/\$string2/$string2/g;
print ($_);
}
But if you have 10-30 varaiables to search in 1000+ 100 line html file, it
can get sloppy and/or really slow quickly.
Is there a fast and cleaner or "correct" way to go about doing this?
Thanks,
Jack
------------------------------
Date: Thu, 12 Oct 2000 20:20:49 GMT
From: bmccoy@chapelperilous.net (Brett W. McCoy)
Subject: Re: perl variables in html?
Message-Id: <slrn8uc7bq.g7m.bmccoy@chapelperilous.net>
On Thu, 12 Oct 2000 14:36:05 -0500, Jack Barnett
<jbarnett@axil.netmate.com> wrote:
> Say you have a small perl cgi script that opens an html and prints it out,
> is there any way to put variables in the html and have them print out?
>
> Small example (I didn't check the syntax on this, and didn't try to run it,
> but you can get the basic idea).
On Win32, you can use PerlScript within ASP to embed Perl in HTML. If you
have IIS available, ActiveState installs support for PerlScript
automatically. But you'll still need to learn the basics of ASP, which
should take, oh, about 5 minutes. Unfortunately, even with Perl, you
cannot get completely away from the Visual Basic/COM roots of ASP.
http://www.fastnetltd.ndirect.co.uk/Perl/Articles/PSIntro.html
On Unix, you can use EmbPerl (http://perl.apache.org/embperl/index.html)
or Mason (http://www.masonhq.com), or even Apache::ASP
(http://www.apache-asp.org) to embed Perl in HTML. I use Mason myself
quite a bit; coupled with mod_perl and DBI, you've got a very slick
development & content management/delivery system.
--
Brett W. McCoy
http://www.chapelperilous.net
---------------------------------------------------------------------------
It's easier to take it apart than to put it back together.
-- Washlesky
------------------------------
Date: Thu, 12 Oct 2000 16:28:26 -0400
From: "steveFarris" <nlymbo@mindspring.com>
Subject: Re: perl variables in html?
Message-Id: <8s56qm$jim$1@slb6.atl.mindspring.net>
The HTML::Template module handles this beautifully. See
http://search.cpan.org.
Jack Barnett <jbarnett@axil.netmate.com> wrote in message
news:suc4nfha4jt0d9@corp.supernews.com...
>
> Say you have a small perl cgi script that opens an html and prints it out,
> is there any way to put variables in the html and have them print out?
>
> Small example (I didn't check the syntax on this, and didn't try to run
it,
> but you can get the basic idea).
>
> #!/usr/bin/perl -w
>
> my $file = "/tmp/page.html";
> my $string1 = "This is string one";
> my $string2 = "This is string two";
>
> print ("Content-type: text/html\n\n");
>
> open (PAGE, "<$file");
> while (<PAGE>)
> { print ($_); }
> close (PAGE);
>
> exit();
>
>
> PAGE.HTML file:
>
> <HTML>
> <HEAD><TITLE>Page Name</TITLE></HEAD>
> <BODY>
>
> <H2>Welcome</H2>
>
> Hi, welcome to my first web page! I would like to tell you about:<BR><BR>
>
> <B>$string1</B><BR>
> <B>$string2</B><BR>
> </BODY>
> </HTML>
>
> This (or somthing like it, I didn't check sytnax), prints out the html
page,
> and for "$string1" it has "$string1", is there any simple way of doing
this
> so that "$string1" would be converted into "This is string one" ? Maybe
> though a module or something?
>
> I know how it would work if I did something like (didn't check syntax on
> this one either)
>
> while (<PAGE>)
>
>
> $_ =~ s/\$string1/$string1/g;
> $_ =~ s/\$string2/$string2/g;
> print ($_);
> }
>
> But if you have 10-30 varaiables to search in 1000+ 100 line html file, it
> can get sloppy and/or really slow quickly.
>
> Is there a fast and cleaner or "correct" way to go about doing this?
>
> Thanks,
> Jack
>
>
>
>
>
------------------------------
Date: Thu, 12 Oct 2000 21:40:19 GMT
From: rathmore@tierceron.com
Subject: Perl Watching Perl?
Message-Id: <8s5b42$75j$1@nnrp1.deja.com>
This promises to be a bit extended so I'll try to be as brief as
possible.
Is it possible to have a Perl program, fork another Perl program whose
purpose is to monitor the first program and restart it if it takes too
long to complete?
Here’s the background: I’ve written a Perl program that opens an FTP
connection to a remote server and downloads a file, then deletes that
file. The program does this on each file that matches some criteria—
there could be anywhere from 1 to over 20 files that need to be
downloaded then deleted. I’m using Net::FTP to handle the FTP
processing.
About 1 out of every 5 times that I do this, the program hangs within
the block that downloads the files and deletes them. From all
appearances, the program is patiently waiting for the next packet of
information to be received, which it never receives. This points to a
problem with the machine that the program is accessing, so the easy
answer is fix that machine; but the machine doesn’t belong to me and
the entity that owns the machine isn’t going to do anything to improve
or make the machine better. Besides that, I’m a program so I want to
code a solution.
Being new to Perl, I don’t know if you can do what I suggested in my
2nd paragraph in this post—fork another Perl program that is capable of
monitoring the program that called it, and have it reset that program
if it takes too long to complete.
I hope that the feedback you can give will not only confirm or refute
this approach, but will also have a few suggestions on how to implement
such a thing! (You don’t have to spell it out, but just enough to get
me started would be peachy.)
Thanks!
Rathmore
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 12 Oct 2000 20:02:16 +0100
From: "John Clifford Williams" <cliffwilliams@eurobell.co.uk>
Subject: Perl/Windows problem
Message-Id: <8s526g$1cjv$1@slrn.eurobell.net>
Hi
I've written a Perl script which is desgned to accept a .ATT file (email
attachment) as its input. I've been trying to set it up so that
double-clicking an ATT file's icon runs the script which in turn loads the
ATT file for processing, but Windows doesn't seem to like it when I try to
associate the .ATT file type with my script. Does anyone know how to do
this, or a way round it?
Thanks for any help!
Mark.
------------------------------
Date: Thu, 12 Oct 2000 12:32:12 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Perl/Windows problem
Message-Id: <39E611BC.127C51A1@stomp.stomp.tokyo>
John Clifford Williams wrote:
> I've written a Perl script which is desgned to accept a .ATT file (email
> attachment) as its input. I've been trying to set it up so that
> double-clicking an ATT file's icon runs the script which in turn loads the
> ATT file for processing, but Windows doesn't seem to like it when I try to
> associate the .ATT file type with my script. Does anyone know how to do
> this, or a way round it?
"...Windows doesn't seem to like it...."
What do you mean by this? Windows play scream.wav? Does
Windows Crash And Burn? Blow up your monitor? Your use
of "doesn't seem" indicates you don't know if there is
a problem or not. Is there a problem or is this a casual
comment of no value?
Add a path statement to your autoexec.bat as appropriate
for accessing your Perl setup. Associate .ATT with your
Perl setup using Window's carry over from powerful
Win 3.x's File Mangler. This File Manager can be
accessed here:
C:\WINDOWS\WINFILE.EXE
Do not modify your autoexec.bat unless you absolutely
know how to do this, correctly. You can cause serious
problems for boot if not written correctly. Be sure
to make a backup copy of your autoexec.bat before you
make any modifications. You will need to reboot for
a change to take effect.
Sequence of events is:
modify your autoexec.bat
reboot
associate .ATT with Perl
reboot (if needed determined by testing)
Should you wish to test this, discover if this will
cure your problem before modifying your autoexec.bat,
you may drop into a DOS window and set a path to your
Perl setup, then associate .ATT with Perl and test.
This would be most prudent as a first test action.
There is very little risk is involved doing this.
If you don't understand these procedures, don't
understand how to do these things, you will be
better off to learn to live with your problem
rather than risk causing serious boot-up problems.
Trying this test, is done so at your own risk.
No guarantee is made nor implied.
Godzilla!
--
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class
------------------------------
Date: Thu, 12 Oct 2000 14:21:18 -0400
From: "theomats" <ejw@windsor.igs.net>
Subject: Re: re-start problem
Message-Id: <8s4vi0$gk7$1@news.igs.net>
I think I figured out my own problem . I had 2 files bishops.htm and
instruct.htm (on old website) that I thought would do the same thing.
The one named instruct.htm was causing the problem.
So I redirected it to load bishops.htm in 4 seconds and the problem went
away.
The java files must have wanted the name to be bishops.htm. right ??
Visit www.bishopsthegame.com
theomats <ejw@windsor.igs.net> wrote in message
news:8rv7g4$dbg$1@news.igs.net...
> Is the bug in line 17 in the Bishops.java file ? or in the .cgi ?
>
> Not in touch lately with programmers so maybe I can fix it myself if you
> copy and paste correction.
>
> I am going through the java tutorials and how to make the .jar file but it
> is tough for me.
>
> When I extracted the Bishops.jar it made 20 Bishops.class files. ??
>
> Still learning how to resave the Bishops. jar as the Bishops.java can be
> changed but then it has to be made into a .jar somehow.
>
> Should I be using Notepad and then Wordpad if file too large ?
> or should I use Dos editor?
>
> Maybe the word "volunteer" is the terrible thing, :) but I am on a
> shoestring budget until things get rolling with the game.
>
> Anyone know any "banner ads" that would pay to have a banner on a new
site?
> Or any sponsors?
>
> With the Long game rules programmed and later avitar video or still images
> of players in the Corners there could be a lot of traffic to the game.
Also
> a CD or download with a .exe app like Chessclub would be quicker and more
> versitile maybe.
>
> Regards,
>
> www.bishopsthegame.com
>
>
>
> Peter Sundstrom <peter.sundstrom@eds.com> wrote in message
> news:8rtgh2$76m$1@hermes.nz.eds.com...
> >
> > Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote in message
> > news:slrn8u4938.4h0.tjla@thislove.dyndns.org...
> > > I was shocked! How could theomats <ejw@windsor.igs.net>
> > > say such a terrible thing:
> > > >Hi,
> > > >Can someone volunteer to answer why my site "Bishops, A Chess
Variant"
> > needs
> > > >to be re-started quite often. My ISP has done all they can and the
> > original
> > > >programmer also has done what is needed to get the program (applet)
> > running.
> > > >The command I have been told to use is : perl5 bishops.cgi &
> > >
> > > You have a bug in line 17
> >
> > The general rule of thumb for identifying errors in non specified code
is
> to
> > check any line number that is prime ;-)
> >
> >
>
>
------------------------------
Date: Thu, 12 Oct 2000 11:31:19 -0700
From: "Kelley Kent" <kelley.a.kent@intel.com>
Subject: Re: reading in file as uneven multi-dimensional array
Message-Id: <8s4vvo$lka@news.or.intel.com>
"Logan Shaw" <logan@cs.utexas.edu> wrote
> Oh, and I forgot to mention an even simpler (or at least shorter) way:
>
> @file = map ([ split ], <>);
>
> Note, however, that this only works because I used split() in a way
> that makes it not matter that I didn't chomp the newline.
How about this quandry then: what if I needed to print out @file
sorted on the first word of each line, ie each $file->[x]->[0] values.
ORIG
my mother said
to pick
the very best one
and
you are it
SORTED
and
my mother said
the very best one
to pick
you are it
I'm assuming something like "sort { $a cmp $b } (@file)", but the
multi-dimensionalism is throwing me for a loop. Do I need "{ $a[0] cmp
$b[0] }"?
In my case I won't need to sort on the 2nd element should the 1st element
"tie" (ie all lines starting with "my" can be printed in any order).
Thanks (yet again!).
-- Kelley
------------------------------
Date: Thu, 12 Oct 2000 11:48:23 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: reading in file as uneven multi-dimensional array
Message-Id: <MPG.144fa754bdfafdfb98ae2c@nntp.hpl.hp.com>
In article <8s4vvo$lka@news.or.intel.com> on Thu, 12 Oct 2000 11:31:19 -
0700, Kelley Kent <kelley.a.kent@intel.com> says...
>
> "Logan Shaw" <logan@cs.utexas.edu> wrote
>
> > Oh, and I forgot to mention an even simpler (or at least shorter) way:
> >
> > @file = map ([ split ], <>);
> >
> > Note, however, that this only works because I used split() in a way
> > that makes it not matter that I didn't chomp the newline.
>
> How about this quandry then: what if I needed to print out @file
> sorted on the first word of each line, ie each $file->[x]->[0] values.
...
> I'm assuming something like "sort { $a cmp $b } (@file)", but the
> multi-dimensionalism is throwing me for a loop. Do I need "{ $a[0] cmp
> $b[0] }"?
The elements of @file aliased by $a and $b are not arrays (which would
make the notation $a[0] correct); they are references to arrays. So the
comparison function is:
{ $a->[0] cmp $b->[0] }
Note that this is much like what you showed above:
$file->[x]->[0]
> In my case I won't need to sort on the 2nd element should the 1st element
> "tie" (ie all lines starting with "my" can be printed in any order).
So don't bother to. :-)
But do look in perlfaq4: "How do I sort an array by (anything)?"
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 12 Oct 2000 19:38:05 +0100
From: "John Clifford Williams" <cliffwilliams@eurobell.co.uk>
Subject: Re: Reg exp help
Message-Id: <8s51lt$1cj9$1@slrn.eurobell.net>
Hi Erik,
try m/[0-9]+,[0-9]+/;
([0-9] matches a digit, [0-9]+ matches 1 or more digits. [0-9]* would match
0 or more digits.)
Mark.
<a94eribe@my-deja.com> wrote in message news:8s14m6$msn$1@nnrp1.deja.com...
> Hi
>
> I´m new to regular expressions and I would like some help.
>
> I need to check that the user submitted a correct quantity.
>
> A correct quantity is numeral and can contain one comma (,).
>
>
> How would the notation for that be?
>
> Thanks for your help
>
> /Erik
>
>
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Thu, 12 Oct 2000 12:39:25 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reg exp help
Message-Id: <MPG.144fb34476524ef098ae2e@nntp.hpl.hp.com>
[Rearranged for logical flow. Jeopardy posting in itself is a warning
of bogosity.]
In article <8s51lt$1cj9$1@slrn.eurobell.net> on Thu, 12 Oct 2000
19:38:05 +0100, John Clifford Williams <cliffwilliams@eurobell.co.uk>
says...
> <a94eribe@my-deja.com> wrote in message news:8s14m6$msn$1@nnrp1.deja.com...
...
> > I need to check that the user submitted a correct quantity.
> >
> > A correct quantity is numeral and can contain one comma (,).
>
> try m/[0-9]+,[0-9]+/;
> ([0-9] matches a digit, [0-9]+ matches 1 or more digits. [0-9]* would match
> 0 or more digits.)
Your regex requires a comma and at least two digits. It also allows any
garbage front and back.
The problem specification 'can contain one comma' would better be
written as 'may contain one comma', but clearly doesn't require the
comma no matter how it is written.
I posted a solution yesterday.
/^\d+(?:,\d+)?\z/
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 12 Oct 2000 19:26:23 +0100
From: "John Clifford Williams" <cliffwilliams@eurobell.co.uk>
Subject: Re: regular expression
Message-Id: <8s4vtb$1cge$1@slrn.eurobell.net>
Hi Laurent,
At first I thought "that's easy", but by the time I realised it was a little
more complicated, it was too late as it was already bugging me. Anyway, I
think I've found a solution:
At first I tried s/(word1 ).*(word2)/$1replacement_str$2/;
This matched "word1 bla bla word2" and replaced it with "word1
replacement_str word2", but it doesn't work with more than one occurence due
to greedyness. (The whole of "word1 bla word2 bla word1 bla word2" is
replaced with "word1 replacement_str word2".)
After consulting perldoc perlre, I discovered that minimal matching can be
enforced using a '?', so I then tried
s/(word1 ).*?( word2)/$1replacement_str$2/;
This seems to do the trick!
Mark.
Laurent <jylog@netcourrier.com> wrote in message
news:8s49d1$oi4$1@reader1.imaginet.fr...
> Hello
>
> i would like to do a regular expression to replace something which is
> between two known words, with a string.
>
> for example, i have: " word1 bla bla bla bla word2 bla bla bla bla"
> then i want : " world1 my_replacement_string word2 bla bla bla bla"
>
> and only for the first occurs
> for example, i have: " word1 bla bla bla bla word2 bla bla bla bla word1
> bla bla bla word2"
> then i want to have:" word1 my_replacement_string word2 bla bla bla bla
> word1 bla bla bla word2"
>
> thanks for your help
> --
>
> Laurent
>
>
------------------------------
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 4600
**************************************