[8687] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2304 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Apr 12 17:07:24 1998

Date: Sun, 12 Apr 98 14:00:32 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 12 Apr 1998     Volume: 8 Number: 2304

Today's topics:
    Re: Can't open a file for writing - again... <rootbeer@teleport.com>
        Compiling Perl with Mingwin32 on Windows NT <fenyvesi@cadvision.com>
        Computing a hash value in Perl <dick@cfcl.com>
    Re: Computing a hash value in Perl <rootbeer@teleport.com>
    Re: File::Find <sowmaster@juicepigs.com>
    Re: keys in hashs stvhoof@netvision.net.il
    Re: MacPerl Book Online in HTML (Rich Morin)
    Re: MacPerl Book Online in HTML lvirden@cas.org
    Re: MacPerl Book Online in HTML <gwynne@utkux.utk.edu>
    Re: MacPerl Book Online in HTML <gwynne@utkux.utk.edu>
    Re: MacPerl standalone apps (Rich Morin)
    Re: MLDBM - calling methods on retrieved object? otis@POPULUS.net
    Re: Numeric validation <ppp-support@canelle.telecom.uqam.ca>
        Perl-y Scripts [apologies to Don Ho] wlindley@compuserve.com
        Profiling resource use (Richard Karpinski)
    Re: Q: Getting the browsers local time? <Rosie@dozyrosy.demon.co.uk>
    Re: question about &parse_form_data... <Rosie@dozyrosy.demon.co.uk>
    Re: Relevance flames considered harmful (was Re: Q: For <merlyn@stonehenge.com>
    Re: Wanted: Amoo to stop my sysadmin from whining (brian d foy)
    Re: Wanted: Amoo to stop my sysadmin from whining (Matthew Cravit)
        wc -l in perl is?????? (Matt Taylor)
    Re: wc -l in perl is?????? (Matthew Cravit)
    Re: wc -l in perl is?????? <rootbeer@teleport.com>
    Re: wc -l in perl is?????? (Tom Mornini)
    Re: Weird problem with sending to a socket <rootbeer@teleport.com>
        Why am I getting an error with @_  ? <bth@acsu.buffalo.edu>
    Re: Why am I getting an error with @_  ? <rootbeer@teleport.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 12 Apr 1998 18:33:36 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: blr@mail.alarmix.net
Subject: Re: Can't open a file for writing - again...
Message-Id: <Pine.GSO.3.96.980412112300.25673E-100000@user2.teleport.com>

On Sat, 11 Apr 1998 blr@mail.alarmix.net wrote:

> sub createfile { #fname
> open(TCF,">$HOMEDIR/var/@_[0]") || return "Can't create @_[0]";

If you ask Perl to warn you about suspicious code, it'll remind you that
you should use $_[0] for the first element of the @_ array. Also, it's
generally useful to include the system's reason for the failure in the
error message, along with the full filename. 

    open TCF, ">$HOMEDIR/var/$_[0]"
	or return "Can't create file '$HOMEDIR/var/$_[0]': $!";

> The debugging is very difficulty, because this is part of a CGI script,
> but i've tried it with root suid,

Eeeek! There are better (much better) ways of debugging CGI scripts than
to make them set-id to root! (This is like looking down the barrel to see
why your rifle is jammed, and saying, "Well, I don't see any obstruction,
so I'll try pulling the trigger.... :-) If the CGI module is properly
installed, it has several ways to help you to test your module. Hope this
helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



------------------------------

Date: Sun, 12 Apr 1998 00:30:12 -0600
From: "Joe" <fenyvesi@cadvision.com>
Subject: Compiling Perl with Mingwin32 on Windows NT
Message-Id: <353108e0.0@news.cadvision.com>

Has anyone tried to compile Perl 5004_04 with the ECGS compiler using
Mingwin32?  Is it possible?

If no one has done this, does anyone know the best way to go about doing
this (i.e. start by editing the Cygwin makefile or the Borland makefile,
which
code files will likely need modification, etc...)?

Another option I've been thinking about is using Impdef and the Dlltool to
create an import library for the perl.dll so that I can create custom
interpreters
and extensions for Perl. Does anyone know if this is doable or if their are
any
issues to be aware of using this approach?

Thanks very much for your help,
Joe

Feel free to E-Mail me privately if you feel this doesn't belong on the
newsgroup.




------------------------------

Date: Sun, 12 Apr 1998 12:04:36 -0700
From: Richard Karpinski <dick@cfcl.com>
Subject: Computing a hash value in Perl
Message-Id: <3531103D.3A11@cfcl.com>

There's more than one way! 

My search is impeded by the fact that hash is an employed term (as
opposed to a keyword) in Perl.

I'd like a convenient method for getting a large number (6+ digits) from
a string by mangling the string value in a repeatable way.  Such a
number is usually called a hashed value or something similar.

Some methods use exclusive or to reduce the string to a shorter,
possibly fixed, length.  Since the commonly used ASCII characters occupy
only a fraction of the space of bit values, exclusive-or tends to
produce an uneven distribution of hash values.  Is there a known
solution to this problem?

My intention is to create a key lookup routine that takes only a single
I/O to get the key and associated data.  The trick in getting to one
read is to do the collisions in RAM.  It takes only a very small RAM
table, one byte per disk block for instance, to do that.

If such a lookup is already available, I'll happily take that instead.

Dick Karpinski (dick@cfcl.com)


------------------------------

Date: Sun, 12 Apr 1998 20:01:18 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Richard Karpinski <dick@cfcl.com>
Subject: Re: Computing a hash value in Perl
Message-Id: <Pine.GSO.3.96.980412125702.25673K-100000@user2.teleport.com>

On Sun, 12 Apr 1998, Richard Karpinski wrote:

> I'd like a convenient method for getting a large number (6+ digits) from
> a string by mangling the string value in a repeatable way.  Such a
> number is usually called a hashed value or something similar. 

I'd use the MD5 module. That makes a 128-bit hash from any data, and in
real-world use, hash collisions should never occur. If you need a shorter
string than 128 bits, you could (say) break it into four 32-bit chunks,
and xor them together. Of course, that makes collisions more likely. Hope
this helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



------------------------------

Date: Sun, 12 Apr 1998 14:37:58 -0400
From: Bob Trieger <sowmaster@juicepigs.com>
To: mikep <mikep@rt66.com>
Subject: Re: File::Find
Message-Id: <35310A06.1A97@juicepigs.com>

mikep wrote:
> 
> I'm looking for the File::Find module. Moreover, if there is a complete
> listing or source where I could download several File::* modules that'd
> be wonderful as well. MTIA


You can find these modules at your friendly neighborhood CPAN. But are
you sure that they didn't come with your distribution of perl? Check in
/usr/bin/perl/lib/File or C:/perl/lib/File.

-- 
Bob Trieger               |  Titanic: big boat, bigger
sowmaster@juicepigs.com   |           iceberg, big deal


------------------------------

Date: Sun, 12 Apr 1998 15:38:36 -0600
From: stvhoof@netvision.net.il
Subject: Re: keys in hashs
Message-Id: <6gr8od$7e9$1@nnrp1.dejanews.com>

In article <352DB35D.7243@outofservice.com>,
  jn1@outofservice.com wrote:
>
> $myhash{'key'} = 12;
> $myhash{key} = 12;
>
> first one is the better way to do it- the second one is a
> bareword, and if perl6 ever came along and claimed the literal
> token key as a symbol, your script would fail.
>

Sorry, I beg to differ...they are exactly the same.  In fact, I would say the
second one is preferred, because it's cleaner (less punctuation to clutter up
the screen!)

Here's my proof:

1    #!perl
2    @ARGV=qw/hi there/;
3
4    $foo{shift}='test';
5    print keys %foo, "\n";


If you were correct, line 4 would would evaluate "shift" as "hi" (since shift
with no arguments outside a subroutine shifts the leftmost argument from
@ARGV) and it would be the same as saying:

    $foo{'hi'} = 'test';

In that case, line 5 would cause the word "hi" to be printed (since the
"keys" function would return "hi" as the only key of the %foo hash).  However,
in fact, line 5 causes the word "shift" to be printed.  What this proves is
that if you have only a single bareword as the key of a hash, it is NOT
evaluated as a keyword, even if it happens to be one (like "shift").  In fact,
if you want to be technical about it, I believe that the term "bareword" does
not even apply to a single word used as a hash index, since this feature of
leaving off the quotes inside the braces is an explicit feature of the
language.

> difference between 'key' and "key": 'key' is literal, whereas "key" will
> expand nicely if you have $vars, etc. (single quoted prints the literal
> of everything except \'ed items, so to print a quote character you use
> '"')
>

Sorry, strike 2!  Single quoted does NOT interpret backslashes on anything
except the single quote itself.  For example:

   print "It costs \$10\n";

will print:

   It costs $10

whereas:

   print 'It costs \$10\n';

will print:

   It costs \$10\n


Oh well, at least you're still at bat...   :)

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


------------------------------

Date: Sun, 12 Apr 1998 12:08:19 -0700
From: rdm@cfcl.com (Rich Morin)
Subject: Re: MacPerl Book Online in HTML
Message-Id: <rdm-1204981208210001@140.174.42.30>

In article <8cd8ent5sp.fsf@gadget.cscaper.com>, Randal Schwartz
<merlyn@stonehenge.com> wrote:

> Writing a book is not a matter of voting.

As Jean-Louis Gassee' put it, "Input is not voting."  Nonetheless, we
did solicit input over the (several month) development effort, placing
draft chapters online so they could be examined.  The results have been
very worthwhile, yielding a greatly improved product.  We will continue
to solicit feedback, using it to improve (we hope :-) later printings,
future versions, and follow-on products.

> If Chris's book is intended for reference, rather than classroom,
> there's no compelling reason for exercises.

Although "MacPerl: Power and Ease" could be used in a classroom, it was
designed to be:

  *  a "first book on programmming"

  *  a "gentle introduction to (Mac-)Perl"

  *  a "cookbook" for using MacPerl

  *  a (terse) reference to (Mac-)Perl

  *  a guide to further study

Unlike many other programming books, "MacPerl: Power and Ease" does NOT
assume that the reader already knows how to program.  OTOH, because we
respect O'Reilly's Perl offerings very highly, we saw no reason to re-do
the Camel, Llama, etc.  Reflecting these goals and decisions, the book
has several major parts:

  *  Part I - Preparation

     This part starts with motivation for using MacPerl, wanders through
     a fair amount of programming philosophy and terminology, and ends
     with a chapter on installing and using the MacPerl application.

  *  Part II - Learning The Language

     This part presents MacPerl through a series of small examples.  It
     teaches a functional (but somewhat restrained) flavor of Perl; for
     instance, we use LOTS of parentheses (:-).  Where appropriate, we 
     concentrate on MacPerl differences (e.g., pathnames...).

  *  Part III - Advanced Topics

     This part is largely a "cookbook" for doing assorted things in Mac-
     Perl.  It does not try to cover any of its topics exhaustively, but
     should give the reader an understanding of the major issues, etc.

  *  Part IV - Reference

     This part starts out with a terse reference to Perl, with specific
     information on MacPerl differences.  It then covers MPW Perl and
     the MacPerl (and extension) "build process".

  *  Part V - Resources

     This part is primarily a book list, concentrating on books and
     other resources of interest to MacPerl programmers.

For more information, of course, see the book itself:

  http://www.ptf.com/macperl/ptf_book/HTML

-r

-- 
Canta Forda Computer Laboratory       | Prime Time Freeware - quality 
UNIX consulting, training, & writing  | freeware at affordable prices
+1 415-873-7841                       | +1 408-433-9662   -0727 (Fax)
Rich Morin, rdm@cfcl.com              | www.ptf.com, info@ptf.com


------------------------------

Date: 12 Apr 1998 19:57:45 GMT
From: lvirden@cas.org
Subject: Re: MacPerl Book Online in HTML
Message-Id: <6gr6bp$aou$1@srv38s4u.cas.org>


According to Bob Gwynne <gwynne@utkux.utk.edu>:
:I think this one needs a thread.

As an alternative to your proposal to vote or email the author on
things needed in his book, perhaps an alternative would be for you or
someone else to write a book of perl exercises that could be used in
conjunction to the original book!  That way, two authors get the benefits
instead of just one.  For those who learn best from exercises, why they
even have the option of just buying the book of exercises.

I do hope however that you consider either a third book containing the
answers, or put the answers in the back.  If the answers, written in
well researched perl, demonstrating proper error handling, etc. are presented,
they can teach a lot to the reader.

I myself enjoy reading books which present complete code examples, rather
than code fragments, particularly if the code does something useful for
me.

-- 
<URL:mailto:lvirden@cas.org> Quote: In heaven, there is no panic,
<*> O- <URL:http://www.teraform.com/%7Elvirden/> only planning.
Unless explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.


------------------------------

Date: Sun, 12 Apr 1998 16:00:30 -0400
From: "Bob Gwynne" <gwynne@utkux.utk.edu>
Subject: Re: MacPerl Book Online in HTML
Message-Id: <6gr6j0$kpo$1@gaia.ns.utk.edu>



>Bob> it might be improved?  I vote for inclusion of exercises.
>
>Writing a book is not a matter of voting.
>
I meant that rhetorically.

>
>In seriousness, there are many styles of learning.  I put exercises in
>"Learning Perl", because I was intending for it to be the complete
>textbook for the course I was designing in parallel with the book.
>But, had I not been doing a course, I might have left the exercises
>out.  (I waffled on that anyway... it really needs about twice the
>exercises it has.)




Randall:
    I don't recall asking for any kind of a vote on Chris's book.  I asked
for a discussion, which is what you are doing.  I also asked him if he had
done any research regarding how people learn.
Your Llama book benefits from exercises and, as you note, could use some
more--preferably graded exercises.  On the other hand, the Camel book does
not lend itself to exercises.  It is more of a reference book than a
tutorial type book.  Although your book is very good, especially for people
who have a c.s. degree, for people on my level (just a couple of basic c.s.
courses), Ormont's book is most useful.  It has lots of exercises and
explains things fairly clearly, albeit the first edition is loaded with
mistakes.  The best model for learning Perl are the Deitel & Deitel books on
C, C++, and Java.

  I don't understand how voting would be of any value.  Having an open
discussion of what type of Perl book  (in this case, MacPerl) is needed
might be useful.  In the end, however, I think that reading and/or working
through all of them is the most useful.  Nothing like a little redundancy to
get info stored in long term memory.

Bob Gwynne
Speech Dept.
University of Tennessee, Knoxville
http://funnelweb.utcc.utk.edu/~gwynne
423-974-6836
Fax: 423-974-4879
Home: 423-523-1097

In the country of the blind, the one-eyed man is king.
Having only one eye, I think that's kinda cool.








------------------------------

Date: Sun, 12 Apr 1998 16:14:54 -0400
From: "Bob Gwynne" <gwynne@utkux.utk.edu>
Subject: Re: MacPerl Book Online in HTML
Message-Id: <6gr7e0$l9h$1@gaia.ns.utk.edu>


Rich Morin wrote in message ...
>In article <8cd8ent5sp.fsf@gadget.cscaper.com>, Randal Schwartz
><merlyn@stonehenge.com> wrote:
>
>> Writing a book is not a matter of voting.
>
>As Jean-Louis Gassee' put it, "Input is not voting."  Nonetheless, we
>did solicit input over the (several month) development effort, placing
>draft chapters online so they could be examined.  The results have been
>very worthwhile, yielding a greatly improved product.  We will continue
>to solicit feedback, using it to improve (we hope :-) later printings,
>future versions, and follow-on products.
>
<snip>

Overall a good, defensible answer, especially the snipped part.

Bob Gwynne

| www.ptf.com, info@ptf.com




------------------------------

Date: Sun, 12 Apr 1998 11:24:52 -0700
From: rdm@cfcl.com (Rich Morin)
Subject: Re: MacPerl standalone apps
Message-Id: <rdm-1204981124520001@140.174.42.30>

In article <6glk34$o6k$1@nnrp1.dejanews.com>, tchurch@gmu.edu wrote:

> I have a script written in MacPerl.  If I save it as a standalone application,
> I have to copy all of the libraries that it uses to a the location where the
> application exists!  How can I get MacPerl to save all of the relevent
> functions inside the standalone app?

IMHO, the best place to start for general information on MacPerl is the
MacPerl Pages (http://www.ptf.com/macperl).  For specific questions such
as this, try the MacPerl email list (available through the MacPerl Pages).

-r

-- 
Canta Forda Computer Laboratory       | Prime Time Freeware - quality 
UNIX consulting, training, & writing  | freeware at affordable prices
+1 415-873-7841                       | +1 408-433-9662   -0727 (Fax)
Rich Morin, rdm@cfcl.com              | www.ptf.com, info@ptf.com


------------------------------

Date: Sun, 12 Apr 1998 14:16:22 -0600
From: otis@POPULUS.net
Subject: Re: MLDBM - calling methods on retrieved object?
Message-Id: <6gr3u5$1bl$1@nnrp1.dejanews.com>

Solution tot his problem:

don't forget to 'use Fcntl' if calling tie like this:

tie (%rep, MLDBM, $self->{file}, O_RDWR|O_CREAT, 0640);

Otis

In article <6gq1cs$kq0$1@nnrp1.dejanews.com>,
  otis@POPULUS.net wrote:
>
> Hello,
>
> I was trying to use MLDBM for persistent object storing.
> Since the modele has the same interface (hash-like) as other DBM
> implementations, adding stuff to MLDBM is not a problem.
>
> However, when I do something like this:
>
>     my ($docID, $webdoc) = each (%rep); # %rep is tied to MLDBM
>     $webdoc->method();
>
> I get error such as:
>
> Can't call method "method" without a package or object reference at Script
> line 123.
>
> This is most probably because $webdoc is not quite the OBJECT any more, so I
> cannot call methods on it.  But it should be an object, isn't that what
MLDBM
> is supposed to do? Preserve the object properly so that I can just get it
like
> a normal DBM value and call a method on it?
>
> Am I doing something wrong? Mistaken?
> Wait, is MLDBM for storing 'only' complex data structures, or objects?
> If the former then the error I'm getting makes sense, if the latter then my
> question still stands...
>
> Thanks,
>
> Otis
> P.S.
> I just discovered a module called ObjStore - how does it compare with MLDBM?
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/   Now offering spam-free web-based newsreading
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


------------------------------

Date: Sun, 12 Apr 1998 18:18:55 GMT
From: ppp-support <ppp-support@canelle.telecom.uqam.ca>
Subject: Re: Numeric validation
Message-Id: <3531047D.B569FA7C@canelle.telecom.uqam.ca>

Ok, it's so simple! The email suggestion work with my code, the results is what i
want, multiple testing shows everythings works fine, etc... and all your answers do
not.You simply want to prove that you know the Faq more than a beginner like me. If
you want to help, its fine... but if you just look for an argument, no time for
that thank you.

Rene
Abigail wrote:

> If you don't understand the faq, how would you know the emailed
> suggestion does what you are looking for?



------------------------------

Date: Sun, 12 Apr 1998 13:50:19 -0600
From: wlindley@compuserve.com
Subject: Perl-y Scripts [apologies to Don Ho]
Message-Id: <6gr2db$v3g$1@nnrp1.dejanews.com>

[with apologies to Don Ho]

"Perl-y Scripts"

Perl-y scripts
from command-line
shining in the Sun(tm)
covering the desktop...
When I run them,
'ps' tells me I love you,
more than all
the little Perl-y scripts.

\\/
William Lindley
Mesa, AZ

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


------------------------------

Date: Sun, 12 Apr 1998 13:39:29 -0700
From: dick@moreinfo.com (Richard Karpinski)
Subject: Profiling resource use
Message-Id: <dick-1204981339290001@rdm.dial.idiom.com>

So far, I'd like to be able to track down usage of three resources by my
Perl programs: CPU time, I/O requests, RAM consumption.  Are there known
ways either to profile Perl scripts or even to get access to the raw data?

I've written and used profilers in several languages, so perhaps I need to
write another.  At least the generation of human readable output should be
easy in Perl.

When I'm using Perl on a Unix system, I can inspect system data to see all
three categories of resources.  However, I'd rather have Perl ways to
discover my program's use of time, I/O, and RAM.  Where do I look to find
such things?
Dick Karpinski  dick@cfcl.com


------------------------------

Date: Sun, 12 Apr 1998 13:33:32 +0100
From: Rosemary I H Powell <Rosie@dozyrosy.demon.co.uk>
Subject: Re: Q: Getting the browsers local time?
Message-Id: <C4XXWEAcSLM1Ew$l@dozyrosy.demon.co.uk>

In article <Pine.SGI.3.96.980411235156.1222A-
100000@foxtrot.gl.umbc.edu>, Stephen Mubita <smubit1@gl.umbc.edu> writes
>On Sat, 11 Apr 1998, Drake Cleary wrote:
>
>=> Is there any way (ie: Env variable) to get the local time of the user
>=> of a perl script on the web?
>=> 
>The time ? Try localtime. I'm not sure if it helps.
>
But localtime will give the time on YOUR server, will it not, and not
that of the user who may be in a different time zone?
Rosemary
-------------------------------------------------------------------
| Rosemary I.H.Powell  EMail: Home: rosemary@dozyrosy.demon.co.uk |     
|                             Work: r.i.h.powell@rl.ac.uk         |
|                       http://www.netlink.co.uk/users/dozyrosy/  |
|                       http://www.dozyrosy.demon.co.uk/          | 
-------------------------------------------------------------------


------------------------------

Date: Sun, 12 Apr 1998 13:15:51 +0100
From: Rosemary I H Powell <Rosie@dozyrosy.demon.co.uk>
Subject: Re: question about &parse_form_data...
Message-Id: <QI9T6CA3BLM1Ewf$@dozyrosy.demon.co.uk>

In article <352CE3E1.C9A4802F@thetsn.com>, David Swain
<dswain@thetsn.com> writes
>Hello, I need a little help here.  I am trying out a perl program from
>page 180-CGI programming o'reilly book.  The code is as follows:
>
>#!/usr/bin/perl5
>
>&parse_form_data(*simple);
>8< snipped >8
>...The error I get when running it off the server is:
>Undefined subroutine &main::parse_form_data called at secure.cgi line 3
>
>so my question is...what is parse_form_data, isn't is included with
>Perl?  I have version 5.003, on red hat linux box.  This has been a big
>problem to me, and I can't figure out why it(perl) can't find the
>parse_form_data subroutine.  I'm sure it's probably something really
>simple, but I am blind to it.  Please help.


David, 

&parse_form_data is one of the subroutines written for the book 
(see page 78!) and isn't included in Perl proper. Examples from the book
are available to download from the O'Reilly web site if you don't want
to have to type them all in.  But since I have it already, here is the
stuff you need (either save this in a file called common.pl or follow
the commented instructions at the top!):

8< ------ cut and paste between the two dividing lines ----------->8   

#!/usr/local/bin/perl

##++
##  This "mini" library contains the parse_form_data and
##  return_error subroutines. 
##
##  The following applies _only_ if you picked up the Examples.tar
##  before June 20th:
##
##  Some of the examples described in the book (and in Examples.tar 
##  on the ORA FTP site), I stated that you needed to use these 
##  subroutines, but I didn't explicitly cover how to do this.
##
##  There are two ways to do so:
##
##     1. You can cut and paste these subroutines directly into
##        the program.
##
##     2. You can leave this file as is, and then insert the
##        following line at the top of your program:
##
##        require "common.pl";
##
##  Shishir Gundavaram
##  June 20, 1996
##--

sub parse_form_data
{
    local (*FORM_DATA) = @_;

    local ($request_method, $query_string, @key_value_pairs,
           $key_value, $key, $value);

    $request_method = $ENV{'REQUEST_METHOD'};

    if ($request_method eq "GET") {
        $query_string = $ENV{'QUERY_STRING'};
    } elsif ($request_method eq "POST") {
        read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
    } else {
        &return_error (500, "Server Error",
                       "Server uses unsupported method");
    }

    @key_value_pairs = split (/&/, $query_string);

    foreach $key_value (@key_value_pairs) {
        ($key, $value) = split (/=/, $key_value);
        $value =~ tr/+/ /;
        $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;

        if (defined($FORM_DATA{$key})) {
            $FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value);
        } else {
            $FORM_DATA{$key} = $value;
        }
    }
}

sub return_error
{
    local ($status, $keyword, $message) = @_;

    print "Content-type: text/html", "\n";
    print "Status: ", $status, " ", $keyword, "\n\n";

    print <<End_of_Error;

<title>CGI Program - Unexpected Error</title>
<h1>$keyword</h1>
<hr>$message</hr>
Please contact $webmaster for more information.

End_of_Error

    exit(1);
}

1;

8< ------ cut and paste between the two dividing lines ----------->8 

Rosemary 

-------------------------------------------------------------------
| Rosemary I.H.Powell  EMail: Home: rosemary@dozyrosy.demon.co.uk |     
|                             Work: r.i.h.powell@rl.ac.uk         |
|                       http://www.netlink.co.uk/users/dozyrosy/  |
|                       http://www.dozyrosy.demon.co.uk/          | 
-------------------------------------------------------------------


------------------------------

Date: Sun, 12 Apr 1998 19:10:37 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Relevance flames considered harmful (was Re: Q: Form CGI script...)
Message-Id: <8cn2dqsvp2.fsf@gadget.cscaper.com>

>>>>> "John" == John Callender <jbc@west.net> writes:

John> Oh, come off it. The mailer syntax is implicit in the snippet he posted.

No it isn't.  $mailprogram could be /bin/mail, Mail, /usr/lib/sendmail,
or something we haven't heard of.

John> I've noticed lately that this kind of knee-jerk relevance flame (even
John> when preceded by "Please") can really set my teeth on edge. The original
John> poster wanted to know how to modify a Perl script to put a particular
John> string in the "From: " header of an E-mail.

If it was /bin/mail, he couldn't have.  Hence, the information is relevant.

John> It's ironic that those who are especially rude to newcomers in this
John> group tend to justify their hostility by painting their victims as
John> intellectually lazy: "They don't bother to research the available
John> documentation before posting, so I'm justified in publicly humiliating
John> them."

But in this case, we truely *were* missing information.  I suggest you
check your facts before you flame a response again.

<sigh>

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 141 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


------------------------------

Date: Sun, 12 Apr 1998 14:36:31 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Wanted: Amoo to stop my sysadmin from whining
Message-Id: <comdog-ya02408000R1204981436310001@news.panix.com>
Keywords: from just another new york perl hacker

In article <3530F6D2.FEE9D649@doitnow.com>, "John C. Quillan" <quillan@doitnow.com> posted:

>Andrew F. Lee wrote:

>> We have Perl 5.002 (which has been around about 2 years) and very limited
>> set of modules.  I am groaning to my sysadmin to UPGRADE, but no one wants
>> to do anything unless the building is on fire.

>What I have been forced to do in the past when I couldn't get something like
>this done is,
>
>   A. Write some code in perl that breaks under 5.002 and create your own fire.
>   B. Install my own copy of perl for the task I am working on.

obviously you guys like the hard approach.  if you want something done,
you need to resort to bribery and gratuity.  taking the sysadmin out
for drinks and so on makes him more likely to respond to your requests. :)

