[6554] in Perl-Users-Digest
Perl-Users Digest, Issue: 179 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 25 20:08:10 1997
Date: Tue, 25 Mar 97 17:00:21 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 25 Mar 1997 Volume: 8 Number: 179
Today's topics:
Re: Accessing the WWW via Perl (Simon Hyde (aka Jeckyll))
Re: ADVICE NEEDED: timelocal() prints wrong result (betty)
Any tools for doing call graphs or code metrics <tibbs@hpc.uh.edu>
Re: bizarre problem - found simple solution <tchrist@mox.perl.com>
Re: case sensativity (Tad McClellan)
Re: chunk POST and receive with LWP or other module (Keith Dreibelbis)
Dbase indexed files and cgi <martin-s@mnplan.state.mn.us>
Re: dereferencing an object in a hash? (Arpad Geller)
does open(FH, "pgm arg1 arg2") take only 1 arg? (Joe McCaughan)
flow control prob??? (Claudia Ma)
Re: Getting filedates in perl <rootbeer@teleport.com>
global my() variable used in foreach() loop loses its v (Ron Newman)
Re: Major Help needed on CGI Forms nickp@futuris.net
Re: multiple key sort <mdb@cdc.noaa.gov>
Re: multiple key sort (Simon Hyde (aka Jeckyll))
Re: Multithreading? <tchrist@mox.perl.com>
Re: Multithreading? <eryq@enteract.com>
Re: On-line web page editor: Changing the directory a <rootbeer@teleport.com>
passing <body bgcolor... in a script?? <qnc496@durhamnews.net>
Porter Needed for NT Perl Domain Name/WebSite Checker S annette@wwip.com
print "Content type: text/html\n\n"; <lorraine@ait.nrl.navy.mil>
Re: Regular Expresion question. (Tad McClellan)
Re: regular expression for check lower case (Rex Fowler)
Re: regular expression for check lower case (Simon Hyde (aka Jeckyll))
Re: text to HTML <dbenhur@egames.com>
Re: Unix 'Cat' equivelent (Josh Purinton)
Re: Unix 'Cat' equivelent <rootbeer@teleport.com>
Unixware 1.1.4 - Perl5.001m Protocol Not Supported <john@execnet.net>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 25 Mar 1997 23:05:46 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: Accessing the WWW via Perl
Message-Id: <33394db6.6243890@news.uni-stuttgart.de>
On 25 Mar 1997 18:06:53 GMT, daniel@aksi.net (Daniel Freeman) wrote:
>I've got this handy little package called getwww that allows me to access
>the WWW via Perl. Now I have a need to access a password protected web site
>(server directory protection; not a cgi-bin style password.)
>
>I can't figure out how to do this. GetWWW simply returns an error "not
>authorized" like the server would return if you tried to access the
>directory with the wrong password.
>
>I'm starting to think that maybe there is a complex form of an URL which
>contains the username and password? If this is the case, I could give
>getWWW that URL instead of the normal one.
>
>Any ideas would be greatly appreciated.
>
I suggest you drop GetWWW and get libwww-perl from
http://www.perl.com/CPAN/modules/by-module/LWP, I believe this does
passwords...although I can't be sure
---
Yours Sincerely,
,
() o /| | |
/\ _ _ _ __ _ _ |___| __| _
/ \| / |/ |/ | / \_/ |/ | | |\| | / | |/
/(__/|_/ | | |_/\__/ | |_/ | |/ \_/|/\_/|_/|__/
/|
\|
(Simon Hyde)
------------------------------
Date: 25 Mar 1997 21:48:42 GMT
From: crocker@ugcs.caltech.edu (betty)
Subject: Re: ADVICE NEEDED: timelocal() prints wrong result
Message-Id: <5h9h7q$66d@gap.cco.caltech.edu>
dusanb@syd.csa.com.au (VK2COT) writes:
>I have written a Perl5 script (I am running Solaris 2.5.1 with
>Perl 5.003) which calculates differences between certain dates. It
>all works fine, except that the
>results are wrong when timelocal() is used on dates that start in
>different months.
>Here is a piece of code that demonstates the problem:
>#!/opt/local/bin/perl
>use Time::Local;
>$AAA = timelocal(37, 53, 04, 1, Mar, 97);
>$BBB = timelocal(37, 53, 22, 27, Feb, 97);
>$CCC = ($AAA - $BBB) > 0 ? ($AAA - $BBB) : abs($AAA - $BBB);
>$DDD = $CCC / 3600;
>printf("%d - %d = %d (%s hours)\n", $AAA, $BBB, $CCC, $DDD);
>exit(0);
>As a result I get:
>852054817i- 854366017 = 2311200 (642 hours)
I don't think timelocal takes a string as input. Shouldn't the month
be a number from 0..11?
try this:
$AAA = timelocal(37, 53, 04, 1, 2, 97);
$BBB = timelocal(37, 53, 22, 27, 1, 97);
(test:
% perl -e 'print join(" ",localtime(852054817)), "\n"'
37 53 9 31 11 96 2 365 0
(9:37:53 Dec 31, 1996)
That ain't right!)
------------------------------
Date: 25 Mar 1997 17:46:20 -0600
From: Jason L Tibbitts III <tibbs@hpc.uh.edu>
Subject: Any tools for doing call graphs or code metrics
Message-Id: <ufalo7br0vn.fsf@sina.hpc.uh.edu>
I find myself needing to track the flow of code in a medium-sized project
(~10K lines) but I see no real cross-referencing tools.
I tried B::Xref and it looks promising, but it generates a nice report and
then it starts dumping binary data. (I can't tell if it's supposed to or
not.)
CPAN-WAIT didn't reveal anything else that might be useful. There must be
something. How do people manage larger projects?
--
Jason L. Tibbitts III - tibbs@uh.edu - 713/743-8684 - 221SR1
System Manager: University of Houston High Performance Computing Center
1994 PC800 "Kuroneko" DoD# 1723
------------------------------
Date: 25 Mar 1997 21:59:05 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: bizarre problem - found simple solution
Message-Id: <5h9hr9$645$3@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
clive@bigfish.co.uk writes:
:chdir "\data" (or something like that)
Never ever ever use backslashes for pathnames. It's Microsoft
Brain Damage, and you must not succumb, for it will come back
to torture you.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"A journey of a thousand miles continues with the second step." --Larry Wall
------------------------------
Date: Tue, 25 Mar 1997 08:55:37 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: case sensativity
Message-Id: <91p8h5.uc1.ln@localhost>
Jon Bell (jtbell@presby.edu) wrote:
: Andrew M. Langmead <aml@world.std.com> wrote:
: >mirage@tsil.net writes:
: >
: >>Is there anyway to keep Perl, Java, JavaScript, etc from being
: >>case sensitive?
: >
: >I think that I'm missing something, first you compain about perl
: >et. al. being case sensitive. (That the identifers, $VAR, $Var, and
: >$var are different.) and then complain that you can't use mixed case
: >(To me implying that you must use $var, and the identifiers $VAR or
: >$Var are illegal.) Or are you saying that because the identifiers are
: >case sensitive you force yourself to use all lowercase letters to
: >prevent using the wrong case?
: No, he's saying that he wants (for example) $var, $VAR, $Var, $VaR, etc, to
: all refer to the same variable. This is the way Pascal works. I bet
: that's the language he's coming from.
Things that *look* different are in fact *not* different?
What advantage is there to that? Seems like a hinderance to understanding
to me..
I prefer things that look different to _be_ different.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 25 Mar 1997 22:18:11 GMT
From: dribbs@netspace.org (Keith Dreibelbis)
Subject: Re: chunk POST and receive with LWP or other module
Message-Id: <5h9iv3$kl2@cocoa.brown.edu>
Thank you all for your suggestions; I just thought I should followup with
a final solution.
Gisle Aas (aas@bergen.sn.no) wrote:
: dribbs@netspace.org (Keith Dreibelbis) writes:
: > In looking through LWP and friends I found that if you wish to retrieve a
: > large file from an HTTP::Request, there is a nice way to process the file
: > in chunks, or to export the output to a file.
: >
: > I am curious if the opposite is possible, i.e. if you can have a variable
: > to POST that actually comes from a file.
: You can let the $req->content be a reference to a subroutine and you
: can make this subroutine read data from a file. Since the LWP client
: code only support HTTP/1.0 you will have to set the
: $req->content_length() correctly.
: open(F, "/etc/hosts");
: $req = new HTTP::Request POST => "http://somewhere.com/";
: $req->content_length(-s F);
: $req->content(sub { scalar(<F>) });
: $ua->request($req);
This is very close to my final solution. The only problem was that having
the subroutine reference read one line of a file was too much overhead for
a 458,880 line file. The CGI would only get 18% of the file before it was
cut off. (timed out, something) Having the subroutine return 100 or 1000
lines at a time fixed the problem.
Oh, and the receiving CGI must process the thing from STDIN *before*
declaring a CGI object, or the CGI object will try to grab it. (in
memory!)
Thanks again.
--
Keith Dreibelbis
dribbs@netspace.org
------------------------------
Date: Tue, 25 Mar 1997 15:16:52 -0600
From: Stephanie Martin <martin-s@mnplan.state.mn.us>
Subject: Dbase indexed files and cgi
Message-Id: <333840C4.2118@mnplan.state.mn.us>
I've got a problem!!
I need to be able to open a dbase file (sitting on a unix system) on an
index associated with it, then be able to seek in that file on that
index. The problem is that I need to do this with a cgi script (in
perl) (unless there is another option?!). I've been using the Xbase
module but it will only open a dbf file in the original order, not
indexed.
Is anyone familiar enough with Xbase to suggest how to modify the open
and seek functions? Does anyone have any other suggestions about how to
do this?
Thanks, Stephanie
------------------------------
Date: 25 Mar 1997 23:32:02 GMT
From: arpad@tezcat.com (Arpad Geller)
Subject: Re: dereferencing an object in a hash?
Message-Id: <5h9n9i$fp@chinx10.tpa.net>
In article <5h4t94$gh9@chinx10.tpa.net>, arpad@tezcat.com says...
>
>$query = new CGI;
>
>tie (%Quest, GDBM_File, "filename", &GDBM_WRCREAT, 0640);
>
>@names = $query->param;
>
>foreach $key (@names) {
> print "key = $key value = ", $query->param($key), "\n";
> $Quest{$key} = {$query->param($key)};
>}
>
>untie (%Quest);
>
The solution is: Don't put brackets around the value in the hash
assignment, so it should be:
$Quest{$key} = $query->param($key);
(duh)
Thanks to all who responded.
--
Peace,
Arpi
David
(773)395-8581<voice> webmaster@cyberchicago.com
(773)862-4144<alternate phone> gelldav@elof.cns.iit.edu
(773)395-8582<fax> geller@thoughtport.com
Chicago, IL
UNSOLICITED COMMERCIAL EMAIL IS NOT APPRECIATED
The Internet is not your "free" advertising medium. We all pay
by your waste of bandwith
------------------------------
Date: 25 Mar 1997 22:42:03 GMT
From: shiloh@best.com (Joe McCaughan)
Subject: does open(FH, "pgm arg1 arg2") take only 1 arg?
Message-Id: <5h9kbr$ded$1@nntp2.ba.best.com>
Hi,
I cannot get the following construction to see more than 1 arg.
I'm using perl4.
open(JUNK, "start.pl $arg1 $arg2 |);
It sees $arg1 OK but nothing after it. I put print statements in
to make sure that the args were defined. This is a major
drawback for my work. If anyone has an idea (or work-around),
I'd appreciate it.
BTW start.pl arg1 arg2 <cr> works fine in /bin/sh or
from the command line.
thanks a lot,
--Joe McCaughan
shiloh@best.com
------------------------------
Date: 25 Mar 1997 22:33:31 GMT
From: maclaudi@cps.msu.edu (Claudia Ma)
Subject: flow control prob???
Message-Id: <5h9jrr$olk$1@msunews.cl.msu.edu>
Hi there,
I have a question about flow control:
$err1 = (Cond1);
$err2 = (Cond2);
$err3 = (Cond3);
if ($err1 || $err2 || $err3) {
&err_msg;
}
...
No matter what change I made in Cond1/Cond2/Cond3, the script always gave me
&err_msg. I printed $err2/$err2/$err3, and found that they worked fine,
either "1" or "".
Can someone tell me: In this case, $err1 is a string or not? And why my
code didn't work?
Thanks a lot!
-Claudia
--
============================================================
Claudia Y. Ma, Computer Science Dept., MSU
Email: maclaudi@cps.msu.edu
URL: http://www.cps.msu.edu/~maclaudi
============================================================
------------------------------
Date: Tue, 25 Mar 1997 15:52:00 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Oscar Wahlberg <qraoswa@era-lvk.ericsson.se>
Subject: Re: Getting filedates in perl
Message-Id: <Pine.GSO.3.96.970325154225.27841A-100000@kelly.teleport.com>
On Tue, 25 Mar 1997, Oscar Wahlberg wrote:
> I need to do this because I want to run specific code
> if a file is older than ten minutes.
The time returned by -M is relative to the time your script started
running (which is stored in $^T, so you could modify it). If it was
modified after your script was started, -M can return a negative number.
But if you mean "not modified since ten minutes ago", for an everchanging
sense of 'ago', maybe you want something like this.
if ( time - (stat $filename)[9] >= 10 * 60 ) { ...
Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 25 Mar 1997 17:08:48 -0500
From: rnewman@shell1.cybercom.net (Ron Newman)
Subject: global my() variable used in foreach() loop loses its value
Message-Id: <5h9idg$9o0@shell1.cybercom.net>
Here's a Perl script whose behavior I don't understand at all.
I am using a global variable, declared my() at the top level, as
the loop control variable in a "foreach" loop. Inside the loop,
I call a subroutine which access the global variable. Instead
of getting the expected value of the variable, it instead finds
the variable to be empty. Why?
***** The perl script ********
#!/usr/local/bin/perl -w
use strict;
my $topic;
main();
sub main {
my @topics = ("first", "second", "third", "fourth");
foreach $topic (@topics) {
print "In loop: topic is $topic\n";
subroutine();
}
}
sub subroutine {
print "In subroutine: topic is $topic\n";
}
******* The output **********
In loop: topic is first
Use of uninitialized value at /tmp/foo.pl line 18.
In subroutine: topic is
In loop: topic is second
Use of uninitialized value at /tmp/foo.pl line 18.
In subroutine: topic is
In loop: topic is third
Use of uninitialized value at /tmp/foo.pl line 18.
In subroutine: topic is
In loop: topic is fourth
Use of uninitialized value at /tmp/foo.pl line 18.
In subroutine: topic is
****** end of output *******
If I remove these two lines:
use strict;
my $topic;
the program behaves properly:
In loop: topic is first
In subroutine: topic is first
In loop: topic is second
In subroutine: topic is second
In loop: topic is third
In subroutine: topic is third
In loop: topic is fourth
In subroutine: topic is fourth
Can anyone explain this?
--
Ron Newman rnewman@cybercom.net
Web: http://www.cybercom.net/~rnewman/home.html
------------------------------
Date: Tue, 25 Mar 1997 17:21:07 -0600
From: nickp@futuris.net
Subject: Re: Major Help needed on CGI Forms
Message-Id: <859331813.19437@dejanews.com>
> Hi I'm an artist for the net but I need to be able to put forms on my
> WWW sites that send a meaning full reply HELP.
I have a forms tuorial which explains writing forms and a little of the
CGI behind them:
http://www.futuris.net/nickp/tags/forms/
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: 25 Mar 1997 15:40:48 -0700
From: Mark Borges <mdb@cdc.noaa.gov>
Subject: Re: multiple key sort
Message-Id: <vklo7bbnnz.fsf@cdc.noaa.gov>
>> On 25 Mar 1997 11:39:56 -0700,
>> Mark Borges(mb) wrote:
mb> I'm trying to sort a bibliographic database in refer(1) format by
mb> multiple keys: (1) lead author, (2) date, (3) remaining
mb> authors. The only thing I can come up with right now (far from
mb> perfect) is to
Hey, Mark -- did you RTFFAQ? If so, you would've seen:
If you need to sort on several fields, the following paradigm is
useful.
@sorted = sort { field1($a) <=> field1($b) ||
field2($a) cmp field2($b) ||
field3($a) cmp field3($b)
} @data;
The FAQ is your friend ;-).
(Sorry for the wasted bandwidth).
--
-mb-
------------------------------
Date: Tue, 25 Mar 1997 23:23:44 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: multiple key sort
Message-Id: <33385bc6.9844854@news.brad.ac.uk>
On 25 Mar 1997 11:39:56 -0700, Mark Borges <mdb@cdc.noaa.gov> wrote:
>I'm trying to sort a bibliographic database in refer(1) format by
>multiple keys: (1) lead author, (2) date, (3) remaining authors. The
>only thing I can come up with right now (far from perfect) is to
>create a secondary integer index and use the ord() function:
>
>----------------------------------------
> @idx = ();
> $ix = 0;
> for (@biblio) {
> for (split("\n",$_)) {
> if (/^%A (.*)/ and $ix == 0) {
> $lead = uc( (split(',',$1))[0] );
> $lead =~ s/^\s*//;
> for (1,2,3,4,5) {
> $fac = 10**(12-(2*$_));
> $ix = $ix + $fac*ord(substr($lead,$_-1,1));
> }
>
> } elsif (/^%D (.*)/) {
> ($val = $1) =~ s/^\s+//;
> $ix = $ix + 2000 - $val;
> push(@idx,$ix);
> print "ix=$idx[-1]\n";
> $ix = 0;
> last;
> }
> }
> }
>
> for (@biblio[ sort { $idx[$a] <=> $idx[$b] } 0 .. $#idx ]) {
> # do stuff
> }
>----------------------------------------
>
>but this is so ugly there must be a more better way ;-). Not only
>that, it's fragile and will surely break for some cases (it ignores
>the remaining authors in the sort for now).
Yeah...very ugly and virtually incomprehsible
>
>Has anyone else come across a more elegant solution?
Try this:
foreach(@biblio){
push(@biblio_2d, [split(/\n/, $_)]);
}
@biblio_2d = sort {($a->[0] cmp $b->[0]) || ($a->[1] cmp $b->[1]) ||
($a->[2] cmp $a->[2]) } @biblio_2d;
@biblio = ();
foreach(@biblio_2d){
push(@biblio, join("\n", @$_));
}
#Biblio is now sorted :-)
---
Yours Sincerely,
,
() o /| | |
/\ _ _ _ __ _ _ |___| __| _
/ \| / |/ |/ | / \_/ |/ | | |\| | / | |/
/(__/|_/ | | |_/\__/ | |_/ | |/ \_/|/\_/|_/|__/
/|
\|
(Simon Hyde)
------------------------------
Date: 25 Mar 1997 22:51:32 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Multithreading?
Message-Id: <5h9ktk$9h6$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
Elliot Mednick <elliot@wellspring.com> writes:
:So, is -- or will there be -- multithreading support in Perl?
Yes, in the 5.005 release.
--tom
--
Tom Christiansen tchrist@jhereg.perl.com
"Just because you're into control doesn't mean you're in control."
--Larry Wall
------------------------------
Date: Tue, 25 Mar 1997 17:49:14 -0600
From: Eryq <eryq@enteract.com>
Subject: Re: Multithreading?
Message-Id: <3338647A.5388675D@enteract.com>
Tom Christiansen wrote:
>
> [courtesy cc of this posting sent to cited author via email]
>
> In comp.lang.perl.misc,
> Elliot Mednick <elliot@wellspring.com> writes:
> :So, is -- or will there be -- multithreading support in Perl?
>
> Yes, in the 5.005 release.
I take it Perl will need to be compiled with sfio.
At last count, there were other non-thread-safe libraries that
were big players in Perl (libgdbm, I think, is one): do you forsee
a big shift in Perl's code base coming?
Just curious,
--
___ _ _ _ _ ___ _ Eryq (eryq@enteract.com)
/ _ \| '_| | | |/ _ ' / Hughes STX, NASA/Goddard Space Flight Cntr.
| __/| | | |_| | |_| | http://www.enteract.com/~eryq
\___||_| \__, |\__, |___/\ Visit STREETWISE, Chicago's newspaper by/
|___/ |______/ of the homeless: http://www.streetwise.org
------------------------------
Date: Tue, 25 Mar 1997 16:32:40 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Zyana <zyanya@ix.netcom.com>
Subject: Re: On-line web page editor: Changing the directory a file is written to?
Message-Id: <Pine.GSO.3.96.970325163047.27841E-100000@kelly.teleport.com>
On 25 Mar 1997, Zyana wrote:
> However... I just cannot find the command(s) for changing to (for
> writing) or just plain writing to, the different directory, from the
> script that runs this thing.
Check out perlfunc(1), which has several helpful Perl operators and
examples. Also, when you're having trouble with a CGI form in Perl, you
should first look at the please-don't-be-offended-by-the-name Idiot's
Guide to solving such problems. It's available on the perl.com web pages.
Hope this helps!
http://www.perl.com/perl/
http://www.perl.com/perl/faq/
http://www.perl.com/perl/faq/idiots-guide.html
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 26 Mar 1997 00:11:32 GMT
From: Richard Morin <qnc496@durhamnews.net>
Subject: passing <body bgcolor... in a script??
Message-Id: <5h9pjk$t30@nr1.toronto.istar.net>
Hi folks,
This novice has been working on a script which I copied out of the Linux
Journal for a cgi quiz. My only trouble seems to be passing extra html
variables off to the page.
How do I dictate my <body bgcolor="#blahblah"> or pass off other html such
as images and links. Pointers to some docs would be greatly appreciated.
Richard Morin
qnc496@durhamnews.net
===============================================================================
I only changed one line and it was a comment...
------------------------------
Date: Tue, 25 Mar 1997 15:01:21 -0600
From: annette@wwip.com
Subject: Porter Needed for NT Perl Domain Name/WebSite Checker Script
Message-Id: <859323171.13424@dejanews.com>
Hi,
I had a short script written for me by a UNIX programmer that was unable
to port it to Perl for NT which I have installed on my NT 3.51 server. I'd
like to hire an experienced Perl for NT programmer who can port it,
install it on my server (I'll give you ftp and telnet access), and test it
to make sure it works.
What it does is take a plain ascii list of registered domain names and it
looks at various URL combinations to try to determine if there is a web
site for that domain. It also records the <TITLE> of all the pages it
finds.
If you are interested, please email me at annette@wwip.com with a quote
and how quickly you can complete the project. Thanks. :)
Annette Thompson
Internet Adoption Photolisting
http://adoption.com/precious/
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
------------------------------
Date: Tue, 25 Mar 1997 16:23:39 -0500
From: Brian Lorraine <lorraine@ait.nrl.navy.mil>
Subject: print "Content type: text/html\n\n";
Message-Id: <3338425B.41C6@ait.nrl.navy.mil>
This one always gets me. I'm writting a perl counter script. Here's the
actual code:
################################
#!/usr/bin/perl
$filename = "testcount";
print "Content type: text/html\n\n";
print <<HTMLHead;
<html>\n<head>\n
<title>Hit Counter</title>\n
</head>\n
<body>\n
HTMLHead
;
open(CFILE, $filename) || print "can't open file\n";
$numero = <CFILE>;
close(CFILE);
$numeronext = $numero + 1;
open(CFILE, ">$filename");
print (CFILE "$numeronext\n");
close(CFILE);
print "You are visitor number $numero\n";
print "</body></html>";
################################
I can get the rest of the program to work, but check it out at:
"http://www.ait.nrl.navy.mil/cgi-bin/lorraine/testcgi.pl"
It won't show the output as an html document. Is there an EXACT place I
have to shove that "print "Content type: text/html\n\n";" line and the
rest of it to get it to work??
--------------------------------------------------------------
Brian "the BrAiN" Lorraine lorraine@ait.nrl.navy.mil
"A truly wise man never plays leapfrog with a unicorn."
--------------------------------------------------------------
------------------------------
Date: Tue, 25 Mar 1997 13:49:42 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Regular Expresion question.
Message-Id: <m8a9h5.7p2.ln@localhost>
Aaron Bennett (abennett@stonehill.edu) wrote:
: Hello everyone:
: I'm a neophyte perl programmer trying to break the code on Regular
: Expressions. I'm working on a mail from a form script (I know there's
: about 1 million scripts like that out there I could copy, but then I'll
: never learn anything :)
: Part of what I want to do is parse the email address the user enters in
: a form and make sure it has one and only one "@" symbol and at least one
: ".".
: Here's a snippet: it doesn't compile correctly, and I know I just don't
: understand what I'm supposed to do.
: # is email address valid?
: print "Content type: text/html", "\n\n";
: if %mail_form{'email'} =~ /\@{1}.+/ {
^^^ ^^
need some parenthesis here!
need a '$' instead of a '%' too.
if ($mail_form{'email'} =~ /\@{1}.+/) { # untested!
That's the syntax error. Now for the regex:
Can you say in English what the pattern is doing? I'd say, for the
pattern above:
match one 'at' char (don't need the {1} either), followed by
one or more of *any character* (except newline).
Dot is special in regexs. You need to escape it to match a literal dot.
So it will match anything that has an '@' that is not at the end
of the string. Not what you wanted.
You need to allow some intervening chars between the '@' and '.' too:
---------------------------------
#! /usr/bin/perl -w
$_ = 'abennett@stonehill.edu';
print "'$_' matched\n" if /\@ # match one 'at' char followed by
.+ # one or more of any char (except newline)
\. # match one 'dot'
/x; # x lets me put the comments in here
---------------------------------
: print "<H1>Email is valid ", %mail_form{'email'}, "</H1>"; }
: Am I on the right track? I've read the camel book's pages on regular
^^^^^^^^^^^^^^^^^^^^^^^
: expresions and the regular expression section of the perl faq, but I
: can't seem to get this right.
Close, but no cigar. ;-)
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 25 Mar 1997 16:21:01 -0600
From: rmfowler@raptor.mtc.ti.com (Rex Fowler)
Subject: Re: regular expression for check lower case
Message-Id: <5h9j4d$ias@raptor.mtc.ti.com>
In article <5h9chb$j73@agate.berkeley.edu>,
Sherman Hsieh <shsieh@haas.berkeley.edu> wrote:
>I was wondering how to go about checking a variable for cases. For
>example, I want to do something if $variable is all lower case. I
>couldn't figure out what regular expression to use. Help.
I wanted something similar to convert all names entered
by someone to be converted to proper case. ie John Doe,
Ronald McDonald, ..
I use the folowing function, which hopefully someone will provide
suggestions for improvement. The assumption is that if there are 2
upper case characters, then the user probably typed it in correctly.
sub namecase {
my $n = shift;
$_=$n;
$cnt = tr/A-Z/a-z/;
# leave alone if there are exactly 2 uppercase characters per name
# this will leave LeAnne McDugal alone but correct uni-case and wildly
# mixed-case names. Won't work on 2 letter names.
if ($cnt ne 2) {
$n=ucfirst(lc($n));
}
$n;
}
> -Sherman
>--
--
Rex Fowler http://www.mtc.ti.com/~rmfowler
(972)997-2779 mailto:rmfowler@mtc.ti.com
Alpha Pager http://www.mtc.ti.com/cgi-bin/alpha_pager.cgi
TI MSG rfow
------------------------------
Date: Tue, 25 Mar 1997 23:05:40 GMT
From: shyde@poboxes.com (Simon Hyde (aka Jeckyll))
Subject: Re: regular expression for check lower case
Message-Id: <33384ca5.5970695@news.uni-stuttgart.de>
On 25 Mar 1997 20:28:27 GMT, shsieh@haas.berkeley.edu (Sherman Hsieh)
wrote:
>I was wondering how to go about checking a variable for cases. For
>example, I want to do something if $variable is all lower case. I
>couldn't figure out what regular expression to use. Help.
>
> -Sherman
>--
if ($variable =~ /^[a-z0-9_\W]/){
print "\$variable is all in lower case\n";
}
---
Yours Sincerely,
,
() o /| | |
/\ _ _ _ __ _ _ |___| __| _
/ \| / |/ |/ | / \_/ |/ | | |\| | / | |/
/(__/|_/ | | |_/\__/ | |_/ | |/ \_/|/\_/|_/|__/
/|
\|
(Simon Hyde)
------------------------------
Date: Tue, 25 Mar 1997 14:18:17 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: Mr Matty <hayes@coventry.ac.uk>
Subject: Re: text to HTML
Message-Id: <33384F29.5B45@egames.com>
[mail&post]
Mr Matty wrote:
> > Lewis Taylor wrote:
> > > I am currently writing a primative text to HTML routine. I want to
> > > replace all instances of double carriage return (\n\n) with a paragraph
> > > tag. But this :
> > > $big_string =~ s/\n\n/<P>/g;
> > > does'nt seem to do anything. I have also tried the two \n's in a
> > > variable to no avail. Other printable chars in place of \n\n work. Can
> > > someone please help?
> Have you tried using the chop function?
In general, it's a good idea to avoid chop() and use chomp()
these days. chop blindly removes the last character, chomp
removes the last character(s) if they match the current
input-record-seperator ($/). Can you see how the former
could be dangerous? What if there's no new-line on the
last line of a file?
> This will get rid of the
> CR LF's for you, then i just did somthing like this..
What if this text2html routine is running as a CGI script
on a unix server, but the submission of text came from a
Win/DOS browser? chomp thinks the end-of-line is "\n",
but the line terminators coming in from the DOS browser
are likely to be "\r\n". Doesn't work.
Also you failed to notice that the original poster was
talking about a single scalar containing multiple lines.
Neither chop or chomp is going to do anything useful with
this.
> chop ($lineoftext);
> $lineoftext =~ s/($lineoftext)/<p>$1</p>/;
This is a gratuituous use of regex substitution (and it
doesn't work if $lineoftext contains any of a number
of regex metacharacters).
What's wrong with:?
$lineoftext = "<p>$lineoftext</p>";
to accomplish the string modification you suggest?
I believe my original reply to Lewis Taylor's post covered
his problem much more correctly and completely, yet you
trimmed my answers/suggestions and propose an incorrect
and inadvisable alternative. Why?
HTH
--
Devin Ben-Hur <dbenhur@egames.com>
eGames.com, Inc. http://www.egames.com/
eMarketing, Inc. http://www.emarket.com/
"It's better to be lucky than good." -- Elizabeth Bourne
------------------------------
Date: 25 Mar 1997 14:11:09 -0800
From: silmaril@best.com (Josh Purinton)
Subject: Re: Unix 'Cat' equivelent
Message-Id: <5h9iht$d1n@shellx.best.com>
Quoth Mike Campbell:
>bill@sover.net.no.junkmail (Bill) writes:
>> Here's a quick and easy cat clone:
>> #!/usr/bin/perl -w
>> while (<>) {
>> print;
>> }
>
>perl -e 'print while (<>);'
Unfortunately, Mike, your version is not quite like 'cat' in that it fails
to print the last line if all it contains is '0'.
echo -n 0 | perl -e 'while(<>) { print }' # prints 0
echo -n 0 | perl -e 'print while(<>)' # prints nothing
There is magic in the first version which makes it "expand" to:
while(<>) { ... } => while(defined($_ = <>)) { ... }
The second version only expands to:
... while(<>) => ... while($_ = <>)
Running a modern beta of Perl with the -w switch will warn you about the
second version:
Value of <HANDLE> construct can be "0"; test with defined() at
-e line 1.
Personally, I think Perl should be changed so they're the same.
--Josh
--
Josh Purinton <joshp@silmaril.com>
The Road goes ever on and on, down from the door where it began.
-- Larry Wall in miniperlmain.c from the Perl 5 source (quoting J.R.R. Tolkien)
------------------------------
Date: Tue, 25 Mar 1997 16:48:59 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Mike Campbell <mcampbel@tvmaster.turner.com>
Subject: Re: Unix 'Cat' equivelent
Message-Id: <Pine.GSO.3.96.970325164753.27841H-100000@kelly.teleport.com>
On 25 Mar 1997, Mike Campbell wrote:
> bill@sover.net.no.junkmail (Bill) writes:
>
> > Here's a quick and easy cat clone:
> >
> > #!/usr/bin/perl -w
> >
> > while (<>) {
> > print;
> > }
>
> perl -e 'print while (<>);'
perl -pe0
:-)
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 25 Mar 97 22:15:25 GMT
From: "John Kaminski" <john@execnet.net>
Subject: Unixware 1.1.4 - Perl5.001m Protocol Not Supported
Message-Id: <01bc3969$b589fd80$084d4dc0@johndos.exec.com>
I am using at Script the uses the chat2.pl perl library with a Unixware
1.1.4 system. My compile of perl5.001m was sucessful. When I execute this
Perl fragment I get a protocol not supported.
The error is below:
open: Protocol not supported at ./chat-test line 25.
The Code Fragement is below:
#!/usr/bin/perl
#
#
#
#
require 'chat2.pl';
if ($#ARGV < 0) {
print "create-dir-remote : Too few arguments \n" ;
print "Correct Usage : " ;
print "create-dir-remote <username> [-t] \n" ;
print " -t Tracing On\n" ;
exit 1 ;
}
if ($#ARGV = 1) {
if ($ARGV[1] eq "-t" ) {
$trace = 1 ;
}
}
$username = $ARGV[0] ;
&chat'open_port("berlin.exec.com", 23) || die "open: $!"; <----- Line 25
!!!!!!
All help would be appriciated.
John Kaminski
Execunet
john@execnet.net
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 179
*************************************