[17450] in Perl-Users-Digest
Perl-Users Digest, Issue: 4870 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 11 18:05:33 2000
Date: Sat, 11 Nov 2000 15:05:09 -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: <973983909-v9-i4870@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 11 Nov 2000 Volume: 9 Number: 4870
Today's topics:
Re: Ä, Ö and Å Characters in Perl Programs <bart.lateur@skynet.be>
Re: Checking Links (Eric Bohlman)
Db_File <bryanliles@hotmail.com>
Re: Db_File (Garry Williams)
DBI:Oracle question texasreddog@my-deja.com
Re: forking (Logan Shaw)
getting total in a foreach loop <theborg@usa.com>
How to call sub routines from a CGI made Form <thectrain@hotmail.com>
Launching an Long-Term Process in IIS <toddm@waltz.rahul.net>
Perl programming of league tables ? <support@bedroomisp.co.uk>
Re: perl question under pc? (Tad McClellan)
Re: perl question under pc? <bart.lateur@skynet.be>
Re: perl question under pc? <jeff@vpservices.com>
Re: perl question under pc? <jeff@vpservices.com>
Re: perl question under pc? <bart.lateur@skynet.be>
Re: perl question under pc? <jeff@vpservices.com>
Phone dialing module? <news@nettenna.com>
Re: Premature end of script headers? otuzow@my-deja.com
Re: Pushing a hash on to a stack... (Anno Siegel)
Re: Quick short easy question <nospam@david-steuber.com>
Re: Random Array with Sort? <joe+usenet@sunstarsys.com>
Re: Self-modifying code in Perl (Ilya Zakharevich)
Re: Self-modifying code in Perl (Martien Verbruggen)
Re: strip html tags from string $text (Tramm Hudson)
Re: using 2 arrays in a foreach loop otuzow@my-deja.com
Re: Using POST and POST/ACTION on the same page - I fig (Martien Verbruggen)
XML:DOM error <mediamas@labyrinth.net.au>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 11 Nov 2000 20:01:57 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Ä, Ö and Å Characters in Perl Programs
Message-Id: <299r0tsgvmj1u7ulbp2mh2inl89drc6bh2@4ax.com>
john_s_brown@my-deja.com wrote:
>How can I use Scandinavian characters like ä, ö, å and Ä, Ö, Å in my
>perl programs?
Yes you can.
>Everytime I try to print those characters (e.g. print "äöä";), they
>appear on my screen as different characters. For example, "Ä" turns
>into "-" and "ä" turns into a strange symbol that looks like "E".
>
>I am using Windows and Active State's Active Perl interpreter.
Ah. Just make sure that you don't write the characters in on character
set (e.g. Windows) and look at the result in another character set (like
DOS, e.g. in a DOS box). DOS and Windows character sets are incompatible
in the upper half, i.e. character codes 128 to 255! A character with the
same character code will look different in a different environment.
Save the output to a file, look at the result in a Windows text editor,
and you'll see it's fine.
--
Bart.
------------------------------
Date: 11 Nov 2000 21:12:00 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Checking Links
Message-Id: <8ukcn0$gut$2@bob.news.rcn.net>
Jimtaylor5 <jimtaylor5@aol.com> wrote:
> I have the following simple perl program to check if links really exist. The
> code is below. 95 percent of the time it works fine, but there is those times
> when it says a link is not OK, when in fact it is. My question is twofold. Why
> is that, and what for example can I do to this program to to recognize the
> other 5 percent of links which are valid but for some reason don't show valid.
> Thank you very much for any help you can give me in correcting this.
> use LWP::Simple;
> $URL = $FORM{'siteurl'};
> $success = head($URL);
> if ($success) {
> &link_ok;
> }
> else {
> push(@ERROR5, "This URL could not be retrieved!");
> &link_not_ok;
> }
Some HTTP servers don't handle HEAD requests. Therefore, if a HEAD fails
you need to do a GET on the same URL before giving up.
------------------------------
Date: Sat, 11 Nov 2000 19:16:00 GMT
From: B <bryanliles@hotmail.com>
Subject: Db_File
Message-Id: <QVgP5.84852$RP.16141352@news1.rdc1.md.home.com>
I am trying to open a Berkely db file using DB_file:
tie %hash, DB_File, "filename";
How do I open a file that I can't write to?
tie %hast, DB_File, "filename", O_RDONLY, 0440, $DB_HASH?
That doesn't seem to work for me. Anyone want to help me out?
------------------------------
Date: Sat, 11 Nov 2000 22:14:14 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: Db_File
Message-Id: <WwjP5.167$xb1.9220@eagle.america.net>
On Sat, 11 Nov 2000 19:16:00 GMT, B <bryanliles@hotmail.com> wrote:
>I am trying to open a Berkely db file using DB_file:
>
>tie %hash, DB_File, "filename";
>
>How do I open a file that I can't write to?
>
>tie %hast, DB_File, "filename", O_RDONLY, 0440, $DB_HASH?
>
>That doesn't seem to work for me. Anyone want to help me out?
Well, it's hard to say what the problem is when you describe it as
"doesn't seem to work for me". How about some code, what you expected
and what actually happened. Please cut and paste it so the typos
above don't show up.
Anyway, it works just dandy for me. Here's what I did:
$ cat x
#!/usr/local/bin/perl -w
use strict;
use DB_File;
my %hash;
my %hast;
tie %hash, DB_File, "filename";
$hash{ONE} = 1;
$hash{TWO} = 2;
untie(%hash);
tie %hast, DB_File, "filename", O_RDONLY, 0440, $DB_HASH;
$hast{THREE} = 3;
untie(%hast);
tie %hast, 'DB_File', "filename", O_RDONLY, 0440, $DB_HASH;
foreach my $k ( keys %hast ) {
print "$k -> $hast{$k}\n";
}
untie(%hast);
$ perl x
Bareword "DB_File" not allowed while "strict subs" in use at x line 6.
Bareword "DB_File" not allowed while "strict subs" in use at x line 10.
Execution of x aborted due to compilation errors.
$
Oops. Your code won't compile cleanly under use strict. Hmmm. You
should get into the habit of starting all of your Perl scripts with
#!/usr/local/bin/perl -w
use strict;
Let's fix your code to compile cleanly and try again:
$ cat x
#!/usr/local/bin/perl -w
use strict;
use DB_File;
my %hash;
my %hast;
tie %hash, 'DB_File', "filename";
$hash{ONE} = 1;
$hash{TWO} = 2;
untie(%hash);
tie %hast, 'DB_File', "filename", O_RDONLY, 0440, $DB_HASH;
$hast{THREE} = 3;
untie(%hast);
tie %hast, 'DB_File', "filename", O_RDONLY, 0440, $DB_HASH;
foreach my $k ( keys %hast ) {
print "$k -> $hast{$k}\n";
}
untie(%hast);
$ perl x
ONE -> 1
TWO -> 2
$
That works as expected.
What are the results you get?
(By the way, the mode specification for a file being opened for read
only is ignored and can be specified as `0'. If you are creating a
file with the tie() function (or sysopen()), set your umask before
doing so, if you care about the resulting mode and then explicitly
specify the mode as 0666.)
--
Garry Williams
Zvolve Systems, Inc.
+1 770 551-4504
------------------------------
Date: Sat, 11 Nov 2000 22:38:18 GMT
From: texasreddog@my-deja.com
Subject: DBI:Oracle question
Message-Id: <8ukhoq$m50$1@nnrp1.deja.com>
Hi,
I am writing a Perl script that uses DBI:Oracle. This script is
supposed to write a bunch of junk to a database on a remote machine.
If somebody pulls the plug on the one machine, the script is supposed
to connect to a second database on another machine, and continue its
thing until it finishes. I am not a big DBI guru, and I'm having
trouble making part of this work. Here is the code:
#!/usr/bin/perl
system("date");
$ENV{'ORACLE_HOME'}
= '/usr/local/oracle/8i/u01/app/oracle/product/8.1.6';
use DBI;
$MAX=1000;
$script = "'$0'";
$port = 1521;
$text = "'Kiss is a band from New York City that first formed in 1973.
Bassist Gene Simmons and guitarist Paul Stanley had ju
st left a band called Wicked Lester, and were looking for new members
to play with. They acquired drummer Peter Criss when th
ey responded to an ad that he left in Rolling Stone Magazine, stating
Drummer willing to do anything to make it. They later
hired guitarist Ace Frehley, after he barged into their loft wearing
one red shoe and one orange shoe. For his audition, he u
sed someone elses guitar, and began playing in the middle of another
persons audition. Frehleys guitar sound was just what
the band was looking for, and the lineup was completed. They began by
playing small clubs in New York City. They later starte
d wearing their trademark makeup after seeing Alice Cooper in concert.
After months of continuous club dates, they landed a r
ecord deal with the newly-formed Casablanca Records. Their first album,
Kiss, was released in February, 1974. The horrific al
bum cover of the members decked out in makeup scared potential fans,
and critics thought Kiss was a joke. But what really inc
reased Kiss popularity was their live shows. Simmons, as the demon,
would spit blood and breathe fire at every show, and set
his hair on fire several times, which concert-goers thought was part of
the show. Songs from the first album, including Deuce
and Firehouse, became big hits, and pushed album sales to gold.'";
local ($user = 'ci2i');
local ($password = 'ci2i');
local ($host1 = 'oliver');
local ($host2 = 'sun2-in');
local ($sid1 = 'dev');
local ($sid2 = 'test3');
local ($db1 = 'oliver');
local ($db2 = 'test');
local ($dbtable = 'test');
# Create a DB connection
my $dbh = DBI->connect
("dbi:Oracle:host=$host1;sid=$sid1", "$user", "$password") or die
("Unable to connect to Oracle DB: $DB
I::errstr\n");
for($cnt=0; $cnt<=$MAX; $cnt++) {
my $statement = "insert into $dbtable values($script, $cnt, $text)";
my $sth = $dbh->prepare($statement);
$sth->execute;
if($sth->err) {
print "Error detected: $DBI::errstr\n";
$dbh->disconnect;
my $dbh = DBI->connect
("dbi:Oracle:host=$host2;sid=$sid2", "$user", $password) or die
("Unable to connect to Oracle DB:
$DBI::errstr\n");
for($cnt=$cnt; $cnt<=$MAX; $cnt++) {
my $statement = "insert into $dbtable values($script, $cnt,
$text)";
my $sth = $dbh->prepare($statement);
$sth->execute;
$sth->finish;
}
}
$sth->finish;
}
$dbh->disconnect;
system("date");
# do not remove this last line
1;
The problem is on the if(sth->err) part. It doesn't work. The script
starts off inserting the junk into the first remote DB. When I pull
the network cable on the remote machine, it doesn't execute the if(sth-
>err) part, it just sits there until the connection is plugged in again.
What do I need to do to my code to make this work??? If there is a
problem with the sth->execute when the connection is unplugged, how
should I code this correctly to switch over to the other machine and DB?
Thanks, Ken
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 11 Nov 2000 13:06:49 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: forking
Message-Id: <8uk5c9$438$1@boomer.cs.utexas.edu>
In article <973788104.819230@romulus.infonie.fr>,
ghwen <ghwen@infonie.fr> wrote:
>Is there a way to launch a kid who is killed if the father is killed ?
You can have the child process run getppid() periodically. If it
returns 1, then the parent is gone.
I don't think there's any way for the child to be interrupted and
informed right when the parent exits, though.
Of course, the other way is possible -- the parent can know when the
child has exited, because you can arrange to get a SIGCHLD when one
dies. So, if you switch the role of parent and child, you can do it
fairly easily.
Also, there may be some way of doing it by using process groups. If
you set the parent process as the session leader, this might do it. I
don't know much about that, though, so I'm not sure whether it would
work and whether it would be portable if it did. (Well, I am pretty
sure it wouldn't be portable outside of Unix...)
- Logan
------------------------------
Date: Sat, 11 Nov 2000 19:21:58 GMT
From: Bob <theborg@usa.com>
Subject: getting total in a foreach loop
Message-Id: <3A0D9C50.80DD8E39@usa.com>
--------------8ACB5DF482BD3E9C71145CCA
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
I am looking for a way to get the running total into this little sub. I
want to be able to print out the total of the value of the goods
selected and the total no. Any help would be appreciated. Thanks very
much - Bob
foreach my $i (0 .. $#products) {
next unless $quantitys[$i];
next unless $prices[$i];
$row_total=$prices[$i] * $quantitys[$i];
$row_total=sprintf("%4.2f", $row_total);
print "<table cellspacing=0 bgcolor=eeeeee><td><tr><td
width=350>$products[$i]</td><td width=50> $quantitys[$i]</td><td
width=75>$prices[$i]</td><td width=75>$ \$row_total</tr></td></table>";
}
--------------8ACB5DF482BD3E9C71145CCA
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I am looking for a way to get the running total into this little sub. I
want to be able to print out the total of the value of the goods selected
and the total no. Any help would be appreciated. Thanks very much
- Bob
<p>foreach my $i (0 .. $#products) {
<br> next unless $quantitys[$i];
<br> next unless $prices[$i];
<br> $row_total=$prices[$i] * $quantitys[$i];
<br> $row_total=sprintf("%4.2f", $row_total);
<br> print "<table cellspacing=0 bgcolor=eeeeee><td><tr><td
<br>width=350>$products[$i]</td><td width=50> $quantitys[$i]</td><td
<br>width=75>$prices[$i]</td><td width=75>$ \$row_total</tr></td></table>";
<br>}
<pre></pre>
</html>
--------------8ACB5DF482BD3E9C71145CCA--
------------------------------
Date: Sat, 11 Nov 2000 22:15:52 GMT
From: "Matt Perzel" <thectrain@hotmail.com>
Subject: How to call sub routines from a CGI made Form
Message-Id: <syjP5.6369$24.476677@news0.telusplanet.net>
I know this is more a cgi question but I am using perl so I guess it applies
here. Anyway I am making a form parsing script, in perl, that displays the
data and then has a button that when you click it sends it to a text file. I
can do all of the above except get the button to write the data. Is there a
way to call the routine from a form action?
This is what I am thinking but it doesn't seem to work
print "<FORM name=\"FORM1\" action=&writeData>";
Thanks
------------------------------
Date: 11 Nov 2000 21:24:24 GMT
From: Todd McLaughlin <toddm@waltz.rahul.net>
Subject: Launching an Long-Term Process in IIS
Message-Id: <8ukde8$c69$1@samba.rahul.net>
I'm trying to start an .exe program from a CGI Perl script. I've tried:
system( 'program.exe' );
system ('start program.exe');
Neither of the above return until program.exe closes. My web browser just
sits there waiting for the page.
exec( 'program.exe' );
The above returns control to the web browser but with the error message
that it didn't get any html code.
Also, the following does not work:
system( 'c:\program files\program.exe');
Do I have to use progra~1 instead?
Thanks!
Todd
------------------------------
Date: Sat, 11 Nov 2000 23:05:18 -0000
From: "Phil Latio" <support@bedroomisp.co.uk>
Subject: Perl programming of league tables ?
Message-Id: <rbkP5.12$I5.1179@stones>
Has anyone seen any tutorials that covers programming of league tables ?
The basic idea is that the local Sunday league I play football in wants to
put a simple form on a web page so home captains can submit results into a
database which can then output a league table. I've searched the web and I
am surprised to find absolutely nothing on this subject.
My thoughts are of saving the results to a MySQL database so I am going to
download all the Perl DBI info and see where that takes me but if anyone has
embarked on such a scheme, I would be grateful for a few pointers.
Cheers
Phil
------------------------------
Date: Sat, 11 Nov 2000 13:41:02 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: perl question under pc?
Message-Id: <slrn90r4lu.i45.tadmc@magna.metronet.com>
On Sat, 11 Nov 2000 18:01:31 GMT, guojx@my-deja.com <guojx@my-deja.com> wrote:
>I am a beginner in perl. could anyone tell me how to "cat" files into
>one file in PC?
perl -ne 'print' *.cdw >output.out
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 11 Nov 2000 19:58:33 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: perl question under pc?
Message-Id: <t09r0tgrss0nbvg9f9avns0ag37f1s2he9@4ax.com>
guojx@my-deja.com wrote:
>I am a beginner in perl. could anyone tell me how to "cat" files into
>one file in PC?
>For example, I have 100 files (*.cdw), I want cat them into one file
>(output.out) when name and content for each file in. How to do it in PC
>by perl?
This is the concept:
@ARGV = glob('*.cdw');
while(<>) {
print;
}
But with some command line switches, you don't need the the print and/or
the while loop.
#!perl -pw
BEGIN {
@ARGV = glob('*.cdw');
}
Yes, that's the complete program. Most definitely don't forget about the
-p switch.
--
Bart.
------------------------------
Date: Sat, 11 Nov 2000 12:24:44 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: perl question under pc?
Message-Id: <3A0DAB0C.317B1F3C@vpservices.com>
Tad McClellan wrote:
>
> On Sat, 11 Nov 2000 18:01:31 GMT, guojx@my-deja.com <guojx@my-deja.com> wrote:
>
> >I am a beginner in perl. could anyone tell me how to "cat" files into
> >one file in PC?
>
> perl -ne 'print' *.cdw >output.out
The OP specified a PC. If the PC is running linux or solaris for intel,
that one liner works and the OP didn't specify, so your answer is
correct.
But my PSI::ESP tells me the OP is running some version of windoze, so
that answer won't work because a) windows won't accept single quotes,
and b) windows won't do the right thing with the file globbing from the
command line. :-(
This, is alternative one-liner that works (at least on my win98):
perl -e "for(<*.cdw>){system(qq/type $_/)}" >output.out
--
Jeff
------------------------------
Date: Sat, 11 Nov 2000 12:30:40 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: perl question under pc?
Message-Id: <3A0DAC70.A5010E5C@vpservices.com>
Bart Lateur wrote:
>
> guojx@my-deja.com wrote:
>
> >I am a beginner in perl. could anyone tell me how to "cat" files into
> >one file in PC?
> ...
> #!perl -pw
> BEGIN {
> @ARGV = glob('*.cdw');
> }
>
Or, as a one-liner to shorten the one I sent in my interchange with Tad:
perl -pe "BEGIN{@ARGV=glob('*.csv')}" >output.out
--
Jeff
------------------------------
Date: Sat, 11 Nov 2000 22:39:36 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: perl question under pc?
Message-Id: <sair0t0v4gcf7qml8skj7n0g6f0o77cdub@4ax.com>
Jeff Zucker wrote:
>> #!perl -pw
>> BEGIN {
>> @ARGV = glob('*.cdw');
>> }
>>
>
>Or, as a one-liner to shorten the one I sent in my interchange with Tad:
>
> perl -pe "BEGIN{@ARGV=glob('*.csv')}" >output.out
For people that may wonder: globbing of the command line arguments won't
always work under Windows. I'm not sure why, but I've come not ever to
rely on it. So:
perl -perl *.cdw >output.out
will not always work.
p.s. the "-perl" option is a trick I learned from Randal. The -p option
is the only one that matters. But you do need a "script": that's what
the -e option is for. The script itself is the string "rl": a bareword.
Indeed it does nothing, except taking the sting out of the -e.
--
Bart.
------------------------------
Date: Sat, 11 Nov 2000 14:54:11 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: perl question under pc?
Message-Id: <3A0DCE13.4834737B@vpservices.com>
Bart Lateur wrote:
>
> For people that may wonder: globbing of the command line arguments won't
> always work under Windows. I'm not sure why, but I've come not ever to
> rely on it. So:
>
> perl -perl *.cdw >output.out
>
> will not always work.
The ActiveState docs have a neat little work around in the perlwin32
FAQ. That one-liner does not work for me on win98 until I do the
workaround. Basically in the workaround you create a tiny Wild.pm file
that takes "*.cdw" as a string and does a glob on it. Then you set
PERL5OPT=-MWild in DOS so that the module is always part of your
oneliner environment and the next time you run the one-liner, presto, it
works as if DOS were actually smart enough to know what "*.cdw" means.
> p.s. the "-perl" option is a trick I learned from Randal.
Randal++; Bart++;
--
Jeff
------------------------------
Date: Sat, 11 Nov 2000 14:56:44 -0800
From: "Dave Ressler" <news@nettenna.com>
Subject: Phone dialing module?
Message-Id: <7ckP5.1213$hn2.317020@news.uswest.net>
Is there a Perl module or routine I can use to dial an arbitrary number
using my modem?
My database program uses the default Phone Dialer that comes with Windows
2000, and it's the most dreadful piece of software I've seen in a long time.
I'd like to write a Perl routine to engage the phone line, dial a string
(including Star, Hash and pause), then get out of the way so I can pick up
the phone and talk.
Any clues would be greatly appreciated.
Thanks,
Dave
------------------------------
Date: Sat, 11 Nov 2000 22:01:25 GMT
From: otuzow@my-deja.com
Subject: Re: Premature end of script headers?
Message-Id: <8ukfji$kfd$1@nnrp1.deja.com>
In article <3A0CBB2C.6DB3@NOSPAMmcmail.com>,
Steve <m00fbe01@NOSPAMmcmail.com> wrote:
> Hi All,
>
> I'm pulling my hair out on this one and have spent
> several hours on it. Basically I installed a Perl
> script on a test server and everything worked ok.
> I've now just installed it in its proper location
> but all i'm getting is the helpful 'Premature end of
> script headers' I have checked all the permissions
> on files/directories - i've removed all the files and
> checked again that they were uploaded in ascii. I've
> even checked the directory structure as it is *slightly*
> different than on the test server. All to no avail even
> though the program ran fine on the other server - i've
> not made any other changes other than to move it to its
> new location.
>
> Is there a way of getting more useful info as to where
> exactly the problem is i.e. The perl script has a
> few files that are required and I suppose the problem
> could be either in any of these three files or with the
> Perl script itself - it's a case of finding where exactly
> the problem lies.
>
> Any Ideas anyone?
>
> Cheers in advance for any help.
>
> Steve
>
Are you sure you doesn't use any perl modules witch wasn't installed on
the live server?
Oleg
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 11 Nov 2000 22:11:53 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <8ukg79$7kp$1@lublin.zrz.tu-berlin.de>
Ren Maddox <ren.maddox@tivoli.com> wrote in comp.lang.perl.misc:
>anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>
>> Christopher Burke <craznar@hotmail.com> wrote in comp.lang.perl.misc:
>> >ren.maddox@tivoli.com (Ren Maddox) wrote in
>> ><m366lvjwx8.fsf@dhcp11-177.support.tivoli.com>:
>
>[A couple of attributions got lost here a couple of posts back, I wrote
>the push line and Christopher wrote the "That one doesn't work" part.]
>
>> >>> > push @fulldata, \%hash; # but do not reuse the same %hash
>> >>>
>> >>> That one doesn't work ... because, even with creating new %hash each
>> >>> loop.
>> >>
>> >>Looks like you might not have finished this thought. It seems that
>> >>you started to say why this wouldn't work, but didn't actually say it.
>> >>
>> >
>> >No - I don't know why it doesn't work. When I tried it - it just didn't
>> >work.
>>
>> You have shown some mastery of sulky evasiveness in this thread,
>> but this tops it off.
>>
>> Look, Christopher was asking you why *you think* the code doesn't
>> work, not for your explanation why it doesn't. In other words:
>
>Just to clarify... Christopher is the OP. I (Ren) was asking
>Christopher the question. As for what the question was, yes, it
>basically comes down to, "Christopher, in what way did that not work
>for you?"
Ugh. Mea culpa. I wrote "Christopher" where I should have written
"Ren". Apologies.
Anno
------------------------------
Date: Sat, 11 Nov 2000 22:00:47 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: Quick short easy question
Message-Id: <m33dgynp81.fsf@solo.david-steuber.com>
Welcome to, "this isn't a Perl question!"
Our contestant tonight is from West Palm Beach, Fl. He seems to have
punched the wrong holes and voted for Perl twice.
The correct answer is:
print '<href="URL" target="window_name">';
The window named "_top" is the top window in the browser. You want a
different name.
--
David Steuber | Perl apprentice. The axe did not stop the
NRA Member | mops and buckets from flooding my home.
ICQ# 91465842
*** http://www.david-steuber.com/ ***
------------------------------
Date: 11 Nov 2000 18:03:56 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Random Array with Sort?
Message-Id: <m3r94i157n.fsf@mumonkan.sunstarsys.com>
James Taylor <james@NOSPAM.demon.co.uk> writes:
> In article <973937192.3210@itz.pp.sci.fi>, Ilmari Karonen
> <URL:mailto:iltzu@sci.invalid> wrote:
> >
> > Fisher-Yates is O(n). You can't improve on that if you want to
> > shuffle the whole array.
>
> This is an interesting discussion and Fisher-Yates sounds like an
> algorithm I ought to be aware of. I've checked the books I've got:
> "Mastering Algorithms with Perl", Knuth vols.1-3,
From Abigail's documentation of Algorithm::Numeric::Shuffle,
it should be in Knuth vol.2 . You can also find an implementation
via
% perldoc -q shuffle
> Please could someone explain Fisher-Yates or point me to
> a suitable URL. Thanks.
Normally I'd point you at a URL, but I didn't see anything
satisfactory. I'm not a CS major, but I'll take a shot at
it for you.
Say you want to do a random shuffle on a 4-element array:
@ordered = ( A,B,C,D );
shuffle @ordered; # @ordered = ( 'B', 'C', 'D', 'A' );
In order for "shuffle" to be "random", it needs to
be capable of generating all possible permutations of
(A,B,C,D) with equal likelihood.
Imagine that these are 4 cards in your left hand.
Since your right hand is free, take one of the four
randomly and place it in your right hand. Rinse,
lather, and repeat, and you've got a reasonable
implementation of a random shuffle. The possible
permutations of your 4 cards is 4! = 24.
The Fisher-Yates algorithm allows you to achieve
the same effect without additional storage space (i.e.
putting the cards in your right hand). For instance,
transforming @ordered above to shuffle(@ordered) via
Fisher-Yates would go like this:
(3,4) (2,4) (1,4)
(A,B,C,D)----->(A,B,D,C)----->(A,C,D,B)----->(B,C,D,A)
The pair of numbers at the top are called "transpositions",
and if you think about how the above algorithm works,
you can see that the decomposition of any permutation into
such transpositions is unique.
The Fisher-Yates algorithm is based on this fact. Here's
an F-Y shuffle
==============================
#!/usr/bin/perl -w
sub shuffle (@) {
my $i = @_;
while ($i > 0) {
my $j = int rand($i+1); # HOW RANDOM ???
next if $i-- == $j; # UGLY ;-)
@_[$i,$j] = @_[$j,$i];
}
}
@ordered=('A'..'D');
shuffle @ordered;
print @ordered, "\n";
==============================
In theory, this is a decent O(n) implementation of F-Y.
However, in reality it's probably pretty useless
for serious work because of your box's implementation
of "rand".
Your rand function is most likely a 32 bit
implementation of ANSI C "uniform deviates".
To test whether this is so, try the following
==============================
#/usr/bin/perl -w
my $n = 0;
while (1) {
$_ = rand (1 << $n++);
last if $_ == int $_;
}
print "BITS=$n\n";
srand( "123456" );
$_ = rand(1<<$n);
print "SEQ=$_\n";
==============================
After a few runs, if you are getting
results like
BITS=29
SEQ=325850549.75
BITS=31
SEQ=1303402199
BITS=32
SEQ=0.606943945866078
BITS=30
SEQ=651701099.5
BITS=31
SEQ=1303402199
...
you've got a 32-bit rand.
That's quite normal, but quite bad here,
because if you try to shuffle say a 7-deck
shoe via a single pass of F-Y as above, your
deck will be *very* far from random. How far
from random, and how many passes might actually
be necessary, I leave for you to figure out.
You might start by tinkering with this
("shuffle" as above):
sub my_shuffle ($) {
my $n = 1 + int rand shift;
return sub {
shuffle @_ while $n--;
wantarray ? @_ : \@_;
}
}
$s = my_shuffle(10);
print &$s(@ordered), "\n";
However, I strongly advise you to investigate
this further before opening your own online
casino ;-)
HTH.
--
Joe Schaefer
------------------------------
Date: 11 Nov 2000 21:13:06 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Self-modifying code in Perl
Message-Id: <8ukcp2$iti$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was NOT sent to Martien Verbruggen
<mgjv@tradingpost.com.au>],
who wrote in article <slrn90qjsp.gs3.mgjv@martien.heliotrope.home>:
> Do you know of any system, or could you imagine a system, where the size
> of a file, as reported by the OS, would be smaller than the actual
> number of bytes that the internal representation in a Perl string would
> use.
Consider a kind of VMSish file system, where any file is a database.
When you read it as a plain fail, the $i-th line is
"$database{$i}\n". Suppose -s reports the actual bytes stored in the
database, so the "\n" added by the plain-read interface are not counted.
[IIRC, the actual VMS has a different implementation of -s, but you
got the idea.]
And about ISO C: who cares? There are many systems where half of ISO
C library would not make any sense. It would not help being ISO: the
C compiler will not support ISO.
Ilya
------------------------------
Date: Sun, 12 Nov 2000 09:34:59 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Self-modifying code in Perl
Message-Id: <slrn90ricj.gs3.mgjv@martien.heliotrope.home>
On 11 Nov 2000 21:13:06 GMT,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> [A complimentary Cc of this posting was NOT sent to Martien Verbruggen
><mgjv@tradingpost.com.au>],
> who wrote in article <slrn90qjsp.gs3.mgjv@martien.heliotrope.home>:
>> Do you know of any system, or could you imagine a system, where the size
>> of a file, as reported by the OS, would be smaller than the actual
>> number of bytes that the internal representation in a Perl string would
>> use.
>
> Consider a kind of VMSish file system, where any file is a database.
> When you read it as a plain fail, the $i-th line is
> "$database{$i}\n". Suppose -s reports the actual bytes stored in the
> database, so the "\n" added by the plain-read interface are not counted.
>
> [IIRC, the actual VMS has a different implementation of -s, but you
> got the idea.]
Yes. But the information about where the records are separated is
contained somewhere. This meta-information, IIRC, is part of the file
size as reported by stat.
I think the point made in another part of this thread, that -s doesn't
work on pipes, is more important. And it probably is also better, in a
language like Perl, not to have to care about buffer sizes, and stuff
like that. You almost never have to, so why should you? Especially if
there are caveats attached.
But then, I wasn't advocating read() with -s HANDLE. I was just
pedantically trying to find out if there were any implementations where
that would be wrong. pipes were correctly pointed out as one. I'm still
interested in a real life example of a system where a real file's size
as reported by stat (-s) is less than the actual inrternal
representation.
> And about ISO C: who cares? There are many systems where half of ISO
I care. And the people on clc. You brought up the point that C is much
less portable than Perl, and I just remarked that I sincerely doubt
that, since ISO C compilers are available for many more platforms than
Perl interpreters.
> C library would not make any sense. It would not help being ISO: the
> C compiler will not support ISO.
There are many platforms where part of the Perl builtins don't make
sense (getpw*, flock, msg* sem*, getgr*), because they are direct
translations of system calls that are specific to one group of OS.
There are many platforms where parts of the ISO C libraries make no
sense. Some of these platforms don't claim ISO C compilance. Others
implement stubs, just so the interface that ISO C requires is complete,
and do claim ISO C compliance.
But I fail to see your point by stating this. Sure, it's true. But it
also is besides the point. I'm also pretty sure that on any system where
ISO C cannot be fully implemented, Perl stands even less of a chance of
being implemented fully functional.
I really wonder why you claim that C is less portable than Perl. Badly
written C is, yes. But so is badly written Perl. And yes, there are
things you can do 'portably' in Perl that you cannot do pertably in C,
but that doesn't make the language more or less portable.
--
Martien Verbruggen |
Interactive Media Division | You can't have everything, where
Commercial Dynamics Pty. Ltd. | would you put it?
NSW, Australia |
------------------------------
Date: 9 Nov 2000 17:31:57 GMT
From: hudson@swcp.com (Tramm Hudson)
Subject: Re: strip html tags from string $text
Message-Id: <8uen2d$6se$1@sloth.swcp.com>
Keywords: the horse is dead, but the beatings continue
[posted and cc'd to cited author]
Jeff Zucker <jeff@vpservices.com> wrote:
> If you had bothered to read the FAQ, you would know that JavaScript has
> nothing to do with it, that angle brackets can be nested inside plain
> comments or even img alt attributes in completely JS-free pages.
Or even by themselves. HTML 4.0 allows unescaped < and > characters
with surrounding whitespace. Other DTD's might as well; I am only familiar
with 4.0. This is fully legal HTML, as validated by w3c:
http://validator.w3.org/check?pw;ss;uri=http://www.swcp.com/~hudson/test.html
And the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><title> < and > character demo</title></head>
1 < 2, 3 > 4
</body>
</html>
> ... Both those examples are in the FAQ, so I really, really do not
> understand why you would bother writing in useless speculation when the
> answer is clearly available to anyone who reads English.
Or DTD's. Which ever is more like your native tongue.
In general, regular expressions do not have the computational power
to parse arbitrary context free grammars. Let's stop beating this
dead horse and get back to debating the speed penalty of -w and
how to properly use Benchmark.
Tramm
--
o hudson@swcp.com hudson@turbolabs.com O___|
/|\ http://www.swcp.com/~hudson/ H 505.323.38.81 /\ \_
<< KC5RNF @ N5YYF.NM.AMPR.ORG W 505.986.60.75 \ \/\_\
0 U \_ |
------------------------------
Date: Sat, 11 Nov 2000 21:44:39 GMT
From: otuzow@my-deja.com
Subject: Re: using 2 arrays in a foreach loop
Message-Id: <8ukek6$js6$1@nnrp1.deja.com>
In article <3A0C59BE.737165EE@usa.com>,
"P.A. Borgan" <theborg@usa.com> wrote:
> I am having difficulty with a foreach loop. I would like to use two
> arrrays. None of the texts I have
> discuss how to use two arrays inside a foreach loop. The idea here is
> only print those lines that are
> not null for quantity. NOTE: I can get this to work for one array, ie
if
> I drop the @quantitys array.
>
> foreach $product (@products) && $quantity (@quantitys) {
> if ($quatity ne "" ) {
> print "$quantity $product";
> }}
>
> PS Any help would be appreciated ! Thanks.
>
> Peter
Try this :
@quantitys=(1,2,"",4);
@products=(1,2,3,4);
for ($i=0; $i < scalar(@products); $i++) {
if ($quantitys[$i] ne '') {
print "$quantitys[$i] $products[$i]\n";
}
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 12 Nov 2000 09:37:55 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Using POST and POST/ACTION on the same page - I figured it out
Message-Id: <slrn90rii3.gs3.mgjv@martien.heliotrope.home>
On Sat, 11 Nov 2000 07:32:00 -0800,
Salvador Peralta <admin@salvador.venice.ca.us> wrote:
>
> Martien Verbruggen wrote:
>> You were
>> talking about forms, and what you wanted to display in browsers. Those
>> things are _never_ a Perl problem. HTML or browser problems, yes. Not
>> Perl.
>
> Unless he had been having aproblem using the methods for building forms
> defined in cgi.pm.
But then the OP would have posted in clp.modules, being a good netizen
and all. And they would have mentioned having read the CGI
documentation.
> Never say "never". :)
I'll never do it again.
Martien
--
Martien Verbruggen |
Interactive Media Division | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd. | enough features yet.
NSW, Australia |
------------------------------
Date: Sun, 12 Nov 2000 09:12:28 +1000
From: "ccj" <mediamas@labyrinth.net.au>
Subject: XML:DOM error
Message-Id: <8ukg7b$29h1$1@arachne.labyrinth.net.au>
Hi
When I run this with -w I get a message I don't understand. I've run it with
a variety of well formed files. Using WinNT & ActiveState 5.6. Any
suggestions?
$file = "d:/perl/scripts/stocks.xml";
use XML::DOM;
my $parser = new XML::DOM::Parser;
my $doc = $parser->parsefile ($file);
Unrecognized escape \d passed through at C:/Perl/site/lib/XML/DOM.pm line
136
Many Thanks
CCJ
------------------------------
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 4870
**************************************