[16641] in Perl-Users-Digest
Perl-Users Digest, Issue: 4053 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 18 00:05:28 2000
Date: Thu, 17 Aug 2000 21:05:12 -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: <966571511-v9-i4053@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 17 Aug 2000 Volume: 9 Number: 4053
Today's topics:
Re: Checking if variables exist <vrillusions@mail.com>
Re: Checking if variables exist <vrillusions@mail.com>
Re: cookie problem <martinqz@taiwan.com>
Re: cookie problem <jeff@vpservices.com>
Eval and Regexps Help bluearchtop@my-deja.com
Re: Eval and Regexps Help (Logan Shaw)
Re: Eval and Regexps Help <elephant@squirrelgroup.com>
Re: Eval and Regexps Help <elephant@squirrelgroup.com>
Re: FileHandle in array <abe@ztreet.demon.nl>
Help on Error Message: "Document Contains No Data" <cooljazz.nospam@flash.net>
Re: Help on Error Message: "Document Contains No Data" (Martien Verbruggen)
Re: Help on Error Message: "Document Contains No Data" <joelnelson@home.net>
Re: Help on Error Message: "Document Contains No Data" (Decklin Foster)
Re: Help writing scriptlet interpreter <bwalton@rochester.rr.com>
Is it possible??? <kalyan@uab.edu>
Re: Is it possible??? <joelnelson@home.net>
Re: Out of memory! error. Working with arrays... (David Wall)
Scalar range operator <drayner@atnf.csiro.au>
setting up a cgi directory cedop@my-deja.com
Re: setting up a cgi directory <joelnelson@home.net>
Re: setting up a cgi directory <jeff@vpservices.com>
Re: Sorting is very slow (Gwyn Judd)
Stuck...why won't this work? <edge@gecko.org>
Re: Stuck...why won't this work? <uri@sysarch.com>
Re: Stuck...why won't this work? <bwalton@rochester.rr.com>
The diamond operator. johnvert@my-deja.com
Re: The diamond operator. <bkennedy@hmsonline.com>
Re: Two pipes and only one runs, why? <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 Aug 2000 01:38:48 GMT
From: Todd Eddy <vrillusions@mail.com>
Subject: Re: Checking if variables exist
Message-Id: <399C93B3.B8E41F4D@mail.com>
Yea, i did get a little mad, just the way I interpetted that "...Some CGI you are doing
there" as in insult, which got me mad througout the entire message. I did look that up,
but just briefly. Like I said before, if it works, go with it. after realizing that the
die wasn't set up right to display the page, I quickly made a subroutine that worked here
it is if your interested:
sub dienice {
my($errmsg) = @_;
print "<h2>Error</h2>\n";
print "$errmsg<p>\n";
print "</body></html>\n";
exit;
}
I don't know if this is true, but it seems that it would take longer to load a module then
just to go to a subroutine. and I did get a solution to that variable checking, its ugly,
but it works (see the reply I make to joe kline's message).
Abe Timmerman wrote:
> [ Please put your comments following the (suitably trimmed) text you are
> responding to ]
> [ Some sort of order restored ]
> On Thu, 17 Aug 2000 22:58:04 GMT, Todd Eddy <vrillusions@mail.com>
> wrote:
> > Abe Timmerman wrote:
> >
> > > On Thu, 17 Aug 2000 04:59:48 GMT, Todd Eddy <vrillusions@mail.com>
> > > wrote:
> ...
> > > >
> > > > #!/usr/bin/perl
> > > No warnings, no Taint checking, no strictness; Some CGI you're doing
> > > there.
> > >
> > This is the reason why I don't post the whole script, I end up getting flamed
> > ("...Some CGI you're doing
> > there."). This is only my second script I have ever made, give me a f#$%ing break
> > here.
>
> I only criticized your code, that's no where near flaming.
>
> > > #!/usr/bin/perl -wT
> > > use strict;
> > >
> > Like that -wT part, I have NEVER seen that on any of the
> > online resources I have looked at for tutorials and stuff (about 6 or 7 sites) nor
> > have I seen that in any of the 10 or so scripts I have installed. Thus it must not
> > be that standard of practice. Same goes for the rest of it, if all of that is
> > working, then why mess with it?
> >
> '-w' turns on warnings, which is very helpful when you are developing a
> program. '-T' turns on taint checking (see perlsec manpage) which should
> be in cgi programs. If you consult sources that do not use these
> features and prefer that, ok, but don't come asking here if it bit you.
>
> ...
>
> > > While you are studying the documentation that comes with CGI.pm, 'fix'
> > > your script like:
> > >
> > > use CGI qw(:standard);
> > > use CGI::Carp 'fatalsToBrowser';
> ...
> > And whats really got me mad and why I took the time
> > to reply is WHERE THE HELL DO YOU GIVE ANY HELP ON THE SUBJECT??????? Your giving me
> > all of these suggestions to make it 'better' and yet you don't even help me with the
> > problem I am having, that being I can't get the error checking to work.
>
> You probably got so mad, that you didn't even look at my answer. By
> putting the line:
>
> use CGI::Carp 'fatalsToBrowser';
>
> in your script, it will show the message of your die() in the browser.
> Please start reading the documentation for CGI.pm (and family).
>
> perldoc CGI::Carp
> perldoc CGI
>
> --
> Good luck,
> Abe
--
Todd Eddy
vrillusions@mail.com
http://www.vrillusions.com/
------------------------------
Date: Fri, 18 Aug 2000 01:45:17 GMT
From: Todd Eddy <vrillusions@mail.com>
Subject: Re: Checking if variables exist
Message-Id: <399C9538.FF38D874@mail.com>
Thank you, your the only so far that has actually provided a solution. Got me
some ideas, heres what I came up with.
Even though you never really mentioned, others made note that the die doesn't
print to the browser by default, so instead of using the module, I made a
quick subroutine:
sub dienice {
my($errmsg) = @_;
print "<h2>Error</h2>\n";
print "$errmsg<p>\n";
print "</body></html>\n";
exit;
}
and, as for the error checking:
if ($FORM{'realname'} eq "") { dienice("Please enter your name\n"); }
if ($FORM{'callsign'} eq "") { dienice("Please enter your call sign\n"); }
if ($FORM{'computer'} eq "") { dienice("Please chose if you are bringing your
own computer or using a house computer\n"); }
if ($FORM{'email'} eq "") { dienice("Please enter your email address\n"); }
if ($FORM{'location'} eq "") { dienice("Please enter your location\n"); }
yea, its messy, all they would have to do is hti space and it would go
through, but it works, and thats all the matters. Just though you might be
interested how I came about all of this. Again, thanks for the suggestions.
Joe Kline wrote:
> Todd Eddy wrote:
> >
> > Here is what I have:
> >
> > if ($FORM{'realname'} && $FORM{'callsign'} && $FORM{'computer'} &&
> > $FORM{'email'} && $FORM{'location'}) { $required = "yes"; }
> > else { die "You did not enter a required field, please make corrections
> > and try again"; }
> >
> > Doesn't that mean that if all of those exist, it will set $required to
> > yes? and if one of those don't exist it will die? then how come when I
> > have those two lines in the script, I get an error saying that the page
> > contains no data in netscape and IE I just get a blank page?
>
> Well, looking at the above code in conjunction with your later
> posting...
>
> The above code is "sort of" checking to see if the %FORM hash has
> values for a bunch of keys. This isn't the best way to go about this,
> I would suggest doing:
>
> if ( ( exists $FORM{'realname'} && $FORM{'realname'} ) &&
> ( exists $FORM{'callsign'} && $FORM{'callsign'} ) &&
> ( exists $FORM{'computer'} && $FORM{'computer'} ) &&
> ( exists $FORM{'email'} && $FORM{'email'} ) &&
> ( exists $FORM{'location'} && $FORM{'location'} )
> )
> { $required = "yes"; }
>
> The "exists" check avoids autovivification. I do believe in I might be
> a bit paranoid with my checking.
>
> As a side note, I would suggest use CGI.pm (or one of the lighter
> weight variants that can be found at http://search.cpan.org ) to do
> your parameter parsing. This would let you do things like:
>
> $realname = param('realname');
> $callsign = param('callsign');
> $computer = param('computer');
> $email = param('email');
> $location = param('location');
>
> Then you could do more meaningful checking to see if all of the form
> fields were completed properly.
>
> --
> Joe Kline
>
> It takes a lot of brains to enjoy satire, humor, and wit;
> but none to be offended by them. ---The Midnight Skulker
--
Todd Eddy
vrillusions@mail.com
http://www.vrillusions.com/
------------------------------
Date: Fri, 18 Aug 2000 10:32:40 +0800
From: MartinQz <martinqz@taiwan.com>
Subject: Re: cookie problem
Message-Id: <399CA048.574AE708@taiwan.com>
>
Thanks for everyone that helps me to solve the problem, and I just found
that I can get what I expected after I used my way to working with the
cookie, and everything seems works fine.
And someone said my code contains poor programming style, and I am very
agree with that, on the other hand, if the problem can be solved, I
believe that any programming style should be used.
whatever it is a black cat or white cat, it is a good cat if it can
catch a mouse!
And if the time allowed, I think I will have the good programming style
by studying in details of Perl, but as I said before, my deadline is
coming...
Anyway, thanks for any criticism, and I will improve myself in the near
future...
ps. please forgive my poor English... ^_^
Martin.Qz
------------------------------
Date: Thu, 17 Aug 2000 19:45:14 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: cookie problem
Message-Id: <399CA33A.AD3D2C2C@vpservices.com>
MartinQz wrote:
>
> if the problem can be solved, I
> believe that any programming style should be used.
>
> whatever it is a black cat or white cat, it is a good cat if it can
> catch a mouse!
What happens if the mouse it caught was a blind mouse and the cat only
caught it by luck? You might think it was a good cat, but when you
bring it home, your house will fill up with mice.
Programming that works in one situation might fail in another situation
so your idea that because something works in one situation it is
therefore ok is bound to get you in trouble if you do any amount of
programming.
> ps. please forgive my poor English... ^_^
No problem, this is an international group and all are welcome.
Besides, you made yourself very well understood. ^_^
--
Jeff
------------------------------
Date: Fri, 18 Aug 2000 01:29:02 GMT
From: bluearchtop@my-deja.com
Subject: Eval and Regexps Help
Message-Id: <8ni3gd$b0t$1@nnrp1.deja.com>
Hi,
I want to be able to embed perl code in a string delimited by <% %> and
have it evaluated.
Example:
$str=<<_EOF_;
This
is
a
<%
print "HELLO WORLD";
print localtime(time);
%>
TEST
AND
<%
print "HI";
%>
_EOF_
$str=~s/<%(.*?)%>/eval $1/iesg;
print $str;
=====================
It prints out:
HELLO WORLD3051317710042291HITHis i
is
a
1
TEST
AND
1
=========================
Couple problems:
1) It doesn't print the evaluated code in the place I want it.
It prints a 1 where I want the output to go.
2) If there is an error in the code, how can I neatly capture and print
the error?
3) Is this the most efficient way to do this? It will be called a
lot...
Thanks!!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 17 Aug 2000 21:22:26 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Eval and Regexps Help
Message-Id: <8ni6l2$gtg$1@provolone.cs.utexas.edu>
In article <8ni3gd$b0t$1@nnrp1.deja.com>, <bluearchtop@my-deja.com> wrote:
>I want to be able to embed perl code in a string delimited by <% %> and
>have it evaluated.
>
> print "HELLO WORLD";
> print localtime(time);
:
:
>$str=~s/<%(.*?)%>/eval $1/iesg;
>print $str;
The "e" option on your s/// operator already does an eval, so by
putting eval in there, it seems like you're going to end evaluating the
code twice, and that's probably not good.
So, why not try this?
$str =~ s/<%(.*?)%>/$1/esg;
Hope that helps.
- Logan
------------------------------
Date: Fri, 18 Aug 2000 02:50:48 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Eval and Regexps Help
Message-Id: <MPG.140741fb1a0ccb7b9896c9@localhost>
bluearchtop@my-deja.com wrote ..
>Hi,
>
>I want to be able to embed perl code in a string delimited by <% %> and
>have it evaluated.
>
>Example:
>
>$str=<<_EOF_;
>This
>is
>a
><%
> print "HELLO WORLD";
> print localtime(time);
>%>
>
>TEST
>
>AND
>
><%
>print "HI";
>%>
>
>_EOF_
>
>$str=~s/<%(.*?)%>/eval $1/iesg;
>print $str;
>=====================
>It prints out:
>HELLO WORLD3051317710042291HITHis i
>is
>a
>1
>
>TEST
>
>AND
>
>1
>
>=========================
>Couple problems:
>
>1) It doesn't print the evaluated code in the place I want it.
>It prints a 1 where I want the output to go.
of course it does .. you're asking it to replace the <%%>s with the
return of the 'eval'ed code .. a successful print returns '1' .. and the
return value of eval is the return value of the last 'eval'ed line of
code .. so the substitution is made .. then you print that result out
essentially what you're replicating is this
print "Some text", print("Hello World"), "some other text\n";
and it will do the same thing .. so .. you EITHER want to execute the
code within <%%>s or you want to print out the result of that code
what you're really trying to do is print everything outside of <%%>s and
execute everything inside <%%> .. your simple substitution will not
accomplish this
>3) Is this the most efficient way to do this? It will be called a
>lot...
depends what you mean by efficient .. CPU / memory / ??
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Fri, 18 Aug 2000 02:55:19 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Eval and Regexps Help
Message-Id: <MPG.14074305e059a80a9896ca@localhost>
Logan Shaw wrote ..
>In article <8ni3gd$b0t$1@nnrp1.deja.com>, <bluearchtop@my-deja.com> wrote:
>>I want to be able to embed perl code in a string delimited by <% %> and
>>have it evaluated.
>>
>> print "HELLO WORLD";
>> print localtime(time);
> :
> :
>>$str=~s/<%(.*?)%>/eval $1/iesg;
>>print $str;
>
>The "e" option on your s/// operator already does an eval, so by
>putting eval in there, it seems like you're going to end evaluating the
>code twice, and that's probably not good.
>
>So, why not try this?
>
> $str =~ s/<%(.*?)%>/$1/esg;
did you try it ? .. I'm guessing not
$1 is evaluated by /e .. but the evaluation of $1 is simply the code
lines .. and they're substituted (not executed)
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: Fri, 18 Aug 2000 03:32:07 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: FileHandle in array
Message-Id: <0c3ppsce3b6u6k3agl28m46iblgh6dkdsg@4ax.com>
On Fri, 18 Aug 2000 00:25:42 GMT, ceeeya <ceeeya@my-deja.com> wrote:
> In article <80hmps4gcj473g38nqdiv7ok991pln0peh@4ax.com>,
> Abe Timmerman <abe@ztreet.demon.nl> wrote:
> >
[ snip my code that uses readline($file->[1]) ]
>
> Thanks for tips. I'm still having trouble with the readline. The
> construct above does not read any lines. It does appear to be
> syntactically correct. I have been successful with this:
>
> for my $file (@files) {
> open $file->[1], $file->[0] or
> die "Can't open[r] '$file->[0]': $!";
> $fh = $file->[1];
> while ( <$fh> ) {
> print;
> }
> close $file->[1];
> }
Yep. I found that readline() doesn't work on my Linux box (perl
5.005_03) either. No problem on NT4 and ActivePerl 5.6.0 (616). The
entry for readline() in perlfunc doesn't seem to have changed.
> I've been pouring over perlref, but haven't been able to make the proper
> connect yet.
The FileHandle manpage says:
$fh->getline
This works like <$fh> described in the section on "I/O Operators" in
the perlop manpage except that it's more readable and can be safely
called in an array context but still returns just one line.
But don't get your hopes up, that didn't work either. Looks like a bug.
--
Good luck,
Abe
------------------------------
Date: Fri, 18 Aug 2000 01:23:47 GMT
From: "Cooljazz" <cooljazz.nospam@flash.net>
Subject: Help on Error Message: "Document Contains No Data"
Message-Id: <De0n5.431$OT5.21082@news.flash.net>
My ISP recently switched servers and now my guestbook won't work. I've
changed all the paths as per their instructions, chmod the files and
directories, but still nothing. Please help me!
The file is:
http://www.quintango.com/guest/addguest.html
The top part of the Perl script (the part that changed) is:
#!/bin/perl
############################################################################
##
# Guestbook Version 2.3.1
#
# Copyright 1996 Matt Wright mattw@worldwidemart.com
#
# Created 4/21/95 Last Modified 10/29/95
#
# Scripts Archive at: http://www.worldwidemart.com/scripts/
#
############################################################################
##
# COPYRIGHT NOTICE
#
# Copyright 1996 Matthew M. Wright All Rights Reserved.
#
#
#
# Guestbook may be used and modified free of charge by anyone so long as
#
# this copyright notice and the comments above remain intact. By using this
#
# code you agree to indemnify Matthew M. Wright from any liability that
#
# might arise from it's use.
#
#
#
# Selling the code for this program without prior written consent is
#
# expressly forbidden. In other words, please ask first before you try and
#
# make money off of my program.
#
#
#
# Obtain permission before redistributing this software over the Internet or
#
# in any other medium. In all cases copyright and header must remain
intact.#
############################################################################
##
# Set Variables
$guestbookurl = "http://www.quintango.com/guest/guestbook3.html";
$guestbookreal = "/custs/home/q/quintang/guest/guestbook3.html";
$guestlog = "/custs/home/q/quintang/guest/guestlog.html";
$cgiurl = "http://www.quintango.com/cgi-bin/guestbook.pl";
$date_command = "/bin/date";
# Set Your Options:
$mail = 1; # 1 = Yes; 0 = No
$uselog = 1; # 1 = Yes; 0 = No
$linkmail = 1; # 1 = Yes; 0 = No
$separator = 1; # 1 = <hr>; 0 = <p>
$redirection = 0; # 1 = Yes; 0 = No
$entry_order = 1; # 1 = Newest entries added first;
# 0 = Newest Entries added last.
$remote_mail = 1; # 1 = Yes; 0 = No
$allow_html = 1; # 1 = Yes; 0 = No
$line_breaks = 0; # 1 = Yes; 0 = No
# If you answered 1 to $mail or $remote_mail you will need to fill out
# these variables below:
$mailprog = '/usr/lib/sendmail';
$recipient = 'tango@quintango.com';
-------------------------
Thanks in advance.
Jonathan
------------------------------
Date: Fri, 18 Aug 2000 02:20:17 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Help on Error Message: "Document Contains No Data"
Message-Id: <slrn8pp7b3.f1f.mgjv@verbruggen.comdyn.com.au>
On Fri, 18 Aug 2000 01:23:47 GMT,
Cooljazz <cooljazz.nospam@flash.net> wrote:
> My ISP recently switched servers and now my guestbook won't work. I've
> changed all the paths as per their instructions, chmod the files and
> directories, but still nothing. Please help me!
The error message you describe in the subject is not a Perl error
message. Most likely the perl error message ended up in the HTTP
server log. Without those particular error messages you won't get far
in discovering what the problem is.
> #!/bin/perl
This is unlikely. Sure it shouldn't be /usr/local/bin/perl or at least
/usr/bin/perl? Anyone who installs the perl binary in /bin should be
summarily shot :)
> # Copyright 1996 Matt Wright mattw@worldwidemart.com
This is part of your problem. Search the history of this newsgroup on
that name to find out what the general opinion about these scripts is.
Use something like www.deja.com for that.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | Curiouser and curiouser, said Alice.
NSW, Australia |
------------------------------
Date: Fri, 18 Aug 2000 02:27:02 GMT
From: Joel Nelson <joelnelson@home.net>
Subject: Re: Help on Error Message: "Document Contains No Data"
Message-Id: <399C9ED9.1FCC7130@home.net>
Cooljazz wrote:
> My ISP recently switched servers and now my guestbook won't work. I've
> changed all the paths as per their instructions, chmod the files and
> directories, but still nothing. Please help me!
>
> The file is:
> http://www.quintango.com/guest/addguest.html
>
> The top part of the Perl script (the part that changed) is:
>
> #!/bin/perl
> <snipped useless lines>
> $guestbookurl = "http://www.quintango.com/guest/guestbook3.html";
> $guestbookreal = "/custs/home/q/quintang/guest/guestbook3.html";
> $guestlog = "/custs/home/q/quintang/guest/guestlog.html";
> $cgiurl = "http://www.quintango.com/cgi-bin/guestbook.pl";
> $date_command = "/bin/date";
>
> # Set Your Options:
> $mail = 1; # 1 = Yes; 0 = No
> $uselog = 1; # 1 = Yes; 0 = No
> $linkmail = 1; # 1 = Yes; 0 = No
> $separator = 1; # 1 = <hr>; 0 = <p>
> $redirection = 0; # 1 = Yes; 0 = No
> $entry_order = 1; # 1 = Newest entries added first;
> # 0 = Newest Entries added last.
> $remote_mail = 1; # 1 = Yes; 0 = No
> $allow_html = 1; # 1 = Yes; 0 = No
> $line_breaks = 0; # 1 = Yes; 0 = No
>
> # If you answered 1 to $mail or $remote_mail you will need to fill out
> # these variables below:
> $mailprog = '/usr/lib/sendmail';
> $recipient = 'tango@quintango.com';
I don't see the whole script. In order to help we must see what is causing the
problem. We can't even guess here. Document contains no data sounds like you
never printed anything, or didn't print the headers correctly. Neither of which
I can see here.
Joel
------------------------------
Date: Fri, 18 Aug 2000 02:42:36 GMT
From: decklin+usenet@red-bean.com (Decklin Foster)
Subject: Re: Help on Error Message: "Document Contains No Data"
Message-Id: <wo1n5.930$CW2.9399@news1.rdc1.ct.home.com>
Joel Nelson <joelnelson@home.net> writes:
> I don't see the whole script. In order to help we must see what is
> causing the problem.
We *did* see what the problem was. Look more closely at
> > <snipped useless lines>
--
There is no TRUTH. There is no REALITY. There is no CONSISTENCY. There
are no ABSOLUTE STATEMENTS. I'm very probably wrong. -- BSD fortune(6)
------------------------------
Date: Fri, 18 Aug 2000 03:49:37 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help writing scriptlet interpreter
Message-Id: <399CB27E.61A91EDD@rochester.rr.com>
bluearchtop@my-deja.com wrote:
...
> I want to be able to embed perl code in a string delimited by <% %>
> and have it evaluated.
...
> $str=<<_EOF_;
> This
> is
> a
> <%
> print "HELLO WORLD";
> print localtime(time);
> %>
>
> TEST
>
> AND
>
> <%
> print "HI";
> %>
>
> _EOF_
>
> $str=~s/<%(.*?)%>/eval $1/iesg;
> print $str;
> =====================
> It prints out:
> HELLO WORLD3051317710042291HITHis i
> is
> a
> 1
>
> TEST
>
> AND
>
> 1
>
> =========================
> Couple problems:
>
> 1) It doesn't print the evaluated code in the place I want it.
> It prints a 1 where I want the output to go.
That's because the print command returns a 1 if it was successful. The
returned value of the eval (the thing that gets substituted into $str)
is then 1, not the output of the print commands you thought you were
getting. The contents of the print commands get printed at the time
eval executes (that's why the output of all the print's all comes
first), and the 1 gets substituted and printed later. To fix that, just
leave the print out of the code between your <% and %>, leaving eval to
do its thing. Note that eval will return the value of the last
expression executed, so you'll need a <% and %> for each Perl statement
you want the value to be substituted for, or else arrange the embedded
Perl code so the value of the last statement is what you want
substituted.
>
> 2) If there is an error in the code, how can I neatly capture and print
> the error?
Check $@ -- see
perldoc perlvar
In your case, that won't not catch them right, since you are eval'ing
potentially many times (using the "g" modifier). You could, however,
delete the "g" modifier from the substitution and put the substitution
into a while loop, checking $@ after each iteration. You will have to
be creative about how to nicely present errors, since you probably don't
want to just print them into your output text. Maybe writing them to a
separate file would be good. Maybe STDERR would be good.
...
Hope that helps.
--
Bob Walton
------------------------------
Date: Thu, 17 Aug 2000 20:37:18 -0500
From: "Chakravarthy Sannedhi" <kalyan@uab.edu>
Subject: Is it possible???
Message-Id: <8ni413$e8l$1@SonOfMaze.dpo.uab.edu>
PERL gurus,
We at UAB are working on a Cisco sponsored project for the past one month
about building Voice over IP(VoIP) model. Our intention is to take the
response from various users regarding the voice quality on the Internet. For
this the users will go through each of the following steps *sequentially.*
http://www.dpo.uab.edu/~kalyan/test1.html
So, what I am thinking initially is to create 5 separate web pages for each
step and each web page contains only one of the steps hyperlinked.
Is this possible using perl, as afterwards we have to include system
commands into the perl script to get our tests done.
Let us say, if the first page contains the hyperlink only for *Configure
7200s for T1 Frame Relay*, after that the second page contains hyperlink
only for *Configure NOISER for generating flood of noise*.
So, the bottom line is I want links to .pl files instead of giving links to
.html pages for the pages to get displayed to the user one after the other.
Any suggestions........?
thanks
Chakravarthy K Sannedhi
------------------------------
Date: Fri, 18 Aug 2000 02:22:21 GMT
From: Joel Nelson <joelnelson@home.net>
Subject: Re: Is it possible???
Message-Id: <399C9DC1.598CB430@home.net>
Chakravarthy Sannedhi wrote:
> PERL gurus,
Well, not me, maybe others.
> We at UAB are working on a Cisco sponsored project for the past one month
> about building Voice over IP(VoIP) model. Our intention is to take the
> response from various users regarding the voice quality on the Internet. For
> this the users will go through each of the following steps *sequentially.*
> http://www.dpo.uab.edu/~kalyan/test1.html
> So, what I am thinking initially is to create 5 separate web pages for each
> step and each web page contains only one of the steps hyperlinked.
> Is this possible using perl, as afterwards we have to include system
> commands into the perl script to get our tests done.
Anything is possible in perl!!
> Let us say, if the first page contains the hyperlink only for *Configure
> 7200s for T1 Frame Relay*, after that the second page contains hyperlink
> only for *Configure NOISER for generating flood of noise*.
> So, the bottom line is I want links to .pl files instead of giving links to
> .html pages for the pages to get displayed to the user one after the other.
> Any suggestions........?
This not really a perl question but a cgi question. Sure you can do it. You
don't even ever have to have a .html file. They can all be .pl files. Once perl
is installed, check the docs and specifically look at the 'CGI' module. You'll
find it's all you need besides code logic.
Joel
------------------------------
Date: 17 Aug 2000 23:07:19 -0400
From: darkon@one.net (David Wall)
Subject: Re: Out of memory! error. Working with arrays...
Message-Id: <8F93E2A04darkononenet@206.112.192.118>
samara_biz@hotmail.com (Alex T.) wrote in <399C1BBE.1E5DB6EA@hotmail.com>:
> foreach my $index (@database){
> print TARGET %{$database[$index]}->{Address}."\n";
> } #foreach
I'm not sure what that print statement is doing (something strange,
anyway), and I know I don't want to think about it. What's wrong with
print TARGET $index->{Address}."\n";
?
I'd also take Jeff Zucker's and Ben Kennedy's suggestions, too.
(I did test this. I got bored with testing it after I got up to 10 MB data
files. My PC only has 128MB RAM, not 160.)(Only! I used to dream of 128
MB RAM.... but tell the young folks today that...)
--
David Wall
darkon@one.net
------------------------------
Date: Fri, 18 Aug 2000 02:09:00 GMT
From: Dave Rayner <drayner@atnf.csiro.au>
Subject: Scalar range operator
Message-Id: <399C9ABC.F1B0DB78@atnf.csiro.au>
Hi All,
Can anyone explain the behaviour of the following piece of code?
---------------------------------
#!/usr/local/bin/perl
open(SUBPROC, "echo|") || die;
#my $nothing=<SUBPROC>; # uncommenting out this line makes it fail!
close SUBPROC;
my $res='4';
my $val=($res==4 .. 0);
print ($val,"\n"); # Should be 1, the first in the sequence
---------------------------------
From page 90 of the Camel book, I see that the scalar range operator ..
returns the sequence number (1 the first time it is true), and appends
an "E0" if it is the last in a sequence. So the range operator in the
following should return 1, which it does.
If, however, you uncomment the said line, the range operator returns
"1E0".
Anyone know why that is?
Tested on 5.004_04 for sun4-solaris and version 5.004_01 on digital
unix.
Regards, Dave R.
------------------------------
Date: Fri, 18 Aug 2000 01:59:01 GMT
From: cedop@my-deja.com
Subject: setting up a cgi directory
Message-Id: <8ni58s$cu4$1@nnrp1.deja.com>
Hello,
can someone please tell me how I set up a cgi-bin directory, so that I
can execute a perl script from a web page. My system is running linux
6.2 (Redhat), and perl is installed.
When I type which perl, I get
/usr/bin/perl
when I execute a perl script by typing
perl scriptName.pl
it works fine, but when i try to run the script from the web browser, I
just get an error page
Please help, am extreemely desperate.
sincerely
elias sukkar
Also, please send reply to
cedop@bigpond.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 18 Aug 2000 02:30:49 GMT
From: Joel Nelson <joelnelson@home.net>
Subject: Re: setting up a cgi directory
Message-Id: <399C9FBC.26A4DEC6@home.net>
cedop@my-deja.com wrote:
> Hello,
>
> can someone please tell me how I set up a cgi-bin directory, so that I
> can execute a perl script from a web page. My system is running linux
> 6.2 (Redhat), and perl is installed.
>
> When I type which perl, I get
> /usr/bin/perl
>
> when I execute a perl script by typing
> perl scriptName.pl
>
> it works fine, but when i try to run the script from the web browser, I
> just get an error page
>
> Please help, am extreemely desperate.
This doesn't really have much to do with perl. You should check the redhat
site and/or the apache newsgroups as I am assuming that you installed the
apache web server. The default apache install should get you set up, you
will want to have your httpd.conf file handy when you ask those groups.
Joel
------------------------------
Date: Thu, 17 Aug 2000 19:33:12 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: setting up a cgi directory
Message-Id: <399CA068.B583A6E1@vpservices.com>
[posted and mailed]
cedop@my-deja.com wrote:
>
> can someone please tell me how I set up a cgi-bin directory,
That has to do with how your webserver is configured, not with how perl
is configured. Since you haven't said what webserver you are running,
I'm afraid we can't even guess what to tell you. Please read the docs
for your webserver and if you still have problems, ask in a newsgroup
about that webserver.
> when I execute a perl script by typing
> perl scriptName.pl
>
> it works fine, but when i try to run the script from the web browser, I
> just get an error page
In other words, perl works fine but your web setup is a problem. So, as
I said, find out what webserver you are running (or install one if you
aren't running one, see www.apache.org, for example) and then read its
documentation to find out how to configure it.
> Also, please send reply to
> cedop@bigpond.com
Well, ok, this first time. But in the future, please remember that
Usenet is a community resource, not a private help desk and if you ask a
question on Usenet you should expect a reply on Usenet.
--
Jeff
------------------------------
Date: Fri, 18 Aug 2000 03:45:05 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Sorting is very slow
Message-Id: <slrn8ppc9v.7uh.tjla@thislove.dyndns.org>
I was shocked! How could Anno Siegel <anno4000@lublin.zrz.tu-berlin.de>
say such a terrible thing:
>Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote in comp.lang.perl.misc:
>
>>As a sidenote, does anyone else feel Perl needs something like Haskell's
>>"zip", "unzip" and related functions? For the uneducated, zip takes two
>>lists and joins them into a two dimensional array (well list actually
>>but why split hairs) by forming pairs of items. unzip does the reverse.
>Another problem is, that many are only well defined when all
>lists have the same length. Your zip is an example. A general
>implementation would have to decide what to do if they aren't.
>Stop where the shorter list ends? Act as if there were so many
>undef's on the shorter list? Who knows what's more useful in
>practice.
Beats me, that's why I asked. I'm no guru. I know in the example I
mentioned (Haskell) they chop it off at the length of the shorter list.
>>I don't think I've explained this well so here is a poor example:
>
>Well, it doesn't do much to clear things up, because it doesn't
>do anything close to what you describe.
Well I *said* "Here is a poor example" :) I think it would be best to
let that piece of code die a peaceful death. nevertheless I feel that
"zip" and friends are actually usefull (if there was an actual working
example).
>[snip]
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
My godda bless, never I see sucha people.
-- Signor Piozzi, quoted by Cecilia Thrale
------------------------------
Date: Fri, 18 Aug 2000 01:16:28 GMT
From: Edge <edge@gecko.org>
Subject: Stuck...why won't this work?
Message-Id: <8ni2ov$abg$1@nnrp1.deja.com>
I'm writing a script that will take the output from an LDAP export, pass
it through a automatically generated awk script and then take that
output and turn it into a script which updates the LDAP server.
what I have is:
==begin snippet==
$field=$ARGV[0];
$field="$field:";
open(AWKOUT,">/tmp/delete.awk");
print AWKOUT "BEGIN {\n";
print AWKOUT " OFS = \":\"\n";
print AWKOUT " }\n\n";
print AWKOUT " {\n";
print AWKOUT " field[\$1] = \$2\n";
print AWKOUT " }\n\n";
print AWKOUT " NF == 0 {\n";
print AWKOUT " if (field[\"$field\"] ) printrecord()\n";
print AWKOUT " for (i in field)\n";
print AWKOUT " delete field[i]\n";
print AWKOUT " }\n\n";
print AWKOUT " END {\n";
print AWKOUT " if (field[\"$field\"] ) printrecord()\n";
print AWKOUT " }\n\n";
print AWKOUT " function printrecord() {\n";
print AWKOUT " print field[\"uid:\"]\n";
print AWKOUT " }\n";
$ldap=`ldapsearch -h ldap-1.dev2 -b ou=People,o=gecko.org uid="*" -L|awk
-f /tmp/delete.awk > /tmp/ldap.txt`;
open(LDAPOUT,">/tmp/ldap.txt");
print LDAPOUT "$ldap";
==end snippet==
the awk script gets generated just fine and /tmp/ldap.txt gets created,
but it's empty. If I use:
print qq{`ldapsearch -h ldap-1.dev2 -b ou=People,o=netdrive.com uid="*"
-L|awk -f /tmp/delete.awk > /tmp/ldap.txt`};
and then paste the result back into my xterm, /tmp/ldap.txt gets
populated.
why won't perl correctly grab the data from the command?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 18 Aug 2000 03:50:01 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Stuck...why won't this work?
Message-Id: <x7itszw7me.fsf@home.sysarch.com>
>>>>> "E" == Edge <edge@gecko.org> writes:
E> I'm writing a script that will take the output from an LDAP export, pass
E> it through a automatically generated awk script and then take that
E> output and turn it into a script which updates the LDAP server.
that is (pardon my expression) nuts! why not just do the work in perl?
you aren't really generating anything complex here.
E> print AWKOUT "BEGIN {\n";
E> print AWKOUT " OFS = \":\"\n";
E> print AWKOUT " }\n\n";
E> print AWKOUT " {\n";
E> print AWKOUT " field[\$1] = \$2\n";
E> print AWKOUT " }\n\n";
regardless of you design decision, use a here doc for that and then you
have only one print and no need to escape all the quotes and put in
explicit newlines.
E> $ldap=`ldapsearch -h ldap-1.dev2 -b ou=People,o=gecko.org uid="*" -L|awk
E> -f /tmp/delete.awk > /tmp/ldap.txt`;
^^^^^^^^^^^^^^^
why are you storing the output into a file AND trying to get output from
the backticks? do you understand those are mutually exclusive as only
one can get output.
E> open(LDAPOUT,">/tmp/ldap.txt");
^
don't open the file for output. that will help i bet.
as i said, just write the code in perl, then run your ldapsearch in
backticks and process that data directly. it will be faster, easier to
maintain and much simpler.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 18 Aug 2000 03:58:21 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Stuck...why won't this work?
Message-Id: <399CB48A.27140CCD@rochester.rr.com>
Edge wrote:
>
> I'm writing a script that will take the output from an LDAP export, pass
> it through a automatically generated awk script and then take that
> output and turn it into a script which updates the LDAP server.
>
> what I have is:
>
> ==begin snippet==
> $field=$ARGV[0];
> $field="$field:";
> open(AWKOUT,">/tmp/delete.awk");
>
> print AWKOUT "BEGIN {\n";
> print AWKOUT " OFS = \":\"\n";
> print AWKOUT " }\n\n";
> print AWKOUT " {\n";
> print AWKOUT " field[\$1] = \$2\n";
> print AWKOUT " }\n\n";
> print AWKOUT " NF == 0 {\n";
> print AWKOUT " if (field[\"$field\"] ) printrecord()\n";
> print AWKOUT " for (i in field)\n";
> print AWKOUT " delete field[i]\n";
> print AWKOUT " }\n\n";
> print AWKOUT " END {\n";
> print AWKOUT " if (field[\"$field\"] ) printrecord()\n";
> print AWKOUT " }\n\n";
> print AWKOUT " function printrecord() {\n";
> print AWKOUT " print field[\"uid:\"]\n";
> print AWKOUT " }\n";
>
close AWKOUT;
> $ldap=`ldapsearch -h ldap-1.dev2 -b ou=People,o=gecko.org uid="*" -L|awk
> -f /tmp/delete.awk > /tmp/ldap.txt`;
> open(LDAPOUT,">/tmp/ldap.txt");
> print LDAPOUT "$ldap";
>
> ==end snippet==
>
> the awk script gets generated just fine and /tmp/ldap.txt gets created,
> but it's empty. If I use:
> print qq{`ldapsearch -h ldap-1.dev2 -b ou=People,o=netdrive.com uid="*"
> -L|awk -f /tmp/delete.awk > /tmp/ldap.txt`};
> and then paste the result back into my xterm, /tmp/ldap.txt gets
> populated.
>
> why won't perl correctly grab the data from the command?
You forgot to close the file you were writing for awk. Buffering
prevents the last portion (or, in this case, probably all) of the file
from actually being written at the time awk tries to read it.
...
--
Bob Walton
------------------------------
Date: Fri, 18 Aug 2000 02:02:53 GMT
From: johnvert@my-deja.com
Subject: The diamond operator.
Message-Id: <8ni5g3$dem$1@nnrp1.deja.com>
Greetings,
$Learning Perl$ claims that: "..the diamond operator reads each line of
file1 followed by each line of file2 and file 3 in turn, returning undef
when all lines have been read."
In that example's case, "file1", "file2", and "file3" are command line
arguments given to the script with the diamond operator.
When I make a test script:
#!/usr/bin/perl
print while (<>);
I run it with no arguments, and then everything I type is echoed back.
Why is that? If I do give it arguments, it indeed prints them out, but
I don't understand the behavior I'm getting when I don't. Hoping
someone could clarify that. Also, an unrelated question: is it possible
to search perlfaq1 perlfaq2 perlfaq3 etc.. all at once? Sometimes I
have questions that I feel are in the FAQ, but I can't search through
all of it.
Thank you very much,
-- john
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 18 Aug 2000 02:38:09 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: The diamond operator.
Message-Id: <lk1n5.109461$A%3.1436977@news1.rdc2.pa.home.com>
<johnvert@my-deja.com> wrote in message news:8ni5g3$dem$1@nnrp1.deja.com...
> Greetings,
>
> $Learning Perl$ claims that: "..the diamond operator reads each line of
> file1 followed by each line of file2 and file 3 in turn, returning undef
> when all lines have been read."
>
> In that example's case, "file1", "file2", and "file3" are command line
> arguments given to the script with the diamond operator.
>
> When I make a test script:
>
> #!/usr/bin/perl
> print while (<>);
>
> I run it with no arguments, and then everything I type is echoed back.
> Why is that? If I do give it arguments, it indeed prints them out, but
> I don't understand the behavior I'm getting when I don't. Hoping
> someone could clarify that. Also, an unrelated question: is it possible
> to search perlfaq1 perlfaq2 perlfaq3 etc.. all at once? Sometimes I
> have questions that I feel are in the FAQ, but I can't search through
> all of it.
When you first use <>, perl checks @ARGV to look for filenames to open. If
$ARGV[0] is not defined, it defaults to opening "-", which is just standard
input - thats why all your text is echoed back, since <> is extracting text
from STDIN. Also, 'perldoc -q term' will pull relavant entries from all
FAQs, for instance "perldoc -q variable". Hope this helps --
--Ben Kennedy
------------------------------
Date: Fri, 18 Aug 2000 03:24:44 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Two pipes and only one runs, why?
Message-Id: <399CACA9.AA7B88@rochester.rr.com>
"Paul R. Andersen" wrote:
>
> The code below is about the minimum I could come up with that
> demonstrates the problem I am having. I clipped this from the program I
> am working on (and simplified stuff) so while it looks kind of strange
> now, it has the elements in it I need. The goal is for the first pipe
> to let the user know that something is happening (and keep the window
> refreshed after it was covered for example). The second pipe is
> representative of one of several sequential processes that would be
> fairly long running (20-30 minutes each).
>
> I am expecting output that looks about like:
> LP is underway.
> XXX
> LP did something.
> XXX
> LP did something.
> XXX
> .
> .
> .
>
> but I am seeing:
> LP is underway.
> LP did something.
> XXXXXXXXXXXXXXXXXXXXXXXX
>
> So can someone please explain to me first where this is getting stuck
> and second how to fix it?
...
> Paul Andersen
...
I haven't studied your code in detail, but I'm certain your problem is
merely that of the buffering of the output. To turn buffering off, put
$|=1;
while the filehandle is selected in your program. See
perldoc perlvar
perldoc -f select
perldoc IO::Handle
for more information. What happens is they by default (for efficiency
purposes), Perl buffers its output, perhaps in chucks, say, 8K bytes
long. If you print to something, the output is actually generated only
when the buffer fills (or the filehandle is closed). Do you can, for
example, write stuff to another program via a pipe, and that program
will not receive anything until 8K bytes of output has been generated.
In the meantime, your program might be writing stuff to STDOUT which is
also buffered. The output will end up looking like yours does -- chunks
of stuff intermingled in apparently strange ways. Turning off buffering
via $|=1 fixes all that. You may have to individually turn off $| on
more than one filehandle depending upon how many you are using
simultaneously. Hope that helps.
--
Bob Walton
------------------------------
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 4053
**************************************