[18510] in Perl-Users-Digest
Perl-Users Digest, Issue: 678 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 11 18:05:59 2001
Date: Wed, 11 Apr 2001 15:05:19 -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: <987026719-v10-i678@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 11 Apr 2001 Volume: 10 Number: 678
Today's topics:
Re: A CGI question <bart.lateur@skynet.be>
Re: CGI-ODBC Problem <cpryce@pryce.net>
Checksums With Unpack Where Is More Info? (Steve K. Brown)
Re: complaint about moderation of this group (---Pete---)
Re: converting UTF8 to 8bit character <juex@deja.com>
Re: converting UTF8 to 8bit character (Andre Malo)
Re: converting UTF8 to 8bit character <elijah@workspot.net>
Re: converting UTF8 to 8bit character <juex@deja.com>
Re: Copying a ColdFusion site <iltzu@sci.invalid>
Re: DBD::DB2 and positioned updates? <a_bordia@hotmail.com>
email related <bing-du@tamu.edu>
Empty Parenthesis Evaluting to True -- WHY? <sparks@novia.net>
Re: Empty Parenthesis Evaluting to True -- WHY? nobull@mail.com
Re: Empty Parenthesis Evaluting to True -- WHY? <joe+usenet@sunstarsys.com>
Re: Empty Parenthesis Evaluting to True -- WHY? <sparks@novia.net>
Re: Empty Parenthesis Evaluting to True -- WHY? (Jay Tilton)
Re: Empty Parenthesis Evaluting to True -- WHY? (Randal L. Schwartz)
Executing Perl script from C or C++ program. <zonnebloem@zonnet.nl>
Re: Expect.pm problem (Charles DeRykus)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Apr 2001 19:27:57 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: A CGI question
Message-Id: <llb9dtog17kglimpe1fmnabt6vd64lo782@4ax.com>
Simon Stiefel wrote:
>Every checkbox has the name "entry_X" while X is the number beginning with
>1. The value is "1" if it is checked.
>
>For example, when I click on 2 checkboxes the new URL will be the
>following:
>
>http://www.stiefel.priv/cgi-bin/pos/pos.cgi?entry_1=1&entry_7=1&action=do+smthg
>
>Now my problem:
>
>Every checked checkbox will appear as "entry_X=1" in the URL.
>How can I fetch them in variables??
>Do I have to create for every entry a new variable?
No. You'd better use an array.
First, you need to get a list of all parameter os this format. Second,
catch the value for all of those (which is, for checkboxes, always "on".
If it wasn't, that parameter simply wouldn't appear in the query.)
Now, assuming use of CGI.pm:
#!/usr/local/bin/perl -w
use CGI;
my $cgi= new CGI;
my @checkboxes = grep /^entry_\d+$/, $cgi->param();
foreach(map /(\d+)/, @checkboxes) {
$check[$_] = 1; # true
}
So, in your example, only $entry[1] and $entry[7] would be true. All
other entries would be undefined, i.e. false, or nonexistent (beyond the
end of the array), i.e. undefined and thus false.
--
Bart.
------------------------------
Date: Wed, 11 Apr 2001 13:32:36 -0500
From: Chris <cpryce@pryce.net>
Subject: Re: CGI-ODBC Problem
Message-Id: <B6FA0D73.2C35%cpryce@pryce.net>
in article u9d7aj8jc5.fsf@wcl-l.bham.ac.uk, nobull@mail.com at
nobull@mail.com wrote on 04/11/2001 11:58 AM:
> Stephan Gross <sg@loralskynet.com> writes:
>
>> I have a perl script that uses ODBC to connect to a database. When I
>> run the file as a CGI program from a browser, it can no longer
>> connect. Any ideas?
>
> Sounds like a user identity/permissions issue with the DSN.
>
> Almost certainly nothing to do with Perl, it would likely be the same
> in any language.
I ran into a similar problem with my DBD::ODBC and Apache set-up. Likely you
have the identity/permissions problem mentioned above, but there is one
other thing you might want to check.
Keep in mind, that if you set and export a Library path as root, it is NOT
set for the Web server. You might also need to use the SetEnv directive in
Apache, or its equivalent in your Web server.
For instance, with my implementation of ODBC, I have a third party driver
that needs to have LD_LIBRARY_PATH set.
In any case, I agree that it is probably not a Perl problem.
cp
------------------------------
Date: 11 Apr 2001 21:11:06 GMT
From: skbrown@vcd.hp.com (Steve K. Brown)
Subject: Checksums With Unpack Where Is More Info?
Message-Id: <9b2h9a$id8$1@news.vcd.hp.com>
I am looking for more details about the checksum portion
of the unpack function. I have read the camel book, looked
at the FAQ, searched perldoc. Where else can I go to get
more information / examples?
What I am doing is reading in a Motorola S record file and
performing an add of the data (after removing the excess
baggage of course). The script takes about 6 minutes to
do this and I am trying to make it faster. I currently
put each byte of data in an array and add the array for
an 8 bit checksum. I then take the array and concatenate
two bytes together at a time to make a 16 bit checksum.
I am looking for a faster algorithm. Any suggestions?
Steven K Brown
------------------------------
Date: Wed, 11 Apr 2001 18:38:02 GMT
From: bogus@erol.com (---Pete---)
Subject: Re: complaint about moderation of this group
Message-Id: <3ad4a46b.59991705@news.earthlink.net>
On 11 Apr 2001 10:47:08 GMT, Ilmari Karonen <iltzu@sci.invalid> wrote:
>So if we just treat CGI-related answers as bulk material to be pushed
>into ciwac, without too much regard to thread integrity, that might
>establish a positive feedback mechanism that would increase the volume
>of ciwac, and hopefully decrease that of clpm.
------
Absolutely, I agree.
Me being a newbie to Perl and this NG, and someone who is
trying to help, please listen to what I am saying because I was
in the very position we are speaking of and trying to correct here.
I needed to do some things with my website that required that
I learn some Perl, I go out and buy/read 1 book that left me with
the wrong impression that CGI some kind of interface but somehow
part of Perl. The Perl docs also left me with a similar impression
because 133 of Perl files were related to CGI. Next I come to this
NG and see people getting flack for posting CGI related topics.
OK, I ask my self where's the FAQ for this NG? I see some posts
indicating that the FAQ is included in the Perl Docs. OK, I read that
but I was still confused. After that I post a message as to what
PERL/CGI books to buy. I get some answers and spend several
more weeks reading. Still, nothing I read pointed out a clear
dividing line between Perl & CGI other than saying it was an
interface. Still confused, I was resourceful enough to find the
NG.. comp.infosystems.www.authoring.cgi and posted some
CGI/Perl questions when someone brought it to my attention
that the Perl Docs was the wrong place to look for info on
the CGI. That's when I finally saw the dividing line, but it took
me 3 books and considerable time to get there.
Ok, with all that said, I believe that the very books and
resources that most newbies encounter will direct them to
this group and without clearly educating and pointing out
the dividing line between CGI & Perl. The "sign" here says
"Perl" and this group says "perl.misc" so, up to this point
most newbies will honestly believe that they can post CGI
questions here. HOWEVER, no one here has taken the
time to clearly explain the dividing line. The buck stops here.
If you desire to separate GCI from PERL then someone
here must make the effort to educate and redirect.
Redirection alone will not solve the problem. If you don't
do these things then be prepared for lost of headaches.
I was reading the CAMEL 3rd edition book today and saw this..
Quote.. "Perl folks are, frankly, some of the most helpful folks
on earth. If there's a religious quality to the Perl movement,
then this is the heart of it. Larry wanted the Perl community to
function like a little bit of heaven, and by and large he seems
to have gotten his wish so far. Please do your part to keep it
that way."
If you do a search within this NG on the topics that are CGI
related and see how the regulars are addressing what
appears to be the newbies innocently posting CGI related
questions you will see the lack of "helpful" advice and
absense of "bit of heaven" that Larry was hoping for.
Most are down right nasty with no attempt to educate or
even redirect.
To me the solution seems simple.. Educate and Redirect.
1.) Use this as the 1st line of defense:
http://www.augustmail.com/~tadmc/clpmisc_guide/clpmisc_guidelines.text
2.) Develop a brief educational CGI/PERL message that
politely and clearly explains difference between CGI and PERL,
reasons why it was made separate from this group, along with
some helpful advise as to how the person will benefit with better
responses and answers by going to:
comp.infosystems.www.authoring.cgi
3.) Place the "rubber stamp" msg on the web and make a reference
to it from the clpmisc_guidelines.text document.
Then simply use the auto-post thing to post the basic rules
and use a cut-n-paste operation to reply to any CGI topic
you feel if truly off-topic; kind of like a rubber stamp.
Now you 's done your part in the true spirit of Larry's wish.
After that, if a person "rubber stamped" persists to break
the rules then I say go kick ass!
---pete---
>
>
>(Before someone mentions it: No, you can't crosspost to ciwac because
>the moderator bot doesn't let you. Crossposts between ciwac and a group
>with a human moderator may succeed if you put the other group first, but
>between ciwac and clpm it won't work. In any case, that would keep much
>of the noise in clpm.)
>
>--
>Ilmari Karonen - http://www.sci.fi/~iltzu/
>Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: Wed, 11 Apr 2001 11:16:39 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: converting UTF8 to 8bit character
Message-Id: <3ad49f87$1@news.microsoft.com>
"Sven Franke" <snefsite@hotmail.com> wrote in message
news:9b1enq$hct$1@ncc1701.cistron.net...
> I need to translate UTF8 to 8bit character.
That's not possible.
Even when using different target code pages (Windows speak) you still need
at least 16 bit to represent e.g. all Chinese characters.
jue
------------------------------
Date: 11 Apr 2001 18:52:49 GMT
From: ndparker@gmx.net (Andre Malo)
Subject: Re: converting UTF8 to 8bit character
Message-Id: <Xns9080D481E51C4ndparker@news.o3media.de>
* Sven Franke wrote in <9b1klm$t22$1@ncc1701.cistron.net>:
>But my ISP only has 5.0053.....
>can it be done?
please don't use jeopardy style.
check out the Unicode modules on CPAN.
For simple transformation you also can use something like this:
$string =~ s{ ([\300-\337])([\200-\277]) }
{ chr((ord($1) << 6 | ord($2) & 63) & 255) }gex;
# $string MUST NOT contain any other characters than UTF8 encoded
ISO-8859-1 chars.
n.d.p.
--
package Hacker::Perl::Another::Just;print
qq~@{[reverse split/::/ =>__PACKAGE__]}~;
# n.d. parker # http://www.o3media.de #
------------------------------
Date: 11 Apr 2001 20:16:47 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: converting UTF8 to 8bit character
Message-Id: <eli$0104111616@qz.little-neck.ny.us>
In comp.lang.perl.misc, Jürgen Exner <juex@deja.com> wrote:
> "Sven Franke" <snefsite@hotmail.com> wrote in message
> news:9b1enq$hct$1@ncc1701.cistron.net...
> > I need to translate UTF8 to 8bit character.
> That's not possible.
It is if you are willing to be lossy.
> Even when using different target code pages (Windows speak) you still need
> at least 16 bit to represent e.g. all Chinese characters.
It is not inconceivable that someone would be dealing with UTF-8
encoded text that only uses iso-8859-X characters and wishes to
make the translation for consistency.
The Unicode::String module can translate UCS4 (UTF-32), UCS2 (UTF-16),
UTF-8, and UTF-7 into Latin-1 (iso-8859-1). The documentation does
warn that this is a lassy translation.
Basically it would be something like this (untested):
use Unicode::String qw( utf8 );
# Specify output format
Unicode::String->stringify_as('latin1');
# Assign to $var the latin1 version of the utf8 text
$var = utf8('UTF-8 encoded string');
I use this (tested) code for translating tab seperated data
in base64 encoded UCS-2 into base64 encoded UTF-8:
perl -MMIME::Base64 -MUnicode::String=utf16 -wpe '
BEGIN{ Unicode::String->stringify_as("utf8") }
($n, $one, undef, undef, $two, undef) = split(/\t/, $_, 6);
$one = encode_base64(utf16(decode_base64($one)));
$two = encode_base64(utf16(decode_base64($two)));
chomp($one); # remove the \n encode_base64 adds
chomp($two); # remove the \n encode_base64 adds
$_ = "$n\t$one\t$two\n";
END{ use Time::SoFar qw( runtime );
$time = runtime();
print STDERR "Took $time\n";
}
' $infile
Goes through about 10 megs of input per minute for me.
Elijah
------
does not the minimum perl version required for Unicode::String
------------------------------
Date: Wed, 11 Apr 2001 13:36:47 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: converting UTF8 to 8bit character
Message-Id: <3ad4c060$1@news.microsoft.com>
"Eli the Bearded" <elijah@workspot.net> wrote in message
news:eli$0104111616@qz.little-neck.ny.us...
> In comp.lang.perl.misc, Jürgen Exner <juex@deja.com> wrote:
> > "Sven Franke" <snefsite@hotmail.com> wrote in message
> > news:9b1enq$hct$1@ncc1701.cistron.net...
> > > I need to translate UTF8 to 8bit character.
[...]
> > Even when using different target code pages (Windows speak) you still
need
> > at least 16 bit to represent e.g. all Chinese characters.
>
> It is not inconceivable that someone would be dealing with UTF-8
> encoded text that only uses iso-8859-X characters and wishes to
> make the translation for consistency.
Quite right. But the OP didn't make this restriction.
He asked for a method to convert general UTF-8 into 8-bit characters
jue
------------------------------
Date: 11 Apr 2001 19:21:33 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Copying a ColdFusion site
Message-Id: <987016160.22480@itz.pp.sci.fi>
In article <3AD48FEB.F7FABE09@vitesse.com>, Rob Root wrote:
>
>I need to copy a site (ours) built with ColdFusion to regular HTML. Is
>there a perl module to help?
LWP, most likely. The only reasonable interpretation of converting CFML
to plain HTML involves passing it through ColdFusion. The easiest way
to achieve that is to use a web spider program to mirror the site. If
you want to write one in Perl, and don't want to use any of the existing
scripts that do this, LWP is what you should use.
http://search.cpan.org/search?dist=libwww-perl
Me, I'd probably just use wget.
(Come to think of it, it shouldn't be too hard to write a Perl module to
parse CFML. Maybe it could even be implemented as an extension of some
existing template framework like HTML::Mason. Now that would be cool.)
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.
------------------------------
Date: Wed, 11 Apr 2001 11:31:52 -0700
From: "Aakash Bordia" <a_bordia@hotmail.com>
Subject: Re: DBD::DB2 and positioned updates?
Message-Id: <9b27rh$k5m$1@stlnews.stl.ibm.com>
I think you are trying an invalid operation because -510 states the
following:
SQL0510N UPDATE or DELETE is not allowed against the specified
cursor.
Explanation: The program attempted to execute an UPDATE or
DELETE WHERE CURRENT OF cursor statement against a table or view
definition that does not permit the requested update or delete
operation. For example, this error can occur in a delete from a
read-only view or in an update where the cursor was not defined
with the FOR UPDATE clause.
On the database manager the view is read-only if the SELECT
statement
o The DISTINCT keyword
o A column function in the SELECT list
o A GROUP BY or HAVING clause
o A FROM clause that identifies one of the following:
- More than one table or view
- A read-only view (READONLY column of SYSCAT.SYSVIEWS is set
to 'Y')
- A table or view that is also identified in the FROM clause of
a subquery of the SELECT statement. (NOTE: This is a
restriction only in releases of DB2 prior to Version
2).
o A set operator (other than UNION ALL).
Note that these conditions do not apply to subqueries of the
SELECT statement.
The cursor is declared with a FOR FETCH ONLY or ORDER BY
clause.
The cursor is ambiguous and the BLOCKING ALL bind option was
specified.
The statement cannot be processed.
User Response: If the database manager is failing the statement
and the cursor is based on a read-only SELECT or VALUES statement,
do not issue any update or delete statements against it.
If the database manager is failing the statement and the cursor
is not based on a read-only SELECT or VALUES statement and is
defined with a FOR FETCH ONLY or ORDER BY clause, either remove
this clause from the cursor definition or do not issue any update
or delete statements.
If the database manager is failing the statement and the cursor
cannot be determined to be either fetch only or updateable from
its definition or context, rebind the program with either the
BLOCKING NO or BLOCKING UNAMBIG bind option.
Federated system users: isolate the problem to the data source
failing the request (see the problem determination guide for
procedures to follow to identify the failing data source). If a
data source is failing the request, examine the restrictions for
that data source to determine the cause of the problem and its
solution. If the restriction exists on a data source, see the
SQL reference manual for that data source to determine why the
object is not updatable.
sqlcode: -510
sqlstate: 42828
"Hemant Shah" <shah@typhoon.xnet.com> wrote in message
news:9b20ic$bab$1@flood.xnet.com...
>
> Folks,
>
> I am using perl DBI/DBD to perform update in DB2 database. The perl DBI
book
> mentions that positioned update are supported in DBI::DB2, but
> I cannot figure out how to use it.
>
>
> $SqlStmt = "SELECT
> TIMESHEET.DATE,
> RTRIM(TIMESHEET.EMP_ID),
> RTRIM(TIMESHEET.PROJECT_ID),
> RTRIM(TIMESHEET.TASK_ID),
> RTRIM(PROJECT.CONTRACT_ID),
> TIMESHEET.RATE
> FROM BILLING.TIMESHEET,
> BILLING.PROJECT,
> BILLING.CONTRACT
> WHERE
> TIMESHEET.DATE <= ?
> AND TIMESHEET.ADJ_ID = ''
> AND TIMESHEET.RATE != 0
> AND TIMESHEET.PROJECT_ID = PROJECT.PROJECT_ID
> AND PROJECT.CONTRACT_ID = CONTRACT.CONTRACT_ID
> ;";
>
> $StmtHandle = $DbHandle->prepare($SqlStmt);
> if (! $StmtHandle)
> {
> print STDERR "$ExeName: ERROR getting info from timesheet table.\n";
> ExitProc(1);
> }
>
> my($MyCursor) = $StmtHandle->{CursorName};
> print "MyCursor = $MyCursor\n";
>
>
> $UpdtStmt="UPDATE BILLING.TIMESHEET
> SET RATE = ?
> WHERE CURRENT OF $MyCursor
> ;";
>
> $UpdtStmtHandle = $DbHandle->prepare($UpdtStmt);
> if (! $UpdtStmt)
> {
> print STDERR "$ExeName: ERROR Cannot prepare update statement.\n";
> ExitProc(1);
> }
>
>
> $StmtHandle->execute($EndDate);
>
> while loop for $StmtHandle->fetchrow()
> {
> Calculate $NewRate
>
> $UpdtStmtHandle->execute($NewRate);
> $UpdtStmtHandle->finish;
> }
>
> # Release database resources.
> $StmtHandle->finish;
>
>
> If I execute the above code, the cursorname is set, but I get following
> error when I execute $UpdtStmtHandle:
>
> MyCursor = SQLCURCS297
> DBD::DB2::st execute failed: [IBM][CLI Driver][DB2/6000] SQL0727N An
error
> occurred during implicit system action type "2". Information returned for
> the error includes SQLCODE "-510", SQLSTATE "42828" and message tokens "".
> SQLSTATE=56098
>
>
> If I add the update clause as follows:
>
> $SqlStmt = "SELECT
> TIMESHEET.DATE,
> RTRIM(TIMESHEET.EMP_ID),
> RTRIM(TIMESHEET.PROJECT_ID),
> RTRIM(TIMESHEET.TASK_ID),
> RTRIM(PROJECT.CONTRACT_ID),
> TIMESHEET.RATE
> FROM BILLING.TIMESHEET,
> BILLING.PROJECT,
> BILLING.CONTRACT
> WHERE
> TIMESHEET.DATE <= ?
> AND TIMESHEET.ADJ_ID = ''
> AND TIMESHEET.RATE != 0
> AND TIMESHEET.PROJECT_ID = PROJECT.PROJECT_ID
> AND PROJECT.CONTRACT_ID = CONTRACT.CONTRACT_ID
> FOR UPDATE OF TIMESHEET.RATE
> ;";
>
>
> If fails while setting the $MyCursor:
>
> Describe failed during DBI::st=HASH(0x203e86b8)->FETCH(CursorName) at
> ./tstphase1.pl line 478.
>
>
>
> How can I use positioned updates in DBD::DB2?
>
> Thanks.
>
>
> --
> Hemant Shah /"\ ASCII ribbon campaign
> E-mail: NoJunkMailshah@xnet.com \ / ---------------------
> X against HTML mail
> TO REPLY, REMOVE NoJunkMail / \ and postings
> FROM MY E-MAIL ADDRESS.
> -----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
> I haven't lost my mind, Above opinions are mine only.
> it's backed up on tape somewhere. Others can have their own.
------------------------------
Date: Wed, 11 Apr 2001 15:15:50 -0500
From: Bing Du <bing-du@tamu.edu>
Subject: email related
Message-Id: <3AD4BB75.5DF72542@tamu.edu>
Hi,
Is there any mail related Perl module that can deliver email directly to
the folder (mailbox)? We use IMAP server. Some shared folders are
created on the server for the students to subscribe to read official
announcements. Now we need to write a CGI program in Perl to let the
directors, department heads, et. al. to be able to use the web interface
to send the announcement to the shared folder.
Appreciate any suggestions.
Bing
------------------------------
Date: Wed, 11 Apr 2001 18:35:25 GMT
From: Thomas Sparks <sparks@novia.net>
Subject: Empty Parenthesis Evaluting to True -- WHY?
Message-Id: <3AD4C12C.928848D6@novia.net>
Hello.
I came across a piece of code and I can't figure out why it works, and
it does indeed work.
Here it is:
...
# the following code is an endless loop
while()
{print "some stuff ";}
...
What I don't understand is why "()" evaluates to true. I've checked
Camel, I've checked Llama, I've checked every source I can get my hands
on and they all suggest (while not specifically adressing the empty
parenthesis) that an empty paren' should be false.
Wassup widat? Thanks for any help in solving this mystery.
Tom
------------------------------
Date: 11 Apr 2001 19:46:19 +0100
From: nobull@mail.com
Subject: Re: Empty Parenthesis Evaluting to True -- WHY?
Message-Id: <u9hezv6zr8.fsf@wcl-l.bham.ac.uk>
Thomas Sparks <sparks@novia.net> writes:
> # the following code is an endless loop
> while()
> {print "some stuff ";}
>
> What I don't understand is why "()" evaluates to true.
Probably DWIM. Guess someone figured the above syntax was cool, added
it and hasn't documented it (yet).
> I've checked Camel, I've checked Llama, I've checked every source I
> can get my hands on and they all suggest (while not specifically
> adressing the empty parenthesis) that an empty paren' should be
> false.
Actually they should be a syntax error. cf. "if ()" because the () are
part of the syntax of while() not part of the expression.
Of course in the postfix form while doesn't have () so in that case ()
is treated as an expression and hense false.
# the following code is an no-op
print "some stuff " while ();
With this in mind I think the addition of this new syntax is probably
miss-guided.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 11 Apr 2001 15:07:10 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Empty Parenthesis Evaluting to True -- WHY?
Message-Id: <m3k84r5k81.fsf@mumonkan.sunstarsys.com>
Thomas Sparks <sparks@novia.net> writes:
> Hello.
>
> I came across a piece of code and I can't figure out why it works, and
> it does indeed work.
>
> Here it is:
>
> ...
> # the following code is an endless loop
> while()
> {print "some stuff ";}
> ...
>
> What I don't understand is why "()" evaluates to true.
"()" doesn't evaluate to true- you have an empty expression (whatever that
means) within *the required parentheses for while*. Change "while()" to
"until()", "unless()", "if()", or "for()" and see what happens. Note
that the corresponding statement modifier does not require the
parentheses- perhaps that is causing confusion:
print "foo" while ();
is essentially the same as
while( () ) { print "foo" } # note the additional pair of parentheses
It appears to me that you've located a bug in perl's parser, since I
think it should kick out a syntax error for "while() {...}".
--
Joe Schaefer "What a waste it is to lose one's mind. Or not to have a mind is
being very wasteful. How true that is."
-- Dan Quayle
------------------------------
Date: Wed, 11 Apr 2001 19:29:47 GMT
From: Thomas Sparks <sparks@novia.net>
Subject: Re: Empty Parenthesis Evaluting to True -- WHY?
Message-Id: <3AD4CDEA.C119660F@novia.net>
None of the following work: "until()", "unless", "if()", or "for()" work. A real
head scratcher here.
In the meantime, I'll just find another way to do what the code is trying to do.
Thanks for your reply.
Joe Schaefer wrote:
> Thomas Sparks <sparks@novia.net> writes:
>
> > Hello.
> >
> > I came across a piece of code and I can't figure out why it works, and
> > it does indeed work.
> >
> > Here it is:
> >
> > ...
> > # the following code is an endless loop
> > while()
> > {print "some stuff ";}
> > ...
> >
> > What I don't understand is why "()" evaluates to true.
>
> "()" doesn't evaluate to true- you have an empty expression (whatever that
> means) within *the required parentheses for while*. Change "while()" to
> "until()", "unless()", "if()", or "for()" and see what happens. Note
> that the corresponding statement modifier does not require the
> parentheses- perhaps that is causing confusion:
>
> print "foo" while ();
>
> is essentially the same as
>
> while( () ) { print "foo" } # note the additional pair of parentheses
>
> It appears to me that you've located a bug in perl's parser, since I
> think it should kick out a syntax error for "while() {...}".
>
> --
> Joe Schaefer "What a waste it is to lose one's mind. Or not to have a mind is
> being very wasteful. How true that is."
> -- Dan Quayle
------------------------------
Date: Wed, 11 Apr 2001 20:53:27 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Empty Parenthesis Evaluting to True -- WHY?
Message-Id: <3ad4c20f.194939231@news.erols.com>
On Wed, 11 Apr 2001 18:35:25 GMT, Thomas Sparks <sparks@novia.net>
wrote:
># the following code is an endless loop
>while()
> {print "some stuff ";}
>
>What I don't understand is why "()" evaluates to true.
I would instead wonder why somebody would intentionally use this
misfeature. It takes only one extra keystroke to type 'while(1)'.
------------------------------
Date: 11 Apr 2001 14:48:47 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Empty Parenthesis Evaluting to True -- WHY?
Message-Id: <m1g0ffxg3k.fsf@halfdome.holdit.com>
>>>>> "Jay" == Jay Tilton <tiltonj@erols.com> writes:
>> What I don't understand is why "()" evaluates to true.
Jay> I would instead wonder why somebody would intentionally use this
Jay> misfeature. It takes only one extra keystroke to type 'while(1)'.
I don't recall when it was blessed, but it's been blessed for a long
time. Oddly, I can find no test in 5.6.1's test suite to verify it
works. So it could come out of 5.6.2 or 5.8 and still pass the
current test suite. :)
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 11 Apr 2001 22:20:50 +0200
From: Jurgen Boerboom <zonnebloem@zonnet.nl>
Subject: Executing Perl script from C or C++ program.
Message-Id: <3AD4BCA2.B8540C1A@zonnet.nl>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
I´m struggling creating a C program that executes a perl script from
a file. I have gone through the Perl docs several times, tried several
things, but can get the grip on it. (See my posting of Thu, 01 Mar
2001 16:00:46)
<p>Can any body tell if it has been done before and maybe provide me with
a coding example.
<p>Thanks, Jurgen Boerboom</html>
------------------------------
Date: Wed, 11 Apr 2001 21:08:09 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Expect.pm problem
Message-Id: <GBnC1L.C00@news.boeing.com>
In article <3ac72a26@news.bezeqint.net>,
Richard Jones <orinoki@hotmail.com> wrote:
>Hi
>
>I'm using Expect.pm on UNIX (FreeBSD) and I'm trying to create expect
>sessions using telnet.
>I'm having some problems with it.
>It works fine until for no reason it gets stuck and it is unable to connect.
>Even after a short delay it has problems.
>An hour later it suddenly works again.
>
>Maybe it has to do with a lack in some sort of resource?
>Maybe you know how can I debug it?
>
Expect has some debugging/logging facilities but you
might well be better off using Net::Telnet if you're
simply trying to automate a telnet session:
http://search.cpan.org/search?dist=Net-Telnet
hth,
--
Charles DeRykus
------------------------------
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 678
**************************************