[19501] in Perl-Users-Digest
Perl-Users Digest, Issue: 1695 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 5 08:45:33 2001
Date: Wed, 5 Sep 2001 03:10:16 -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: <999684615-v10-i1695@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 5 Sep 2001 Volume: 10 Number: 1695
Today's topics:
HTML syntax (second pair of eyes) <admin@mickyemoose.net>
Re: HTML syntax (second pair of eyes) (Chris Fedde)
Re: HTML syntax (second pair of eyes) <admin@mickyemoose.net>
Re: HTML syntax (second pair of eyes) <admin@mickyemoose.net>
Re: HTML syntax (second pair of eyes) (Ian Boreham)
Low Priority File Copy - Slow Links (Jason)
Re: Low Priority File Copy - Slow Links (Chris Fedde)
Re: Match starting from the nth occurrence of a charact (Ian Boreham)
Re: Open 2 exes from Perl <bart.lateur@skynet.be>
Perl Commands Not Working <whataman@home.com>
Re: Perl Commands Not Working (Chris Fedde)
Re: Perl Commands Not Working <damian@platypus.qimr.edu.au>
Re: Perl Commands Not Working (Tad McClellan)
Re: Perl Commands Not Working <mbudash@sonic.net>
Re: Recommendations for a PERL editor (Tim Hammerquist)
Re: references, slices, voodoo <jasper@guideguide.com>
Re: Regular Express <bart.lateur@skynet.be>
Re: Shell Scripts vs. Perl Scripts <wolfh@master.sm.go.dlr.de>
Re: Shell Scripts vs. Perl Scripts (Damian James)
Re: Statement modifiers?? (David Combs)
Re: Statement modifiers?? (Malcolm Dew-Jones)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 4 Sep 2001 21:56:03 -0500
From: "JD Lampard" <admin@mickyemoose.net>
Subject: HTML syntax (second pair of eyes)
Message-Id: <eigl7.235931$rV6.11178726@e420r-atl2.usenetserver.com>
I was given a project to add a small (couple thousand) SQL database-backed
web page to my company's intranet. I set up MySQL, created the database,
imported the data, created the Perl script to select the data and return in
to the visitor's browsers. The database is actually quite simple... web
links. To make a long story short here's a snippet of my code...
<BEGIN PASTE>
my %row;
$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
while ($sth->fetch) {
print "<tr><td><a
href=$row(url)>$row{site}</a></td><td><ahref=$row(url)>$row{url}</a></td></t
r>\n";
}
<END PASTE>
The desired result would be "tablefied"...
Site 1 http://url.of.site1
Site 2 http://url.of.site2
Site 3 http://url.of.site3
Each column (site and URL) should be linked.
With my code I end up with a link like this:
http://intranet.mycompany.com/cgi-bin/(url). You can see in my code that
each site (in both the site name and url columns) is linked but improperly.
I'm sure the fix is simple--I simply need a second pair of eyes... it's
always nice to have a second pair of eyes!
Your help is much appreciated!
Regards,
JD Lampard
------------------------------
Date: Wed, 05 Sep 2001 03:15:31 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: HTML syntax (second pair of eyes)
Message-Id: <nNgl7.125$Owe.192582656@news.frii.net>
In article <eigl7.235931$rV6.11178726@e420r-atl2.usenetserver.com>,
JD Lampard <admin@mickyemoose.net> wrote:
>my %row;
>$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
>while ($sth->fetch) {
> print "<tr><td><a
>href=$row(url)>$row{site}</a></td><td><ahref=$row(url)>$row{url}</a></td></t
>r>\n";
>}
I'm not sure that $row(url) means what you think that it means.
Using 'use strict;' might help a bit with locating the bug.
good luck
--
This space intentionally left blank
------------------------------
Date: Tue, 4 Sep 2001 23:31:34 -0500
From: "JD Lampard" <admin@mickyemoose.net>
Subject: Re: HTML syntax (second pair of eyes)
Message-Id: <OHhl7.236201$rV6.11232286@e420r-atl2.usenetserver.com>
I'm using the DBI module to connect to an SQL database... I use the
bind_columns and fetch commands bound to a statement handle to retrieve the
records row by row. In my case "$row(url)" represents the address of the
site in the current record... "(url)" is the bound column--its actual
counterpart in the SQL database is the field named "url".
I do use strict but because my syntax is correct as far as Perl is concerned
I get no errors... this is an HTML problem but it's embedded in Perl code.
Thanks for your input!
-JD
"Chris Fedde" <cfedde@fedde.littleton.co.us> wrote in message
news:nNgl7.125$Owe.192582656@news.frii.net...
> In article <eigl7.235931$rV6.11178726@e420r-atl2.usenetserver.com>,
> JD Lampard <admin@mickyemoose.net> wrote:
> >my %row;
> >$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
> >while ($sth->fetch) {
> > print "<tr><td><a
>
>href=$row(url)>$row{site}</a></td><td><ahref=$row(url)>$row{url}</a></td></
t
> >r>\n";
> >}
>
> I'm not sure that $row(url) means what you think that it means.
> Using 'use strict;' might help a bit with locating the bug.
>
> good luck
> --
> This space intentionally left blank
------------------------------
Date: Wed, 5 Sep 2001 00:01:23 -0500
From: "JD Lampard" <admin@mickyemoose.net>
Subject: Re: HTML syntax (second pair of eyes)
Message-Id: <L7il7.236425$rV6.11249384@e420r-atl2.usenetserver.com>
My apologies Chris... this is/was an issue on the Perl side--not in the
HTML. I was using parenthesis ($row(site) and $row(url)) when I should have
been using curly brackets.
-JD
"JD Lampard" <admin@mickyemoose.net> wrote in message
news:OHhl7.236201$rV6.11232286@e420r-atl2.usenetserver.com...
> I'm using the DBI module to connect to an SQL database... I use the
> bind_columns and fetch commands bound to a statement handle to retrieve
the
> records row by row. In my case "$row(url)" represents the address of the
> site in the current record... "(url)" is the bound column--its actual
> counterpart in the SQL database is the field named "url".
>
> I do use strict but because my syntax is correct as far as Perl is
concerned
> I get no errors... this is an HTML problem but it's embedded in Perl code.
>
> Thanks for your input!
>
> -JD
>
> "Chris Fedde" <cfedde@fedde.littleton.co.us> wrote in message
> news:nNgl7.125$Owe.192582656@news.frii.net...
> > In article <eigl7.235931$rV6.11178726@e420r-atl2.usenetserver.com>,
> > JD Lampard <admin@mickyemoose.net> wrote:
> > >my %row;
> > >$sth->bind_columns( \( @row{ @{$sth->{NAME_lc} } } ));
> > >while ($sth->fetch) {
> > > print "<tr><td><a
> >
>
>href=$row(url)>$row{site}</a></td><td><ahref=$row(url)>$row{url}</a></td></
> t
> > >r>\n";
> > >}
> >
> > I'm not sure that $row(url) means what you think that it means.
> > Using 'use strict;' might help a bit with locating the bug.
> >
> > good luck
> > --
> > This space intentionally left blank
>
>
>
------------------------------
Date: 4 Sep 2001 23:50:34 -0700
From: ianb@ot.com.au (Ian Boreham)
Subject: Re: HTML syntax (second pair of eyes)
Message-Id: <f02c4576.0109042250.3767e92e@posting.google.com>
"JD Lampard" <admin@mickyemoose.net> wrote in message news:<eigl7.235931$rV6.11178726@e420r-atl2.usenetserver.com>...
> href=$row(url)>$row{site}</a></td><td><ahref=$row(url)>$row{url}</a></td></t
^ ^ ^ ^
In one case you have used braces, and in the other, parentheses.
Ian
------------------------------
Date: 4 Sep 2001 18:29:22 -0700
From: jpierce512@hotmail.com (Jason)
Subject: Low Priority File Copy - Slow Links
Message-Id: <40e297b.0109041729.781bb677@posting.google.com>
Hello,
I need to automatically copy files across several slow links on a
regular basis. The problem is that I can not interfere with the time
sensitive information already on the network. Is there a way for me to
slowly copy a file across the network. Can I set the Frame Size or
other TCP options within Perl. If possible I will need to have several
copy processes to differant nodes smultaneously. I have had no luck
thus far.
Thanks in Advance,
Jason
------------------------------
Date: Wed, 05 Sep 2001 03:06:07 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Low Priority File Copy - Slow Links
Message-Id: <zEgl7.124$Owe.171088896@news.frii.net>
In article <40e297b.0109041729.781bb677@posting.google.com>,
Jason <jpierce512@hotmail.com> wrote:
>Hello,
>
>I need to automatically copy files across several slow links on a
>regular basis. The problem is that I can not interfere with the time
>sensitive information already on the network. Is there a way for me to
>slowly copy a file across the network. Can I set the Frame Size or
>other TCP options within Perl. If possible I will need to have several
>copy processes to different nodes simultaneously. I have had no luck
>thus far.
>
>Thanks in Advance,
>Jason
It'd be straight forward to write a client server pair that put
any kind of delay that was desirable between writes or reads on a
socket. Another idea would be to put a web server like micro-httpd
on the source machine and write a client using IO::Socket and a
sleep. Or you could use thttpd and it's throttle option to control
the bandwidth at the server.
It's possible to write a throttled HTTP client if you use the
callback form of the LWP::UserAgent::request method and strategically
placing a sleep sleep somewhere in the callback.
Look at the manual page for IO::Socket::INET and the perlipc manual
page for ideas about the client server model. Micro-httpd and
thttpd can be found at http://www.acme.com/. Writing a specialized
HTTP client using LWP is easy if you follow examples in the lwpcook
manual page and review the LWP::UserAgent manual page.
good luck
--
This space intentionally left blank
------------------------------
Date: 4 Sep 2001 20:38:09 -0700
From: ianb@ot.com.au (Ian Boreham)
Subject: Re: Match starting from the nth occurrence of a character to the nth+1 occurrence
Message-Id: <f02c4576.0109041938.497c7c2b@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrn9pajkg.scn.tadmc@tadmc26.august.net>...
>You can do it most easily without a pattern match:
my $fourth_field = (split /,/, $line)[3]; # List Slice
If $line is large, you might want to use split's LIMIT parameter to
stop searching after the item you want is extracted.
If efficiency is important, you probably want index and substr,
though.
Regards,
Ian
---
P.S. As far as I'm aware, a slice is itself a list, so I don't see any
slicing going on here.
------------------------------
Date: Wed, 05 Sep 2001 08:38:13 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Open 2 exes from Perl
Message-Id: <i2pbptsukutr1h7stp2bnv6pkup1gej94o@4ax.com>
Helgi Briem wrote:
>To summarise, there are three ways:
>
>system ('start notepad')
>system(1, 'notepad');
>use Win32::Process;
Four. There's the ShellExecute API call, through Win32::API.
--
Bart.
------------------------------
Date: Wed, 05 Sep 2001 02:48:19 GMT
From: "What A Man !" <whataman@home.com>
Subject: Perl Commands Not Working
Message-Id: <3B95927C.ABB834AF@home.com>
Can anyone tell me why the following perl commands will not work in a
script on my webserver?
unlink
chmod
open
close
I've asked my webhost, and they don't know. These are running on a Linux
server with Apache and Perl version 2.6. I have my files chmodded to
755, but I don't think it's a permissions problem (could be wrong
though). I'm wondering since they use SSH telnet, if that could be
what's messing up these commands.
Any ideas would really be appreciated. I've spent 3 days trying to
figure this out.
Regards,
Dennis
------------------------------
Date: Wed, 05 Sep 2001 03:34:41 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Perl Commands Not Working
Message-Id: <l3hl7.126$Owe.198676992@news.frii.net>
In article <3B95927C.ABB834AF@home.com>,
What A Man ! <whataman@home.com> wrote:
>Can anyone tell me why the following perl commands will not work in a
>script on my webserver?
>
>unlink
>chmod
>open
>close
>
Looking at the error messages in the webserver error log. If you don't
know where that is ask your webmaster.
Good luck.
--
This space intentionally left blank
------------------------------
Date: 5 Sep 2001 03:44:00 GMT
From: Damian James <damian@platypus.qimr.edu.au>
Subject: Re: Perl Commands Not Working
Message-Id: <slrn9pb822.bm.damian@platypus.qimr.edu.au>
In article <3B95927C.ABB834AF@home.com>, What A Man ! wrote:
> Can anyone tell me why the following perl commands will not work in a
> script on my webserver?
>
> unlink
Needs write permission to the directory containing the file
> chmod
Needs to be owner of the file (or root)
> open
> close
Needs read permission only for open FH, "<file"; needs write permission for
open FH, ">file".
> I've asked my webhost, and they don't know. These are running on a Linux
> server with Apache and Perl version 2.6.
I think you might want to check that version number again. Try typing
perl -v
at the command line.
> I have my files chmodded to
> 755, but I don't think it's a permissions problem (could be wrong
> though).
I think it's a permission problem. 755 means only the owner of the file has
write permission for it. Is the script in question running as the user who
owns the file, or as some other user (like, the web server user)?
> I'm wondering since they use SSH telnet, if that could be
> what's messing up these commands.
No, I think that's extremely unlikely. Are we talking about command line or
CGI scripts here?
> Any ideas would really be appreciated. I've spent 3 days trying to
> figure this out.
Cheers,
Damian
--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker, ### rev 3.3 -- stupidectomy performed :-)
------------------------------
Date: Wed, 05 Sep 2001 04:20:07 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl Commands Not Working
Message-Id: <slrn9pb6uv.t5b.tadmc@tadmc26.august.net>
What A Man ! <whataman@home.com> wrote:
>Can anyone tell me why the following perl commands will not work in a
>script on my webserver?
>
>unlink
>chmod
>open
>close
No, but each of those can itself tell why it failed via its
return value and the $! variable.
But you have to write code to check them, and you haven't
shown us the code, so we don't know if they are being
tested or not...
>I've asked my webhost, and they don't know.
They probably do know but aren't telling you ('cause then
they'd have to explain it).
>These are running on a Linux
>server with Apache and Perl version 2.6.
^^^^^^^^^^^^^^^^
April first is a long ways away. That bit there is utter nonsense.
>I have my files chmodded to
>755, but I don't think it's a permissions problem (could be wrong
>though).
It may be the permissions on the parent directory that matter,
rather than the permissions of the files themselves.
Note that this is a unix issue and has nothing to do with Perl.
>I'm wondering since they use SSH telnet, if that could be
>what's messing up these commands.
I'm not sure what that means, since you said "web server", I
thought you are doing HTTP. What involvement does telnet have
in what you are doing?
>Any ideas would really be appreciated. I've spent 3 days trying to
>figure this out.
Numero uno would be to get the thing running from the command
line first.
Then be sure you are checking return values for the above functions,
and see what the messages tell you.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 05 Sep 2001 05:24:38 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Perl Commands Not Working
Message-Id: <mbudash-8A39D8.22244004092001@news.sonic.net>
In article <l3hl7.126$Owe.198676992@news.frii.net>,
cfedde@fedde.littleton.co.us (Chris Fedde) wrote:
> In article <3B95927C.ABB834AF@home.com>,
> What A Man ! <whataman@home.com> wrote:
> >Can anyone tell me why the following perl commands will not work in a
> >script on my webserver?
> >
> >unlink
> >chmod
> >open
> >close
> >
>
> Looking at the error messages in the webserver error log. If you don't
> know where that is ask your webmaster.
or the OP could fashion his 'unlink', etc. thusly:
unlink ($file) or die ("can't unlink $file: $!");
might help...
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Wed, 05 Sep 2001 01:19:59 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Recommendations for a PERL editor
Message-Id: <slrn9pb04q.6kq.tim@vegeta.ath.cx>
Me parece que Jürgen Exner <jurgenex@hotmail.com> dijo:
[ snip ]
> Your problem is most likely that your ISPs web server can't handle the
> EndOfLine 0x0A 0x0D used in the Windows world.
From a different point of view, the shebang line of the scripts doesn't
conform to the *nix standard EOL format.
[ snip ]
--
Tell me -- How's your love life? Killed any girlfriends
recently? Or sentenced any more of them to Hell?
-- Desire to Morpheus, The Sandman
------------------------------
Date: Wed, 05 Sep 2001 10:34:51 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: references, slices, voodoo
Message-Id: <3B95F1BB.43814DBA@guideguide.com>
ctcgag@hotmail.com wrote:
>
> Jasper McCrea <jasper@guideguide.com> wrote:
> ...
> > But I wrote my own, anyway, in the way that I thought would be simplest
> > ie extract a random element, and put it in a new array.
> >
> > sub new_order {
> > my @ray = @array; # I was using a global for the testing...
> > my @new_order = ();
> > push @new_order, (splice @ray, (int rand @ray), 1) while (@ray);
> > return \@new_order;
> > }
>
> > Oh, and speed:
> >
> > Benchmark: running mine, yate, each for at least 3 CPU seconds...
> > mine: 4 wallclock secs ( 3.00 usr + 0.00 sys = 3.00 CPU) @
> > 9299.00/s (n=27897)
> > fisher: 5 wallclock secs ( 3.00 usr + 0.00 sys = 3.00 CPU) @
> > 7380.33/s (n=22141)
>
> Dandy. Now what if you want shuffle something with more than 4 elements?
> Say, 3000?
>
sure:
Benchmark: running mine, yate, each for at least 3 CPU seconds...
mine: 5 wallclock secs ( 3.85 usr + 0.01 sys = 3.86 CPU) @
18.91/s (n=73)
yate: 6 wallclock secs ( 3.64 usr + 0.03 sys = 3.67 CPU) @
19.89/s (n=73)
was with 4000.
Benchmark: running mine, yate, each for at least 3 CPU seconds...
mine: 6 wallclock secs ( 3.77 usr + 0.00 sys = 3.77 CPU) @
6.63/s (n=25)
yate: 5 wallclock secs ( 3.67 usr + 0.00 sys = 3.67 CPU) @
9.81/s (n=36)
with 8000
so obviously there's a crossover in speed.
I've gotta say that in the code I use, I rarely use an array with more
than 1-2000 elements. I suppose the decrease in speed is coming from the
fact that it's creating two fairly large arrays, rather than just
shuffling about the single array. Perl's implementation of small arrays
( < 4000 elements ?) seems to produce an advantage this way, rather than
the FY shuffle.
> Xho
Jasp
--
split//,'019617511192'.
'17011111610114101114'.
'21011141011840799901'.
'17101174';
foreach(0.. # my
$#_){$_[$_ # signature is too
++]^=$_[$_ # bignature
--]^=$_[$_
]^=$_[++ $_]if!($_%
2)}$g.=$_ ,chr($g)=~
/(\w)/&&($o.=$1and
$g='')foreach@_;
print"$o\n"
------------------------------
Date: Wed, 05 Sep 2001 07:46:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regular Express
Message-Id: <4vlbpt091trevrj46715k4r45m5arc495q@4ax.com>
Bart Lateur wrote:
>Stefan Adams wrote:
>>I assumed the RE /<BODY\s+.*?>(.*?)</BODY>/ would work, but it
>>doesn't. Any suggestions?
I forgot to add: You'd better replace that "\s+" with "\b", or you'd not
match a plain and simple "<BODY>".
--
Bart.
------------------------------
Date: Wed, 05 Sep 2001 09:41:36 +0200
From: Heiko Wolf <wolfh@master.sm.go.dlr.de>
To: tadmc@augustmail.com
Subject: Re: Shell Scripts vs. Perl Scripts
Message-Id: <3B95D730.D40F363D@master.sm.go.dlr.de>
> >I want to execute a bs script from a perl script.
> ^^
>
> Eh? Did you mean "bash" instead?
No sorry, I meant "sh" -> UNIX-newbie *plonk*
> >How can I do this? Is there a kind of "run"-command?
>
> perldoc -f system
> perldoc -f qx
> perldoc -q external
>
So I tried to enter those commands at the command line, and I only got
error messages like the following:
perldoc -f system
Unknown option: f
perldoc [-h] [-v] [-u] PageName|ModuleName|ProgramName...
-h Display this help message.
-t Display pod using pod2text instead of pod2man and nroff.
-u Display unformatted pod text
-m Display modules file in its entirety
-v Verbosely describe what's going on.
PageName|ModuleName...
is the name of a piece of documentation that you want to look
at. You
may either give a descriptive name of the page (as in the
case of
`perlfunc') the name of a module, either like `Term::Info',
`Term/Info', the partial name of a module, like `info', or
`makemaker', or the name of a program, like `perldoc'.
Any switches in the PERLDOC environment variable will be used before
the
command line arguments.
I'm using SUN Solaris 2.7
Any suggestions?
Regards Heiko Wolf
------------------------------
Date: 5 Sep 2001 09:39:46 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Shell Scripts vs. Perl Scripts
Message-Id: <slrn9pbsjr.7nj.damian@puma.qimr.edu.au>
Heiko Wolf chose Wed, 05 Sep 2001 09:41:36 +0200 to say this:
>...
>No sorry, I meant "sh" -> UNIX-newbie *plonk*
>
You probably don't mean 'plonk' here -- this is supposed to indicate an
increment to the population of the poster's killfile.
>...
>So I tried to enter those commands at the command line, and I only got
>error messages like the following:
>
>perldoc -f system
>
> Unknown option: f
> perldoc [-h] [-v] [-u] PageName|ModuleName|ProgramName...
Blech! This doesn't sound like any version of perldoc I have encountered.
What version of perl are you running? Try `perl -v`. I'll wager it is
somewhat aged. One way to work with this would be to try:
%perldoc perlfunc
and then search for the 'system' function by typing '/system'. A better way
would be to install a more recent perl.
>
>I'm using SUN Solaris 2.7
>Any suggestions?
Check your version of perl, and either install a newer perl or prevail upon
your sysadmin to do so
Cheers,
Damian.
--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker, ### rev 3.3 -- stupidectomy performed :-)
------------------------------
Date: 5 Sep 2001 05:42:33 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Statement modifiers??
Message-Id: <9n4e09$776$1@news.panix.com>
In article <3b893d23@news.victoria.tc.ca>,
Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
>Ilya Martynov (ilya@martynov.org) wrote:
>: >>>>> On 25 Aug 2001 09:49:21 GMT, dkcombs@panix.com (David Combs) said:
>
>: DC> Anyway, about assertions.
>
>: DC> You really need macros to do them "right".
>
>: DC> You define assert *as a macro*.
>
>: DC> So that Assert(i > j) generates:
>
>: DC> if not (i > j) {
>: DC> either-die-or-warn-or-goIntoDebugger("Assertion Failed: " . "i > j")
>: DC> }
>
>: DC> (not exact syntax, but at least readable)
>
>: You can implement same thing in Perl using source filters.
>
>
>but I don't think you even need to.
>
>I tested something very similar, (I forget exactly what I'm afraid, so I
>may be wrong here).
>
>If you define your 'Assert' sub as a do nothing then it is either
>optimized away, or the sub itself is so optimized that there's effectively
>no runtime added to the script, only compile time, (but compile time
>doesn't count since a macro preprocessor or filter would always have to
>parse the macros anyways).
>
>(perhaps my test was of &the_sub; calls, (implicit parameters) so it might
>not apply ?)
>
Are you sure? The whole idea of this "assert" is that
you pass it ONE argument -- the (unquoted) condition that
you are asserting evaluates to true -- and if it does
NOT, then you want to turn that *same* single unquoted
arg into a *string* to print out in the assertion-failed
message.
Is that what your suggestion would do?
(About adding such a facility, I suggest that
it be done in perl6, not 5. As built into the
compiler -- and debugger too!)
>: DC> So that Assert(i > j) generates:
>
>: DC> if not (i > j) {
>: DC> either-die-or-warn-or-goIntoDebugger("Assertion Failed: " . "i > j")
^^^^^
>: DC> }
------------------------------
Date: 5 Sep 2001 01:05:48 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Statement modifiers??
Message-Id: <3b95dcdc@news.victoria.tc.ca>
David Combs (dkcombs@panix.com) wrote:
: In article <3b893d23@news.victoria.tc.ca>,
: Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
: >Ilya Martynov (ilya@martynov.org) wrote:
: >: >>>>> On 25 Aug 2001 09:49:21 GMT, dkcombs@panix.com (David Combs) said:
: >
: >: DC> Anyway, about assertions.
: >
: >: DC> You really need macros to do them "right".
: >
: >: DC> You define assert *as a macro*.
: >
: >: DC> So that Assert(i > j) generates:
: >
: >: DC> if not (i > j) {
: >: DC> either-die-or-warn-or-goIntoDebugger("Assertion Failed: " . "i > j")
: >: DC> }
: >
: >: DC> (not exact syntax, but at least readable)
: >
: >: You can implement same thing in Perl using source filters.
: >
: >
: >but I don't think you even need to.
: >
: >I tested something very similar, (I forget exactly what I'm afraid, so I
: >may be wrong here).
: >
: >If you define your 'Assert' sub as a do nothing then it is either
: >optimized away, or the sub itself is so optimized that there's effectively
: >no runtime added to the script, only compile time, (but compile time
: >doesn't count since a macro preprocessor or filter would always have to
: >parse the macros anyways).
: >
: >(perhaps my test was of &the_sub; calls, (implicit parameters) so it might
: >not apply ?)
: >
: Are you sure? The whole idea of this "assert" is that
: you pass it ONE argument -- the (unquoted) condition that
: you are asserting evaluates to true -- and if it does
: NOT, then you want to turn that *same* single unquoted
: arg into a *string* to print out in the assertion-failed
: message.
: Is that what your suggestion would do?
I don't see an easy way to get the string message now that you mention it,
though during debugging you could simply die with the line number, (since
that always ties directly and reliably to the source) but I thought the
issue was how to ensure that the assert macro took no runtime overhead
when you turned debugging off.
If you have a series of 'if $debugging then' statements then you do get
runtime overhead, but I was theorizing (based on hazy memory) that by
using 'assert(condition)' then you could use a perl sub as the assert
because if you define the assert to be a null sub for production use then
the entire function call would dissappear due to optimizations and
therefore the assert would have no runtime overhead, just like using a
"real" macro which expands into nothing.
: (About adding such a facility, I suggest that
: it be done in perl6, not 5. As built into the
: compiler -- and debugger too!)
: >: DC> So that Assert(i > j) generates:
: >
: >: DC> if not (i > j) {
: >: DC> either-die-or-warn-or-goIntoDebugger("Assertion Failed: " . "i > j")
: ^^^^^
: >: DC> }
--
Want to access the command line of your CGI account? Need to debug your
installed CGI scripts? Transfer and edit files right from your browser?
What you need is "ispy.cgi" - visit http://nisoftware.com/ispy.cgi
------------------------------
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 1695
***************************************