[11610] in Perl-Users-Digest
Perl-Users Digest, Issue: 5210 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 23 21:07:37 1999
Date: Tue, 23 Mar 99 18:00:20 -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, 23 Mar 1999 Volume: 8 Number: 5210
Today's topics:
Re: << string definer <uri@home.sysarch.com>
Re: C function in Perl <cassell@mail.cor.epa.gov>
Re: Environment strings <bret@bordwell.com>
Re: Extreme Newbie here needs help <candree@one.net.au>
Re: Extreme Newbie here needs help <kglazier@cyberus.ca>
Re: Extreme Newbie here needs help <cassell@mail.cor.epa.gov>
flock() && win95 #HELP! <lopex@Ibdhi.com>
Re: FUNCTION accessing args in a sub <rick@rixsoft.com.fixme>
Re: help with loops <lopex@Ibdhi.com>
Keeping place in a file <gala@sonic.net>
Limiting database results cgi@higherlove.com
Make Perl handle white space in a path mchoueir@geocan.nrcan.gc.ca
Re: My file keeps getting clobbered! sstarre@my-dejanews.com
Re: Need username in Perl script (John Dilley)
newbe: to find the highest entry in group jas888@my-dejanews.com
Re: newbie question <jglascoe@giss.nasa.gov>
open3 and flushing STDOUT (Bill Moseley)
Re: Perl Books (was Re: << string definer) <mkersey@metricom.com>
Re: Perl Books (was Re: << string definer) <upsetter@ziplink.net>
Perl Detecting Browser Version <davewal@corp.sgi.com>
Re: Perl Detecting Browser Version (brian d foy)
Re: Perl Detecting Browser Version (Craig Vitter)
Perl error(?) when <textarea> contains hard return (Laar)
Please help!!! <rizwan.q@usa.net>
Reading a non Archived ( Live ) file with PERL kamez@my-dejanews.com
Sending files with CGI <aidan.curran@agilesoft.com>
Shipping Cost Script <erik@rockymountainwebtech.com>
sorting multi-dim array (Timothy Larson)
why my sub returns nothing? dizhao@my-dejanews.com
Re: why my sub returns nothing? <jglascoe@giss.nasa.gov>
Re: why my sub returns nothing? <jglascoe@giss.nasa.gov>
Re: Win32:EventLog and problems capturing data (Craig Vitter)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Mar 1999 18:41:18 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: << string definer
Message-Id: <x7aex3bwpt.fsf@home.sysarch.com>
>>>>> "S" == Scratchie <upsetter@ziplink.net> writes:
S> It might be worth pointing out in the docs (I just discovered this fairly
S> recently) that you can do multi-line strings using normal quote operators
S> as well. I often use
S> print qq|
S> Some multi-line text
S> Some more of the same
S> |;
S> to accomplish nearly the same thing, and I just discovered (when I
S> tried it) that you can even do the same thing with regular old
S> double-quotation marks.
there are several signifigant differences between here docs and long
quoted strings. first, your quoted string starts with newline, while
here docs never do (unless you put leading blank lines in the here
body). on the back end of the string, here docs always end with a
newline while you can close your regular quote before a trailing
newline.
here docs never need to escape a quote char while any form of quoted
string would have to escape them (except for nested paired quotes like
(){}[]<>).
you can do syntactic stuff with here docs that you can't do with quoted
strings:
sub_foo( <<FOO, <<BAR ) ;
foo text
FOO
bar text
BAR
if those texts were very long, using quoted strings would be very ugly
and the closing ); could be very far from the opening foo(.
visually it seems to me that here docs are much better as finding the
close token is easier (if the token is well selected) than finding the
matching close quote char.
as always TIMTOWTDI and i use both plain and q versions and here docs
according to the needs of the string.
i use here docs with die a lot:
open( FOO, 'foo' ) || die << DIE ;
can't open foo since it doesn't exist, you maroon!!!!
DIE
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Tue, 23 Mar 1999 16:59:23 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: C function in Perl
Message-Id: <36F838EB.FE049536@mail.cor.epa.gov>
yue xu wrote:
> Does anyone know how to integrate a C function into
> Perl? i.e. if I have a function doing shell sort, how can
> I make it available in PERL (not mean make it a executable
> and do system)?
The Perl docs talk about this. A lot. Use 'perldoc' or 'man'
to peruse perlembed and perlguts. If that's not enough:
perldoc -q embed
Found in C:\PERL509\lib/pod/perlfaq3.pod
I've read perlembed, perlguts, etc., but I can't embed perl in
my C program, what am I doing wrong?
Download the ExtUtils::Embed kit from CPAN and run `make
test'. If the tests pass, read the pods again and again
and again. If they fail, see the perlbug manpage and
send a bugreport with the output of `make test
TEST_VERBOSE=1' along with `perl -V'.
But do you really need to do this? Perl has a very fast sort
routine as a builtin.
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 23 Mar 1999 19:22:44 -0500
From: Bret Bordwell <bret@bordwell.com>
Subject: Re: Environment strings
Message-Id: <36F83054.4B0B@bordwell.com>
> Possibly have a different IP?
> When you "immediately" go back to the site, to continue playing ( I ain't
> gonna touch it) the game, are you still using the same "hit" on the site that
> you originally used? If so, then the ENV variables are going to be the same.
> You are basically in the same client/server session.
"hit" on the site? what is this?
The "play" would be pressing the "submit" button from within my mail
reader. Wait a few for the return mail to be ready, collect it, then
press "submit" with the new piece of mail.
Thanks for your reply.
Bret
------------------------------
Date: Wed, 24 Mar 1999 09:58:14 +1000
From: "chris" <candree@one.net.au>
Subject: Re: Extreme Newbie here needs help
Message-Id: <36f82bd2.0@pink.one.net.au>
Isn't this book only for the Windows NT and Unix platforms?
Robert Gwynne wrote in message <7d6u70$im0$1@gaia.ns.utk.edu>...
>
>Jon Orwant's Perl 5 Interactive Course is a thorough and well designed book
>for learning Perl from the ground up. You don't have to know how to program
>to get started.
>
>---------------------------
>Bob Gwynne
>gwynne@utkux.utk.edu
>Speech Comm
>University of Tennessee, Knoxville
>
>JAPN (Just Another Perl Newbie)
>
>
>
------------------------------
Date: Tue, 23 Mar 1999 19:01:53 -0500
From: "Michael Villeneuve" <kglazier@cyberus.ca>
Subject: Re: Extreme Newbie here needs help
Message-Id: <7d9bha$adj$1@remarQ.com>
Great choice! Learning Perl is an excellent start. If you're interested in
CGI programming with Perl, you may want to get a copy of O'reilly's book of
the same name. I know it helped me a lot when I started doing the same.
Also, don't be afraid of the examples. Try them out to see what the relusts
are.
Good Luck!
Mike
------------------------------
Date: Tue, 23 Mar 1999 17:06:21 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Extreme Newbie here needs help
Message-Id: <36F83A8D.BD643E1A@mail.cor.epa.gov>
chris wrote:
> Isn't this book only for the Windows NT and Unix platforms?
> Robert Gwynne wrote in message <7d6u70$im0$1@gaia.ns.utk.edu>...
> >
> >Jon Orwant's Perl 5 Interactive Course is a thorough and well designed book
> >for learning Perl from the ground up. You don't have to know how to program
> >to get started.
If it covers Perl for WinNT, it covers Perl for Win32. There are
a few things that NT has which 95 and 98 don't, like 'hostname'.
But ActivePerl runs on all these platforms.
David
--
David L. Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Tue, 23 Mar 1999 17:23:51 -0600
From: John Cosby <lopex@Ibdhi.com>
Subject: flock() && win95 #HELP!
Message-Id: <36F82286.EB2A24A8@Ibdhi.com>
I'm new to perl and may be mussing it up, but am I correct in assuming
that flock() is not available to win95 coders? I tried it in my code and
tried the ex. in PerlFAQ5 and the error was fatal. I'm thinking about
renaming the file between * and *.lock to show a locked state. Has
anyone tried this, and if so, how well did it work for you?
I've got about a month's exp. w/perl and am using build 509. ANY
comments would be appreciated.
------------------------------
Date: Tue, 23 Mar 1999 20:07:50 -0500
From: Rick Osborne <rick@rixsoft.com.fixme>
Subject: Re: FUNCTION accessing args in a sub
Message-Id: <36F83AE6.514AB3B3@rixsoft.com.fixme>
Quoth Zenno:
> @Klant_EMaildata = &get_Filtered_List(@Klant_EMaildata,@fields);
> sub get_Filtered_List {
> my(@org_List) = $_[0];
> my(@filterElts) = $_[1];
> my(@result_List) = ();
Think about what you are doing here. Remember "@_"? You get @_ passed to
you in the sub. And what is @_ made of? All the arguments to the
function, right? And since everything comes in as one array (@_), how are
you supposed to tell where @Klant_EMaildata begins and @fields ends?
Instead, look into references (perldoc perlref). They let you do
something like this:
@Klant_EMaildata = &get_Filtered_List(\@Klant_EMaildata,\@fields);
sub get_Filtered_List {
my($r_org_List, $r_filterElts) = @_;
my @org_List = @$r_org_List;
my @filterElts = @$r_filterElts;
# do whatever
}
Of course, you'll want to do error checking (make sure the passed
arguments are references [use ref()], etc). But that should point you in
the right direction.
--
Rick Osborne <rick at rixsoft dot com> -- Founder, Orlando Perl Mongers
(What is or who are the Orlando Perl Mongers? Ask me.)
------------------------------
Date: Tue, 23 Mar 1999 17:36:19 -0600
From: John Cosby <lopex@Ibdhi.com>
Subject: Re: help with loops
Message-Id: <36F82572.67675C2F@Ibdhi.com>
Chris Denman wrote:
> I have a program which gets into a loop. There are many parts to this
> program, so it is hard to find out which sub has the loop.
>
> Is there any way of finding out where a program has got into a loop. I have
> the perl DK and the debugger, but the debugger gets into a loop also. I
> have not found a way to stop the debugger and get the line number that it is
> at.
>
> I could manually work through the code, but I have a deadline to stick to.
>
> Cheers for any help,
>
> Chris D
I had a simular prob this morning, I forgot to reset an open end counter to zero
at the beginning of the loop, so when I recalled the loop it started at the old
value and went infinate. Start checking where you have arrays or hashes that you
are parsing.
I recall something about setting breakpoints and watches in the debugger, if not
use print lines to serve the same purpose.
-me
------------------------------
Date: Tue, 23 Mar 1999 16:50:45 -0800
From: "Gala Grant" <gala@sonic.net>
Subject: Keeping place in a file
Message-Id: <7d9cpf$adj$1@ultra.sonic.net>
I am writing a program that searchs a file for links, and then checks them.
My problem is that if the link is within the same page (an anchor tag) I
need to have a subroutine check if the anchor is on the page. When I do
this, I have to read the file, further down, losing my place. My question
is, is there a way to return to the same place within the file after I test
for the anchor tag? I know about using seek to rewind the file to where I
need to go, but how would I know exactly where I had been. Actually, I
would need to be right after the last thing I checked.
Thank You,
Gala Grant
------------------------------
Date: Wed, 24 Mar 1999 00:34:37 GMT
From: cgi@higherlove.com
Subject: Limiting database results
Message-Id: <36f83311.22676076@news.phnx.uswest.net>
I have a database script running so that it cycles through arrays to
find matches.
To keep things simple, lets say I use something like the following
(I'm not going to list complete code since the program as it stands
works for what it needs to do at present):
foreach $lines(@database_array) {
@edit_array = split(/\|/,$lines);
if ($edit_array[5] eq $INPUT{'name'}){
push (@matches, $lines);
}
...
then I jump back to whatever routine called my search to count
matches
...
$count = @matches; # count matches found
if ($count == 0){
&nomatches; #If no matches found, print web page
}
else {
&printrecords; #Print found records
}
What I'm wondering is how I can get the system to display the first 10
results and allow users to cycle through their search results in
groups of 10. I've studied various programs that do this, but I just
can't seem to figure this out
I really appreciate any help on this!
Lisa
------------------------------
Date: Tue, 23 Mar 1999 23:23:11 GMT
From: mchoueir@geocan.nrcan.gc.ca
Subject: Make Perl handle white space in a path
Message-Id: <7d97oj$p4c$1@nnrp1.dejanews.com>
Hi all,
Please check this little script below and if you would tell me how I
can let it work !
# Purpose
# Lists all the files in a specified directory.
my $directory = "c:\\Program Files\\Windows NT\\Pinball\\*";
while (glob("$directory"))
{
print "File: $_\n";
}
As you can see, if the variable directory is given a path with no
spaces, it works just fine but if like this example, it wouldn't !
I used GetOpt::Long but didn't work either !
Any suggestion would be appreciated !
Thank you very much.
Michael.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 24 Mar 1999 00:47:16 GMT
From: sstarre@my-dejanews.com
Subject: Re: My file keeps getting clobbered!
Message-Id: <7d9cmh$t93$1@nnrp1.dejanews.com>
Mike:
Thank-You for your reply. I re-read the FAQ- there really isn't much there on
flock but from what i can can tell I'm using it correctly. I also read posts
to this newsgroup, particularly those from Tom Christensen, but I can't see
any problems.
As you request, here are the pertinent code sections that illustrate my open
and locking procedures. I dont get any errors.
The mysterious part to me is that in the examples I've found, it uses a
mysterious call to flock like:
$r=flock(F, LOCK_EX);
instead of
$r=flock(F, $LOCK_EX);
I get an error when I try the first method.
#***************************************************************************
use Fcntl;
use strict;
my $M;
my $TMP;
my ($LOCK_SH,$LOCK_EX,$LOCK_NB,$LOCK_UN) = (1,2,4,8);
sub lockF #arg is share yes or no
{my $r;
if ($_[0])
{$r=flock(F, $LOCK_SH) ||
pmessage::SayError("file", "lock- could not shlock F, try again");}
else
{$r=flock(F, $LOCK_EX) ||
pmessage::SayError("file", "lock- could not exlock F, try again");
}
return $r;
}
sub unlockF
{flock F, $LOCK_UN;
}
sub mcop # copy m file to a tmp file for listing
{sysopen(F,$M,O_RDONLY) || pmessage::SayError("file", "old member file $!");
lockF(1);
sysopen(X,$TMP,O_RDONLY) || pmessage::SayError("file", "old member file $!");
lockX(0);
copy($MEM,$TMP);
unlockF();
unlockX();
}
sub madd # the text line is the arg
{ my $MAXLEN = 255;
my $result=0;
my $line=$_[0];
$_=$line;
if (!/\n$/) {$line.="\n";}
if (length $_[0] < $MAXLEN)
{sysopen(F,$M,O_WRONLY|O_APPEND) || pmessage::SayError("cant open m file
$!");
lockF(0);
print F $line;
unlockF();
$result = 1;
}
else {pmessage::SayError("Line", "too long for DB entry");}
close F;
return $result;
}
In article <7d47c7$jtn$1@pegasus.csx.cam.ac.uk>,
mjtg@cus.cam.ac.uk (M.J.T. Guy) wrote:
> In article <36F55CC9.CD67CA85@bol.net>, sara starre <webqueen@bol.net> wrote:
> >I have a textfile that numerous users update through perl print
> >statements and copy() commands. The file is about 10k lines.
> >
> >About 3 times a day it turns 100 to 2000 lines into one giant line,
> >which in vi looks like screenfuls of NULL chars I guess. The lines
> >appear to be garbled too- if I insert CR every 80 chars there seems to
> >be some lines missing and others shortened.
> >
> >I tried adding flock (exclusive) during updates- no improvement. I tried
> >replacing system calls (to cp) with copy(f1,f2). I tried checking the
> >length of each line that I print to the file. None of these remedies
> >made any difference.
>
> You may *think* you are using flock(), but it's notoriously easy to
> do it incorrectly. If you haven't already done so, check out the
> entries relating to locking in perlfaq5.
>
> And if you think you are doing it correctly, try posting the relevant
> code to see if we agree with you. :-)
>
> Mike Guy
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 23 Mar 1999 22:55:52 GMT
From: john@deletethisdilley.com (John Dilley)
Subject: Re: Need username in Perl script
Message-Id: <36f81b55.20750659@news.jps.net>
Thanks for the response. With some 35,000 + groups showing up in Agent could
you give provide some advice on an appropriate group for authentication
schemes?
Thanks
JohnD
abigail@fnx.com (Abigail) wrote:
>John Dilley (john@deletethisdilley.com) wrote on MMXXX September MCMXCIII
>in <URL:news:36f830d7.90195566@news.jps.net>:
> <snip>
>
>No. All you get is what the browser sends to the server, and that the
>server puts in the environment. Browsers stopped sending user names
>about 5 years ago, after many reports of abuse.
>
>If you want to set up some kind of authentication scheme, go ask in an
>appropriate group.
>
>
>Abigail
------------------------------
Date: Wed, 24 Mar 1999 00:52:10 GMT
From: jas888@my-dejanews.com
Subject: newbe: to find the highest entry in group
Message-Id: <7d9cvm$tl3$1@nnrp1.dejanews.com>
hello folks,
I'd to find out the way to look for the highest entry in a group with a text
entries looks like this :
things1,2
things1,3
things1,4 *
data5,2
data5,3 *
For example, "things1,4" is capture for "things1" group and
"data5,3" is capture for "data5" group
I'd appreciate any pointers.
Thank you very much.
Regards
Jason
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 23 Mar 1999 17:51:48 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Chen Li <erpeng@cs.auc.dk>
Subject: Re: newbie question
Message-Id: <36F81B04.6A49279E@giss.nasa.gov>
[courtesy copy sent to cited author]
Chen Li wrote:
>
> How to append a line to a file? Thanks a lot.
a bit more straightforward:
open FH, ">> $file_name" or die "can't append to file: $!";
print FH $your_line_here, "\n";
close FH;
or this:
do {
local *STDOUT;
open STDOUT, ">> $file_name" and print $your_line_here, "\n";
} or die "file append failed: $!";
I like that: "do ... or die ...". Also, both the "open()" and
"print()" are checked; extra error checking!
And the icing on the cake: I'm using STDOUT so I needn't write my
file handle symbol more than twice...
All around good code, neh? ;^)
Jay Glascoe
--
Poit!
------------------------------
Date: Tue, 23 Mar 1999 16:34:31 -0800
From: moseley@best.com (Bill Moseley)
Subject: open3 and flushing STDOUT
Message-Id: <MPG.1161d2ee6f6520b49896e5@206.184.139.132>
I've got a CGI script that during processing sends email via sendmail.
Like a good programmer, I was checking the open, the print, and the close
for errors. Every once in a while I was receiving an error on my
close(). I posted a question about that and Zenin
(zenin@archive.rhps.org) recommended using his Sendmail.pm, saying that
you need to not only check return codes, but also look at sendmail's
STDOUT and STDERR for output indicating an error.
I didn't use his Sendmail.pm, but I did use his open3 call to catch
STDERR and STDOUT. Here's what I'm doing:
use FileHandle;
use IPC::Open3;
my $to_sendmail = new FileHandle;
my $stdout_sendmail = new FileHandle;
my $stderr_sendmail = new FileHandle;
open3( $to_sendmail, $stdout_sendmail, $stderr_sendmail, $params )
or return "Failed open of sendmail:$sendmail:$!";
Here's the problem. When I do the open3() call my current STDOUT seems
to get flushed - AGAIN. So my web page get's the text that's already
been print()ed displayed once again. Everything up to that point is
displayed twice. (And this happens if running the script from the
command line, too.)
In my CGI script, I've got STDERR to a log file -- and I don't get
duplicate entries in my log file. So it seems that it is only happening
to STDOUT.
Clearly, I don't understand how to properly use open3, or really anything
that's going on here. Can someone help?
Thanks,
--
Bill Moseley mailto:moseley@best.com
------------------------------
Date: Tue, 23 Mar 1999 17:10:34 -0600
From: Michael Kersey <mkersey@metricom.com>
Subject: Re: Perl Books (was Re: << string definer)
Message-Id: <36F81F6A.4C042765@metricom.com>
I read the first edition of the book "Teach Yourself CGI Programming with
Perl 5 in 7 Days" by Eric Hermann. I was initially confused by the
presentation order, but it was clear that the author _did_ understand the
subject matter. However, the presentation order was so distracting that I
spent considerable effort attempting to understand it.
My conclusion was that the presentation style was in the form of a flattened
tree: That is, Mr. Hermann would move from a very high-level discussion down
to the limiting details within a few pages and back up again; that the entire
volume was much akin to a depth-first traversal of a tree structure. Once I
had a better understanding of the book's organization, it was much easier to
read. There is a wealth of detail in the text. However I think it is a rather
unusual organization for an introduction to any language. I have heard that
the second edition has been modified significantly.
Scratchie wrote:
> Timothy Larson <larsot2@krypton.mankato.msus.edu> wrote:
> : In _Teach Yourself Perl in 21 Days_ I found a neat use of << to define
> : multiline strings.
>
> This is the second time I've seen this book mentioned today. Is it getting
> remaindered somewhere?
>
> Here is a critical review of the book in question:
> http://xenu.phys.uit.no/~tom/TYP21D.html
>
> While I can't vouch for the accuracy of this review (I haven't read this
> book), if it's half as bad as "Teach Yourself CGI Programming with Perl 5
> in 7 Days" (same publisher) it should be avoided at all (or any) cost. The
> latter book seemed to have been written by someone who didn't really
> understand the subject matter, and who was just cutting and pasting
> information (and code examples) that he found on the web. Aspiring perl
> programmers would be much better off sticking to the O'Reilly & Associates
> offerings.
>
> --Art
> --
> --------------------------------------------------------------------------
> National Ska & Reggae Calendar
> http://www.agitators.com/calendar/
> --------------------------------------------------------------------------
------------------------------
Date: Wed, 24 Mar 1999 00:59:12 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: Perl Books (was Re: << string definer)
Message-Id: <ANWJ2.584$Yk5.100719@news.shore.net>
Michael Kersey <mkersey@metricom.com> wrote:
: I read the first edition of the book "Teach Yourself CGI Programming with
: Perl 5 in 7 Days" by Eric Hermann. I was initially confused by the
: presentation order, but it was clear that the author _did_ understand the
: subject matter. However, the presentation order was so distracting that I
: spent considerable effort attempting to understand it.
I was disturbed by the fact that some code examples had typos and some
were missing important lines. I must have spent a half hour trying to find
where "$mailprog" was defined in one script before I realized that he
hadn't included that line in the code listing. Since the script in
question was a freely-available form-to-email script, that didn't say much
about Mr. Herrmann's understanding of the material.
When the book initially went from "Perl" to "Perl 5", the publishers
added a bunch
of
command-line perl tutorials at the end of each chapter, but none of the
primary content of the book (the CGI material) even mentioned a single
function or ability of Perl 5 (as opposed to Perl 4). The only mention of
CGI.pm was a chapter that simply quoted Lincoln' Stein's documentation in
toto.
The Perl tutorials themselves were completely unrelated to any of the Perl
in the rest of the book, so you might be seeing perl constructs in the CGI
section of, say, Chapter 3 when that piece of perl didn't appear in the
perl tutorial section until Chapter 9.
The book has a lot of examples on how to accomplish specific things, (many
of which are unrelated to Perl or CGI, such as image maps and SSI) but the
book struck me as pretty light on providing the sort of foundation of
knowledge you need to build upon if you're going to create new apps
unrelated to the examples in the book. The book seemed to be aimed towards
consultants who need to cut and paste something together to give someone a
guest book and an email response form.
--Art
--
--------------------------------------------------------------------------
National Ska & Reggae Calendar
http://www.agitators.com/calendar/
--------------------------------------------------------------------------
------------------------------
Date: Tue, 23 Mar 1999 16:25:30 -0800
From: David Walford <davewal@corp.sgi.com>
Subject: Perl Detecting Browser Version
Message-Id: <36F830F9.84143BFA@corp.sgi.com>
Is there a way that PERL could detect the version of a users browser in
a cgi script?
If so, how?
Or is this only capable with javascript?
Thanks
David
--
--------------------------------------------------------------
David M. Walford | email: davewal@corp.sgi.com
RealityCenter Tech. Engr. | m/s: 06U-122
Silicon Graphics, Inc. | voice: 650-933-6451
Corporate Briefing Center | fax: 650-932-6451
------------------------------
Date: Tue, 23 Mar 1999 20:26:14 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Perl Detecting Browser Version
Message-Id: <comdog-ya02408000R2303992026140001@news.panix.com>
In article <36F830F9.84143BFA@corp.sgi.com>, David Walford <davewal@corp.sgi.com> posted:
> Is there a way that PERL could detect the version of a users browser in
> a cgi script?
sure. use the same method that you would use in any other language.
see the documents referenced in the CGI Meta FAQ for more details.
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 24 Mar 1999 02:37:52 GMT
From: craig@vitter.com (Craig Vitter)
Subject: Re: Perl Detecting Browser Version
Message-Id: <7d9fiu$m07@dfw-ixnews11.ix.netcom.com>
In article <comdog-ya02408000R2303992026140001@news.panix.com>, comdog@computerdog.com (brian d foy) wrote:
>In article <36F830F9.84143BFA@corp.sgi.com>, David Walford
> <davewal@corp.sgi.com> posted:
>
>> Is there a way that PERL could detect the version of a users browser in
>> a cgi script?
>
>sure. use the same method that you would use in any other language.
>see the documents referenced in the CGI Meta FAQ for more details.
>
As an addition to this I have been working on a module to do some of this
dirty work. The module is functional, yet not complete and probably not very
pretty at that. But here is the code if you are interested. (If you want the
module e-mailed to you just write me at craig@vitter.com and I will send it as
an attachment).
#!/usr/bin/perl
#####################################################
# Package Getclientinfo
# By Craig Vitter - craig@vitter.com/www.vitter.com
#
# Getclientinfo subroutines:
# browser -
# Attempts to deconstruct the http_user_agent
# to return the browser type in plain english
# (you figure out what to do with the info...)
#
# Usage:
# use lib "path\to\package";
# use Getclientinfo;
#####################################################
# This code can be distributed, changed, hacked,
# or ridiculed openly as long as you don't charge for
# it (unless of course you want to send me a cut...)
# Please leave these headers intact so any and all
# abuse can be directed to craig@vitter.com.
# Questions, comments, bugs, or cool fixes? Drop me
# a line. Peace.
#####################################################
package Getclientinfo;
require Exporter;
#####################################################
# Subroutine browser
#####################################################
sub browser {
$web_browser = $ENV{'HTTP_USER_AGENT'};
# Sample results:
# Mozilla/4.5 [en] (Win95; I)
Netscape 4.5
# Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)
Explorer 4.01
# Mozilla/4.0 (compatible; MSIE 4.01; AOL 4.0; Windows 95)
Explorer 4.01 AOL
# Try to deconstruct $web_browser to get readable values
# to create @browser = ($company, $browser, $version, $platform,
$language);
# Check first for Netscape and Netscape wanna'be's like IE and Opera
if($web_browser =~ /Mozilla/i) {
# We will deal with netscape browsers first by eliminating Internet
# Explorer and Opera with an if not MSIE or Opera statment
if($web_browser !~ /MSIE/i and $web_browser !~ /opera/i) {
$company = "Netscape";
$browser = "Navigator";
# Figure out the major and minor version numbers and if it
# is navigator gold or not
if($web_browser =~ /(\d\.\d\d)/) { # Version x.xx
$version = $1;
}
elsif($web_browser =~ /(\d\.\d)/) { # Version x.x
$version =$1;
}
else {
$version = "Unknown";
}
if($web_browser =~ /gold/i) { # Is it
navigator gold?
$version = "$version Gold";
}
}
# ElsIf we are dealing with Internet Explorer
elsif($web_browser =~ m/MSIE/i) {
$company = "Microsoft";
$browser = "Internet Explorer";
#Determine what version of Explorer (including AOL and WebTV)
if($web_browser =~ /(MSIE\s\d\.\d\d)/) { #
Version x.xx
$version = $1;
if($version =~ /(\d\.\d\d)/) {
$version = $1;
}
}
elsif($web_browser =~ /(MSIE\s\d\.\d)/) { #
Version x.x
$version =$1;
if($version =~ /(\d\.\d)/) {
$version = $1;
}
}
if($web_browser =~ /aol/i) { #
Check for AOL users
$version = "$version for AOL";
}
if($web_browser =~ /webtv\/\d\.\d/i) { #
Check for WebTV users
$version = "$version / $1";
}
}
# Check for Opera
elsif($web_browser =~ m/opera/i) {
$company = "Opera Software";
$browser = "Opera";
# Get version info
if($web_browser =~ /(\d\.\d\d)/) { # Version x.xx
$version = $1;
}
elsif($web_browser =~ /(\d\.\d)/) { # Version x.x
$version =$1;
}
}
# Otherwise it is some other imposter
else {
$browser = "Unknown Netscape Compatible Browser";
# Get version info
if($web_browser =~ /(\d\.\d\d)/) { # Version x.xx
$version = $1;
}
elsif($web_browser =~ /(\d\.\d)/) { # Version x.x
$version =$1;
}
}
}
# Start checking for other browsers here since we know its not
# Netscape or a Netscape imposter
# Figure out the visitors computing platform
if($web_browser =~ /win95/i or $web_browser =~ /Windows 95/i) {
$platform = "Windows 95";
}
elsif($web_browser =~ /win98/i or $web_browser =~ /Windows
98/i) {
$platform = "Windows 98";
}
elsif($web_browser =~ /winnt/i or $web_browser =~ /Windows
NT/i) {
$platform = "Windows NT";
}
elsif($web_browser =~ /win32/i or $web_browser =~ /Windows
32bit/i) {
$platform = "Windows 3.XX 32-Bit";
}
elsif($web_browser =~ /win16/i or $web_browser =~ /win31/i or
$web_browser =~ /Windows 3.1/i) {
$platform = "Windows 3.XX";
}
elsif($web_browser =~ /macppc/i or $web_browser =~ /mac_ppc/i)
{
$platform = "Apple Power Mac";
}
elsif($web_browser =~ /ppc/i and $web_browser !~ /macppc/i) {
$platform = "IBM Power PC";
}
elsif($web_browser =~ /68k/i or $web_browser =~ /mac/i or
$web_browser =~ /68000/i or $web_browser =~ /mac_68k/i) {
$platform = "Apple Macintosh";
}
elsif($web_browser =~ /linux/i) {
$platform = "Linux";
}
elsif($web_browser =~ /solaris/i or $web_browser =~ /sunos/i)
{
$platform = "Sun Solaris";
}
elsif($web_browser =~ /hp/i or $web_browser =~ /hpux/i or
$web_browser =~ /hp-ux/i) {
$platform = "HP Unix";
}
elsif($web_browser =~ /amiga/i) {
$platform = "Amiga";
}
elsif($web_browser =~ /irix/i) {
$platform = "SGI";
}
elsif($web_browser =~ /dec/i or $web_browser =~ /ultrix/i or
$web_browser =~ /alphastation/i or $web_browser =~ /alphaserver/i) {
$platform = "DEC Alpha";
}
elsif($web_browser =~ /vms/i or $web_browser =~ /openvms/i or
$web_browser =~ /vax/i) {
$platform = "DEC Open VMS";
}
elsif($web_browser =~ /sco/i) {
$platform = "SCO Unix";
}
elsif($web_browser =~ /bsd/i) {
$platform = "BSD Unix";
}
elsif($web_browser =~ /os\/2/i or $web_browser =~ /os2/i) {
$platform = "IBM OS/2";
}
elsif($web_browser =~ /unix/i) {
$platform = "Unknown Unix Platform";
}
else {
$platform = "Unknown Platform";
}
# Figure out the visitors language
if($web_browser =~ /(\[en\])/i) {
$language = "English";
}
elsif($web_browser =~ /(\[no\])/i) {
$language = "Norwegian";
}
elsif($web_browser =~ /(\[it\])/i) {
$language = "Italian";
}
elsif($web_browser =~ /(\[ru\])/i) {
$language = "Rusian";
}
elsif($web_browser =~ /(\[de\])/i) {
$language = "German";
}
else {
$language = "";
}
@browser = ($company, $browser, $version, $platform, $language);
}
------------------------------
Date: Tue, 23 Mar 1999 23:43:40 GMT
From: laar@ix.netcom.com (Laar)
Subject: Perl error(?) when <textarea> contains hard return
Message-Id: <36f826a1.79546264@nntp.ix.netcom.com>
Hello all,
I've searched the FAQs unsuccessfully for a solution to this problem.
I wrote a script ("extract.pl") to place data from a form in %array.
Everything works perfectly *except* when a user enters a hard return
in a <textarea> input field, in which case I receive an error. If the
user enters everything on one line without hitting [enter], then the
script return the information as expected.
A sample form with the Perl code is at:
207.221.60.17/testform.html
Any help appreciated.
------------------------------
Date: Tue, 23 Mar 1999 15:59:20 -0700
From: "Rizwan Qazi" <rizwan.q@usa.net>
Subject: Please help!!!
Message-Id: <36f828fc$0$222@nntp1.ba.best.com>
Hello everybody,
I have made an application which allows uploading of a 'gif'
file from a perl script. When somebody clicks on browse to locate the file
to be uploaded the pop-up window has the following default entries (on a
Windows 95 system):
Look in : Windows
File name: (Blank)
File of type: HTML (*.htm,*.html)
How can I make the 'File of type' entry to be 'gif' ?
Please reply. Thanks to everybody for reading this message.
Rizwan Qazi
------------------------------
Date: Wed, 24 Mar 1999 00:26:40 GMT
From: kamez@my-dejanews.com
Subject: Reading a non Archived ( Live ) file with PERL
Message-Id: <7d9bfm$sac$1@nnrp1.dejanews.com>
Hello there,
could you help me for the following stuff : i wanna read a live file with
variable size ( on records ) , each time i find out a certain string in a
record newly created on my file , i wanna launch a specific process...
Could anyone among you get a clue about how we do handle that with the neatest
way
?
Thanks for your help folks.
Khalid.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 23 Mar 1999 15:48:15 -0800
From: "Aidan Curran" <aidan.curran@agilesoft.com>
Subject: Sending files with CGI
Message-Id: <7d992j$9e4$1@ffx2nh3.news.uu.net>
I am using a Perl/CGI script to send files to the client. I am printing the
HTTP header (just content-type) and then printing the contents of the file.
I have had to resort to using a system call to the DOS command 'TYPE' to
print the file contents as the Perl I/O commands corrupted the data - they
worked fine with text files but not with binary files (even using
'binmode'). Using the DOS command 'TYPE' works in almost all cases except I
have found a few GIF files that it breaks down for (most GIFs come out
fine). In these few cases what I get in my IE browser is a string of text
(mostly question marks) instead of the image. My Netscape browser shows a
broken image graphic.
How is the file data getting corrupted and is there any way to prevent this?
System Details:
OS: NT 4
Web Server: IIS 4
Perl: Perl 5.003 for Win32
------------------------------
Date: Tue, 23 Mar 1999 17:23:43 -0800
From: Erik Boles <erik@rockymountainwebtech.com>
Subject: Shipping Cost Script
Message-Id: <36F83E9F.B1851B29@rockymountainwebtech.com>
Sorry if this is off topic for this NG but could not find any more
appropriate.
I am looking for a script to run in a CGI environment that will take
information from a shopping cart program, and, based on on product
weight and the destination zip code, will formulate UPS ground shipping
costs. Can anyone point me in the right direction if there is even such
a thing?
Any help is greatly appreciated.
erik
------------------------------
Date: 24 Mar 1999 01:42:39 GMT
From: larsot2@krypton.mankato.msus.edu (Timothy Larson)
Subject: sorting multi-dim array
Message-Id: <7d9fuf$gp2$1@nitrogen.mankato.msus.edu>
Greetings!
I'm having big problems doing this. The first subscript is not a problem,
I'm using integers and I control how the indexes are accessed, so I can
put them in order. It's the second subscript that is the pain. Those
keys are rather arbitrary. As I go through the outer index, how can I
sort the inner one and get the values in that order?
Tim
------------------------------
Date: Tue, 23 Mar 1999 22:53:19 GMT
From: dizhao@my-dejanews.com
Subject: why my sub returns nothing?
Message-Id: <7d960p$ni8$1@nnrp1.dejanews.com>
Look at the code below, in the sub t, I predefined $index, but when returned
from the foreach loop, it returns nothing(it supposed to return 0). I think
it has something to do with foreach scenario. Can someone give me a
explanation? I am using perl5.005_2. Thanks. #!/usr/bin/perl $i = t(0); print
"i is: $i\n"; $i = t(1); print "i is: $i\n"; sub t { my ($ii) = @_; my
$index = 1; if ($ii) { foreach $index (0..10) { return $index; } }
$index = 2; return $index; }
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 23 Mar 1999 18:33:48 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: jglascoe@giss.nasa.gov
Subject: Re: why my sub returns nothing?
Message-Id: <36F824DC.CD802C08@giss.nasa.gov>
Jay Glascoe wrote:
>
> sub main {
> my $i = t();
oops. should read "mysub()" (as it does in my code).
The bug is still there.
> __END__
> Narf!
> Jay Glascoe
------------------------------
Date: Tue, 23 Mar 1999 18:30:16 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: dizhao@my-dejanews.com
Subject: Re: why my sub returns nothing?
Message-Id: <36F82408.FBCB8749@giss.nasa.gov>
[courtesy copy to cited author]
dizhao@my-dejanews.com wrote:
>
> Look at the code below, in the sub t, I predefined $index, but when returned
> from the foreach loop, it returns nothing(it supposed to return 0).
Wow. I think it's a bug. It works fine on perl5.003, perl5.004,
and even perl5.0055. But perl5.00502 has this to say:
$ perl500502 -w baf.pl
Use of uninitialized value at baf.pl line 7.
$i is: ''
where
$ cat baf.pl
use strict;
main();
sub main {
my $i = t();
print "\$i is: '$i'\n"; # <-- line 7
}
sub mysub {
my $index;
foreach $index (0..10) { return $index }
}
__END__
Narf!
Jay Glascoe
------------------------------
Date: Wed, 24 Mar 1999 02:20:23 GMT
From: craig@vitter.com (Craig Vitter)
Subject: Re: Win32:EventLog and problems capturing data
Message-Id: <7d9ei5$3gv@sjx-ixn8.ix.netcom.com>
In article <36F7CA91.CD87C16F@mail.cor.epa.gov>, "David L. Cassell" <cassell@mail.cor.epa.gov> wrote:
>Okay, let's take a look under the hood...
>First, let me ask: did you call Perl withthe -w flag, and did you say
> use strict
>at the top of your program? I always do, because I make lots of embarrassing
>typos and stuff...
Actually I did try -w but no errors developed there. I snipped a lot of the
code for brevity and because of it being unrelated to the problem.
>> $SecPerDay = 7 * 24 * 60 * 60;
>> $Now = time();
>> $OneDayAgo = $Now - $SecPerDay;
>
>I would have done this part with localtime() and Time::Local, but each to
>his own. There has been a thread about this recently.
Normally I use a module that I created to handle all sorts of time formats
painlessly but here I followed the code that Dave Roth used in explaining the
concept where we are just capturing the seconds.
>> [a little snip to cut to the chase]
>> if( $Hash{EventType} == EVENTLOG_ERROR_TYPE ||
>> $Hash{EventType} == EVENTLOG_WARNING_TYPE)
>
>Hmmm. If your error type and warning type are character strings, you
>want to make the comparison using 'eq'. Otherwise, you're forcing
>a numerical comparison against a non-number. No match. Hence no
>output.
You know what, I did not try this and I will try it now. I did follow Dave
Roth's example here as well and this was how he did the comparisons however
there was another typo in his code that I caught so this == could have been
typos as well.
Thanks for your input.
BTW, anyone else interested in reading event logs through Perl may want to
look into the Dumpel.exe utility that MS puts out. You can dump the Event Log
contents into a tab deliminated file. I rewrote my orginal script to do this
and then parse that dump file to get the errors messages etc.
Craig
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5210
**************************************