also, make it seem that it is the sysadmin's idea to upgrade.  perhaps 
he should be concerned about the security problems with older versions
of Perl, or there is some nifty script you have that can make his life
a lot easier, but darn it! - it requires 5.004.

too bad they don't teach this sort of thing in school since they are such
effective methods.  doing things like installing your own version of Perl
is likely to pis the admin off and make him less likely to help you in
the future :(

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers <URL:http://www.pm.org>


------------------------------

Date: 12 Apr 1998 12:56:12 -0700
From: mcravit@best.com (Matthew Cravit)
Subject: Re: Wanted: Amoo to stop my sysadmin from whining
Message-Id: <6gr68s$1uo$1@shell3.ba.best.com>
Keywords: from just another new york perl hacker

In article <comdog-ya02408000R1204981436310001@news.panix.com>,
brian d foy <comdog@computerdog.com> wrote:

>effective methods.  doing things like installing your own version of Perl
>is likely to pis the admin off and make him less likely to help you in
>the future :(

Speaking as a sysadmin, I can definitely attest to that. I've had users try
end-runs around me before, and it's a huge problem. This is especially true
since when I tell a user "no, we can't do xxxx", there's generally a good
reason behind it. I'd rather that a user who has a legitimate need for
something ask me and let me work with him/her to solve it than try to make
an end-run around me.

ObPerl: I was trying to update the modules on one of my copies of perl
yesterday, using the "perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'"
example from the CPAN man page, and it got as far as updating the IO
module, and then broke due to the version of IO being newer than what
some of the other IO:: modules expected. Does anyone know how to work
around this, or, if it doesn't work, why it's given as an example in the
man page? 

/MC

-- 
Matthew Cravit, N9VWG               | Experience is what allows you to
E-mail: mcravit@best.com (home)     | recognize a mistake the second
        mcravit@net.com (work)      | time you make it.


------------------------------

Date: Sun, 12 Apr 1998 19:25:40 GMT
From: nospam@rnoc.com (Matt Taylor)
Subject: wc -l in perl is??????
Message-Id: <3533148a.95807148@news.realnews.net>

I need a function like the unix wc (aka wordcount function) that
allows me to print out how many lines there are in a file. Is there
something like this built into perl?  The idea is to randomly read a 
line from a file which is basicly a pointer to a url.  

email replys to mtaylor@rnoc.com


------------------------------

Date: 12 Apr 1998 13:12:40 -0700
From: mcravit@best.com (Matthew Cravit)
Subject: Re: wc -l in perl is??????
Message-Id: <6gr77o$75e$1@shell3.ba.best.com>

In article <3533148a.95807148@news.realnews.net>,
Matt Taylor <nospam@rnoc.com> wrote:
>I need a function like the unix wc (aka wordcount function) that
>allows me to print out how many lines there are in a file. Is there
>something like this built into perl?  The idea is to randomly read a 

There are a couple of ways you could go about this:

open (FILE, "whatever") or die "Couldn't open file: $!";
while (<FILE>) { $lines++; }
close FILE;

open (FILE, "whatever") or die "Couldn't open file: $!";
@data = <FILE>;
close FILE;
$lines = scalar @data;


The first of these seems (according to the Benchmark module) to be faster,
but if you're planning on using the data from the file, it might benefit
you to retain it in memory, in which case the secound would be better, as
you'd only have to read the file once.

>email replys to mtaylor@rnoc.com

Why? If this is important enough for you to ask it, it's obviously important
enough that you can spend the time checking the newsgroup for replies. Besides,
if replies were emailed to you, nobody else would see and learn from them.

/MC

-- 
Matthew Cravit, N9VWG               | Experience is what allows you to
E-mail: mcravit@best.com (home)     | recognize a mistake the second
        mcravit@net.com (work)      | time you make it.


------------------------------

Date: Sun, 12 Apr 1998 20:27:35 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Matt Taylor <nospam@rnoc.com>
Subject: Re: wc -l in perl is??????
Message-Id: <Pine.GSO.3.96.980412131915.25673L-100000@user2.teleport.com>

On Sun, 12 Apr 1998, Matt Taylor wrote:

> I need a function like the unix wc (aka wordcount function) that
> allows me to print out how many lines there are in a file. Is there
> something like this built into perl?  

Sure. Just read in the file and count the lines. :-)  (Depending upon the
file and your skills with perl, there is more than one way to do it.
tr/\n// comes to mind, as does $count = @lines.)

> The idea is to randomly read a line from a file which is basicly a
> pointer to a url. 

It's the same if every line is not "basicly a pointer to a url". :-) Maybe
you want something like this: 

    open FILE, $name or die "Can't read '$name': $!";
    while (<FILE>) {
	$line = $_ if rand($.) <= 1;
    }
    print "One randomly-selected line is $line";

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



------------------------------

Date: Sun, 12 Apr 1998 20:51:21 GMT
From: tmornini@netcom.com (Tom Mornini)
Subject: Re: wc -l in perl is??????
Message-Id: <tmorniniErBJ9M.9wJ@netcom.com>

Matt Taylor (nospam@rnoc.com) wrote:

: I need a function like the unix wc (aka wordcount function) that
: allows me to print out how many lines there are in a file. Is there
: something like this built into perl?  The idea is to randomly read a 
: line from a file which is basicly a pointer to a url.  

----------
#!/usr/bin/perl -w

# the most obvious way, to me

use strict;

my $line=0;

while (<>)
 {
  $line++;
 }

print "$line\n";
----------

or

----------
#!/usr/bin/perl -w

# almost certainly faster. Certainly uses more memory.

use strict;

my $line=my @file=<>;

print "$line\n";
----------

Interesting! The "obvious" way is much faster than the "almost
certainly faster" method. That'll teach me to make any assumptions!

Perhaps I shouldn't even assume that it uses more memory... :-)

Talk about a lose/lose situation!

Does anyone know why this might be?

sun630mp% perl -v

This is perl, version 5.004_04 built for sun4-solaris

sun630mp% ls -al bible11.txt
-rw-r--r--   1 tmornini info_own  4833023 Apr 12 13:15 bible11.txt

sun630mp% timex ./wc.pl bible11.txt
114104

real        2.67
user        2.44
sys         0.18

sun630mp% timex ./wc2.pl bible11.txt
114104

real        6.18
user        3.60
sys         2.26

I ran each test 3 times, to make certain that file caching was equal
for both. These results are run number 3 for each. This is on an
ancient Sun 630MP which has a fair amount of RAM at 512 meg and fast
external RAID disks (though caching should negate any advantages there)
but two slow 50Mhz SuperSparc processors. Load average of around .5

This system runs a relatively busy web site averaging about 260k hits/day.

I reran the tests on a 100Mhz FreeBSD system with 0.00 load average

> ./wc.pl blah.txt; ./wc.pl blah.txt;time  ./wc.pl blah.txt
114104
114104
114104
2.127u 0.125s 0:02.29 97.8%     542+332k 0+0io 0pf+0w

> ./wc2.pl blah.txt ; ./wc2.pl blah.txt ; time ./wc2.pl blah.txt
114104
114104
114104
4.361u 1.094s 0:05.61 97.1%     545+12296k 0+0io 0pf+0w

-- Tom Mornini
-- InfoMania


------------------------------

Date: Sun, 12 Apr 1998 18:58:20 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Paul Wilson <prw@vanitydomain.net>
Subject: Re: Weird problem with sending to a socket
Message-Id: <Pine.GSO.3.96.980412115215.25673H-100000@user2.teleport.com>

On Sun, 12 Apr 1998, Paul Wilson wrote:

> Here's part of a script than when it's printed, just prints a number
> instead of the actual string:
> 
> ($uhost,$foo,$foo,@stuff) = split(/\s+/,$line);
> send SOCK, "lwallops :Possible Spam: $uhost: @stuff\n", 0;
> 
> This results in a printout of "Possible Spam: 266421: whatever..."
> 
> $uhost would typically contain an IRC hostmask such as
> someone@nas-nh12-32.ix.netcom.com. If I split $uhost on @, then put it
> back in in the send SOCK, it works fine:
> 
> ($uhost,$foo,$foo,@stuff) = split(/\s+/,$line);
> ($uid,$host) = split(/\@/,$uhost);
> send SOCK, "lwallops :Possible Spam: $uid\@$host: @stuff\n", 0;

If everything is truly as you say, then there is a significant bug in your
perl binary. 

Here's a test that you could try. At that point in your code, use this:

    my $test_line = 'foo@bar undef undef rest of the test data';
    ($uhost, undef, undef, @stuff) = split(/\s+/,$line);
    send SOCK, "lwallops :testing: $uhost: @stuff\n", 0;

If that gives a number instead of 'foo@bar', then there's a bug in your
perl binary. Hope this helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



------------------------------

Date: Sun, 12 Apr 1998 14:48:45 -0400
From: Bryan T Hoch <bth@acsu.buffalo.edu>
Subject: Why am I getting an error with @_  ?
Message-Id: <Pine.GSO.3.96.980412144335.3041A-100000@xena.acsu.buffalo.edu>

	Hi all.
	This may seem like a really dumb question, but to me it's not (I'm
still just learning Perl).
	When I run a sub routine I get an error involving @_ . The error I
get says this:

syntax error at database.pl line 78, near "sub drop_table_1"
Can't use global @_ in "my" at database.pl line 80.


	The piece of code I am using looks a little like this...

sub drop_table_1{
    my($table_tablename) = @_ ; #parameter being passed in.
	....
	A LOT MORE CODING HERE
	....
} #end subroutine drop_table_1

Anyone have any ideas what I am doing wrong by trying to pass in this
parameter?
	Thanks.
						Bryan H

PS - I used the @_ in another subroutine before this, but it didn't give
me any problems then and I didn't think that it should now....



------------------------------

Date: Sun, 12 Apr 1998 19:55:57 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Bryan T Hoch <bth@acsu.buffalo.edu>
Subject: Re: Why am I getting an error with @_  ?
Message-Id: <Pine.GSO.3.96.980412124604.25673J-100000@user2.teleport.com>

On Sun, 12 Apr 1998, Bryan T Hoch wrote:

> 	When I run a sub routine I get an error involving @_ . The error I
> get says this:
> 
> syntax error at database.pl line 78, near "sub drop_table_1"
> Can't use global @_ in "my" at database.pl line 80.
> 
> 
> 	The piece of code I am using looks a little like this...

"a little like this"? It helps to show the actual code that causes the
error! But that error generally means that somehow you have @_ being
declared as a my() variable - not allowed. The code you posted didn't
_look_ as if that was happening, though. Maybe you've got a syntax error
that has confused the parser. 

If you still can't find the problem, cut your code down to (say) a dozen
or so lines that you can post here. Good luck!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



------------------------------

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 2304
**************************************

home help back first fref pref prev next nref lref last post