[17503] in Perl-Users-Digest
Perl-Users Digest, Issue: 4923 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 19 14:05:42 2000
Date: Sun, 19 Nov 2000 11:05:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <974660712-v9-i4923@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 19 Nov 2000 Volume: 9 Number: 4923
Today's topics:
誠意邀請對Perl有興趣的朋友 <vicschanweb@hotmail.com>
Re: About to slit my own throat (Craig Berry)
Can't run perl !! <Please_reply@this.group>
Re: Can't run perl !! <lauren_smith13@hotmail.com>
Re: Can't run perl !! <bart.lateur@skynet.be>
Re: Can't run perl !! dtbaker_dejanews@my-deja.com
Re: Can't run perl !! dtbaker_dejanews@my-deja.com
Re: Capital Letters Won't Sort - HeLp! <iltzu@sci.invalid>
Re: Free Online Sample Certification Questions <iltzu@sci.invalid>
Re: grep and reg exp question <iltzu@sci.invalid>
Re: hello i am new <jaford@watford53.freeserve.co.uk>
How to I replace charachter? <edmond.nolan@debitel.net>
Re: How to I replace charachter? <edmond.nolan@debitel.net>
Re: Naming variables with variables, how? <iltzu@sci.invalid>
Need easy Perl help, will trade for online presentation (Al Rosetti)
Re: Need easy Perl help, will trade for online presenta <lauren_smith13@hotmail.com>
Re: Net::SMTP error message; dtbaker_dejanews@my-deja.com
New to Perl. Question <ayambema@adelphia.net>
Re: New to Perl. Question (Garry Williams)
Re: New to Perl. Question (Tad McClellan)
Re: New to Perl. Question <bart.lateur@skynet.be>
Re: New to Perl. Question <lauren_smith13@hotmail.com>
Re: New to Perl. Question (Garry Williams)
Re: New to Perl. Question <lauren_smith13@hotmail.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 20 Nov 2000 01:04:51 +0800
From: "vic" <vicschanweb@hotmail.com>
Subject: 誠意邀請對Perl有興趣的朋友
Message-Id: <8v91tv$8502@rain.i-cable.com>
誠意邀請對Perl有興趣的朋友
http://easy4u.virtualave.net/
本站開設Perl論壇,
誠意邀請對Perl有興趣的朋友
或有問題的朋友到本站發表問題,
本站Perl論壇採用最方便快捷機制系統:
1>當有回覆時第一時間把回應送到您的email中
2>如果你嫌Check email 煩的話,可以引用ICQ回覆的
最新係統!
而且收集很多有關Perl/CGI的文章,絕對是學Perl或增強
Perl資訊的一流網站!
http://easy4u.virtualave.net/
有使每位對Perl/CGI得到完滿的答覆是本站的目標!
------------------------------
Date: Sun, 19 Nov 2000 18:10:56 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: About to slit my own throat
Message-Id: <t1g5tg3aot6pbb@corp.supernews.com>
Anthony (apsaffer@hotmail.com) wrote:
: No, it is NOT a spam generator. It is an anonymous email program made
: for a legitimate organization that will not use it for spam.
I can't think of any legitimate use for automated anonymous email. If
your recipients want it, then don't send it anonymously. If your
recipients don't want it, it's spam.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "Here's to the struggles of the silent war,
| here's to the closing of the age." -The Call
------------------------------
Date: Sun, 19 Nov 2000 15:43:01 GMT
From: "Jason" <Please_reply@this.group>
Subject: Can't run perl !!
Message-Id: <9ySR5.16539$DG3.333928@news2.giganews.com>
Hi all,
Why can't I run perl??? If I change the .pl to .cgi work fine but if I leave
it .pl it show all the text !!! My perl extention is fine, example:
#!/usr/bin/perl
It worked on other website but not my server ???
Please help !!!
Thanks !!!!!!!!
J
------------------------------
Date: Sun, 19 Nov 2000 17:00:43 GMT
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Can't run perl !!
Message-Id: <_GTR5.2914$ba3.656718@dfiatx1-snr1.gtei.net>
"Jason" <Please_reply@this.group> wrote in message
news:9ySR5.16539$DG3.333928@news2.giganews.com...
> Hi all,
>
> Why can't I run perl??? If I change the .pl to .cgi work fine but if I
leave
> it .pl it show all the text !!! My perl extention is fine, example:
> #!/usr/bin/perl
> It worked on other website but not my server ???
>
I'll bet your server documentation includes instructions on how to set
up Perl on your server!!! This is most definitely a server problem!!!
Lauren
------------------------------
Date: Sun, 19 Nov 2000 17:04:29 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Can't run perl !!
Message-Id: <mp1g1tcq4hpb1uvma4e1duubolrcm6rj9d@4ax.com>
Jason wrote:
>Why can't I run perl??? If I change the .pl to .cgi work fine but if I leave
>it .pl it show all the text !!! My perl extention is fine, example:
>#!/usr/bin/perl
>It worked on other website but not my server ???
I think it's the server configuration. If the server doesn't know that
the .pl extension belongs to a script, then it'll simply treat it as a
data file. What is strange, is that with the script set to execution
file mode, and .pl not recognized as script, then I get a server error.
If the server is Apache, and your server configuration allows it, then
you can override the default behaviour in a .htaccess file:
<files "*.pl">
SetHandler cgi-script
</files>
--
Bart.
------------------------------
Date: Sun, 19 Nov 2000 17:03:34 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: Can't run perl !!
Message-Id: <8v9153$j6t$1@nnrp1.deja.com>
In article <9ySR5.16539$DG3.333928@news2.giganews.com>,
"Jason" <Please_reply@this.group> wrote:
> Hi all,
>
> Why can't I run perl??? If I change the .pl to .cgi work fine but if I
leave
> it .pl it show all the text !!! My perl extention is fine, example:
> #!/usr/bin/perl
> It worked on other website but not my server ???
>
------------
it is a configuration issue with your webserver. it needs to be set up
to know that *.pl scripts need to open with perl. you also need to be
sure that you have chmod your scripts to BE executable.
you probably need to ask your sys admin about changing the server
config, or change your script names to *.cgi
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 19 Nov 2000 18:42:59 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: Can't run perl !!
Message-Id: <8v96vi$nhd$1@nnrp1.deja.com>
In article <9ySR5.16539$DG3.333928@news2.giganews.com>,
"Jason" <Please_reply@this.group> wrote:
> Hi all,
>
> Why can't I run perl??? If I change the .pl to .cgi work fine but if I
leave
> it .pl it show all the text !!! My perl extention is fine, example:
> #!/usr/bin/perl
> It worked on other website but not my server ???
-------------------
by "my server" I'm guessing you are attempting to run on a localhost at
home? If you are wanting to run on a win32 machine, you might want to
try using the freebie webserver from www.xitami.com as a localhost. It
is super easy to set up and runs perl cgi with no additional setup. If
you are trying to use Apache or IIS, you'll have to dig into the config
docs.
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 19 Nov 2000 18:42:18 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Capital Letters Won't Sort - HeLp!
Message-Id: <974658028.16807@itz.pp.sci.fi>
In article <3A145BCB.157E7D9A@home.com>, Michael Carman wrote:
>
>@sorted = sort {lc($a) cmp lc($b)} @list;
>
>That's fine if @list is small, but wasteful if its large because it has
>to recompute the lowercase value each time. For larger arrays, try a
>map-sort-map approach (a.k.a. "Schwartzian Transform"):
The Guttman-Rosler transform is probably even more efficient:
@sorted = map /\0X(.*)/s, sort map lc($_)."\0X".$_, @list;
In case it's not obvious, the code first prepends to each element a
lowercased version of it and "\0X", then sorts _those_ strings and
finally extracts the original strings. The reason for picking that
particular separator is that "\0" sorts before any other character,
while "X" is uppercase and therefore cannot possibly occur in the
lowercased part of the temporary strings.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: 19 Nov 2000 14:56:48 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Free Online Sample Certification Questions
Message-Id: <974644437.557@itz.pp.sci.fi>
In article <8uur44012sc@news1.newsguy.com>, Jeff Yoak wrote:
>In article <8uo399$7fa$1@nnrp1.deja.com>, cd_root@my-deja.com wrote:
>
>> Perl questions are located at:
>> http://www.networkessentials.com/certified/perl
>
>This seemed pretty lame to me. Probably a third of the questions I got
>related to pack templates, which I happen to use infrequently. What
>would this imply about my level of certification in Perl? Also, there
>are questions where none of the options are correct. You should have
It's not just the questions, the web interface is also broken.
It says "Nota Bene: There may be more than one right answer. Check all
that apply." right underneath submit button, but I don't think their
software can in fact even handle that. I did 30 of them just to make
sure, and every time the software claimed there to be only one right
answer, whether or not that was true in reality.
The way they've abused HTML radio inputs also means the only way to
_un_check an answer is by using the reset button. Then there were
these two pages:
[perlfunc]The grep function is not limited to regular expressions.
(_) a. TRUE
(_) b. FALSE
(_) c. (DO NOT USE THS ANSWER)
(_) d. (DO NOT USE THS ANSWER)
(_) e. (DO NOT USE THS ANSWER)
[perlop]What is the result of the following operation?
5
(_) 3
(_) a. 1
(_) b. 3
(_) c. 5
(_) d. 7
Anyone want to bet on whether these people use pipe delimited files?
(In case you're wondering, the JavaScript popup claims the answer to
the second question to be "e".)
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: 19 Nov 2000 14:13:44 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: grep and reg exp question
Message-Id: <974643083.22382@itz.pp.sci.fi>
In article <k8a5kmva.fsf@macforce.sumus.dk>, Jakob Schmidt wrote:
>
>make that $last =~ /^$lastname$/i and it oughtta work.
Is $lastname _supposed_ to be a regexp? If not,
lc($last) eq lc($lastname)
will not only be faster but will work correctly too.
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: Sun, 19 Nov 2000 14:29:09 +0000
From: Jim Ford <jaford@watford53.freeserve.co.uk>
Subject: Re: hello i am new
Message-Id: <3A17E3B4.33C88A31@watford53.freeserve.co.uk>
Gwyn Judd wrote:
> >HELLO I AM NEW TO THIS GROUP. CANB SOMEONE TELL ME WHAT IT IS ABOUT, I =
> >HEARD ABOUT IT IN ALT.POKEMON
>
> alt.stupidity is that way ------------->
Or this way <------------- (TIMTOWTDI !)
Regards: Jim Ford
------------------------------
Date: Sun, 19 Nov 2000 16:35:49 +0100
From: Edmond Nolan <edmond.nolan@debitel.net>
Subject: How to I replace charachter?
Message-Id: <3A17F355.2A10A43@debitel.net>
This is a multi-part message in MIME format.
--------------24D02350571F027BECAACEFC
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
how I do I replace all spaces in a string with underscores?
my $test = "a b c";
so that $test ends up having "a_b_c"
Thanks
Ed
--------------24D02350571F027BECAACEFC
Content-Type: text/x-vcard; charset=us-ascii;
name="edmond.nolan.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Edmond Nolan
Content-Disposition: attachment;
filename="edmond.nolan.vcf"
begin:vcard
n:Nolan;Eddie
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:edmond.nolan@debitel.net
fn:Edmond Nolan
end:vcard
--------------24D02350571F027BECAACEFC--
------------------------------
Date: Sun, 19 Nov 2000 17:45:31 +0100
From: Edmond Nolan <edmond.nolan@debitel.net>
Subject: Re: How to I replace charachter?
Message-Id: <3A1803AB.8ED62C78@debitel.net>
This is a multi-part message in MIME format.
--------------2D480604A6B701CFA8D13622
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
OK, found it ...
my $space = " ";
my $underscore = "_";
$test =~ s/$space/$underscore/;
Edmond Nolan wrote:
> Hi,
>
> how I do I replace all spaces in a string with underscores?
>
> my $test = "a b c";
>
> so that $test ends up having "a_b_c"
>
> Thanks
>
> Ed
--------------2D480604A6B701CFA8D13622
Content-Type: text/x-vcard; charset=us-ascii;
name="edmond.nolan.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Edmond Nolan
Content-Disposition: attachment;
filename="edmond.nolan.vcf"
begin:vcard
n:Nolan;Eddie
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:edmond.nolan@debitel.net
fn:Edmond Nolan
end:vcard
--------------2D480604A6B701CFA8D13622--
------------------------------
Date: 19 Nov 2000 15:03:23 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Naming variables with variables, how?
Message-Id: <974645992.11290@itz.pp.sci.fi>
In article <itpolxxq.fsf@macforce.sumus.dk>, Jakob Schmidt wrote:
>
>But don\t do it. There\s practically always a better way. Probably you
>simply want an array or a hash. Believe me.
I've no idea what made your apostrophes turn into backslashes, but I
did spend a few seconds wondering why you'd use \s outside a regexp..
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: Sun, 19 Nov 2000 15:27:18 GMT
From: al@maystreet.com (Al Rosetti)
Subject: Need easy Perl help, will trade for online presentation at www.maystreet.com
Message-Id: <3a17fdb4.622883@news>
I'm not a code expert and I'm having trouble setting up a counter
system for my website, www.maystreet.com. If you'll build me a
counter and a simple page search (allows users to input a keyword in a
text box that sends them to a corresponding URL) I'll be happy to
build you an online presentation for whatever you need. Whether you
want an online photo album or a presentation to sell a
car/house/whatever I'll take care of it.
sincerely,
Al Rosetti
al@maystreet.com
www.maystreet.com
------------------------------
Date: Sun, 19 Nov 2000 17:05:53 GMT
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: Need easy Perl help, will trade for online presentation at www.maystreet.com
Message-Id: <RLTR5.2935$ba3.658024@dfiatx1-snr1.gtei.net>
"Al Rosetti" <al@maystreet.com> wrote in message
news:3a17fdb4.622883@news...
> I'm not a code expert and I'm having trouble setting up a counter
> system for my website, www.maystreet.com. If you'll build me a
> counter and a simple page search (allows users to input a keyword in a
> text box that sends them to a corresponding URL) I'll be happy to
> build you an online presentation for whatever you need. Whether you
> want an online photo album or a presentation to sell a
> car/house/whatever I'll take care of it.
Not that the offer is not tempting, it's just that I don't have any need
for such a presentation.
Here's a link that may help you get underway.
http://www.perl.com/pub/doc/FAQs/cgi/perl-cgi-faq.html
Do a text search for "counter".
Lauren
------------------------------
Date: Sun, 19 Nov 2000 15:17:55 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: Net::SMTP error message;
Message-Id: <8v8qv0$erv$1@nnrp1.deja.com>
In article <3A17A579.4E7FDAFA@yahoo.de>,
jens <jensluetzen@yahoo.de> wrote:
> Hello all,
>
> We have the perl Net::SMTP module running on one of our webservers
> (Netscape Enterprise 3.6 on NT4.0) and the client wants to have
messages
> sent to the SMTP server with the help of this module. It works
perfectly
> with the small exception that there is always an error message
returned
> after pressing the "send"-button, saying: "system could not find path
> specified" even though, as mentioned, the message is actually sent.
We
> checked all the environment variables and could not find any mistake,
we
> reinstalled perl and SP 6.0 but without any success. We simply don't
> know where this error message is generated for us to manipulate the
path
> that the system is obviously trying to access (however unnecessary for
> the functioning...).
> Does anyone have any ideas?
> Any help is greatly appreciated,
--------------------
I had a spurious warning message like that until I added the optional
hello=>'mailhost' to the constructor. try using all the options like
this:
$smtp = Net::SMTP->new('mail', # connect to an SMTP server
Hello => 'mail' ,
Timeout => 30,
Debug => 0,
);
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 19 Nov 2000 14:48:55 GMT
From: "hokiebear" <ayambema@adelphia.net>
Subject: New to Perl. Question
Message-Id: <rLRR5.1795$tR2.48226@news1.news.adelphia.net>
Greetings all. I have an HTML page that has several fields (name, email
etc.) including a textarea field where someone can enter a message. Now, I
am trying to write a PERL program that counts the total number of words the
user has entered in the textarea. This is the subroutine I have written for
the part of the program that will count the words in $Message ($Message has
already been parsed in a separate subroutine) and display an HTML page:
-----------------------------------------------------------------------
sub wordNumber {
@wordCount=split(" ", $Message);
%my_count=();
for ($x = 0; $x < length(@wordCount); $x++ ) {
$my_count{$wordCount[$x]}++;
}
print("Content-type: text/html\n\n");
print("<HTML>\n");
print("<HEAD><TITLE>Guestbook</TITLE></HEAD>\n");
print("<BODY>The number of words in your document is
$my_count.</BODY>\n");
print("</HTML>\n");
}
-----------------------------------------------------------------
The trouble is, when I test the page, it does not report anything for
$my_count. I am new to PERL and can't see what the problem is. Thanks for
your help!
amba
------------------------------
Date: Sun, 19 Nov 2000 15:40:02 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: New to Perl. Question
Message-Id: <mvSR5.1062$xb1.62143@eagle.america.net>
On Sun, 19 Nov 2000 14:48:55 GMT, hokiebear <ayambema@adelphia.net> wrote:
...
>am trying to write a PERL program that counts the total number of words the
>user has entered in the textarea. This is the subroutine I have written for
...
>sub wordNumber {
>
>@wordCount=split(" ", $Message);
>%my_count=();
>
>for ($x = 0; $x < length(@wordCount); $x++ ) {
You need to read the manual. In the perlfunc manual page, the length
function is described:
length EXPR
length Returns the length in characters of the value of EXPR. If EXPR
is omitted, returns length of `$_'. Note that this cannot be
--> used on an entire array or hash to find out how many elements
these have. For that, use `scalar @array' and `scalar keys
%hash' respectively.
> $my_count{$wordCount[$x]}++;
> }
>
> print("Content-type: text/html\n\n");
> print("<HTML>\n");
> print("<HEAD><TITLE>Guestbook</TITLE></HEAD>\n");
> print("<BODY>The number of words in your document is
>$my_count.</BODY>\n");
> print("</HTML>\n");
> }
If you had enabled warnings, you would already know what one of the
problems was:
Global symbol "$my_count" requires explicit package name at...
It looks like you are counting the occurrences of *each* word by
incrementing a count in a hash for each unique word encountered. That
is different from what you say you want. At the end of the for loop,
you will have the frequency distribution of all of the unique words in
$Message stored in the %my_count hash.
If all you want is the count of the number of words in $Message, then
here's a way to do it:
$ cat x
#!/usr/local/bin/perl -w
use strict;
my $Message = 'Now is the time for all good men to
come to the aid of their country.';
wordNumber($Message);
exit(0);
sub wordNumber {
my $my_count;
for ( split ' ', shift ) {
$my_count++;
}
print <<EOF;
Content-type: text/html
<HTML>
<HEAD><TITLE>Guestbook</TITLE></HEAD>
<BODY>The number of words in your document is $my_count.</BODY>
</HTML>
EOF
}
$ perl x
Content-type: text/html
<HTML>
<HEAD><TITLE>Guestbook</TITLE></HEAD>
<BODY>The number of words in your document is 16.</BODY>
</HTML>
$
Why aren't you using the CGI module?
--
Garry Williams
------------------------------
Date: Sun, 19 Nov 2000 10:12:29 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: New to Perl. Question
Message-Id: <slrn91fret.85s.tadmc@magna.metronet.com>
On Sun, 19 Nov 2000 14:48:55 GMT, hokiebear <ayambema@adelphia.net> wrote:
>I
>am trying to write a PERL program that counts the total number of words the
>user has entered
>-----------------------------------------------------------------------
>sub wordNumber {
>
>@wordCount=split(" ", $Message);
You should not use global variables for communicating with functions.
You should pass $Message as an argument instead.
You should have the "use strict" pragma (compiler directive)
enabled in *all* of your Perl programs. It would have helped
catch the error you have below.
sub wordNumber {
my($Message) = @_;
my @wordCount=split(" ", $Message);
but you do not need the @wordCount temporary variable at all anyway...
>%my_count=();
>
>for ($x = 0; $x < length(@wordCount); $x++ ) {
1) You are writing C code in Perl. You should do it the Perl way
when you are writing Perl :-)
2) You should read the contract for a function before you use it.
You don't really sign contracts without reading them, do you?
perldoc -f length
says in part: "this cannot be used on an entire array"
But there you are, using it on an array. You were told not
to do that so you should not do that.
foreach ( @wordCount ) {
or eliminate the temp array:
foreach ( split(" ", $Message) ) {
> $my_count{$wordCount[$x]}++;
> }
>
>$my_count.</BODY>\n");
^^^^^^^^^
That is the very first time that you code mentions that variable,
so of course it has nothing in it, you have never put anything in it.
$my_count (a scalar variable) has no relationship at all to
$my_count{something} (accessing a scalar value in a hash).
>-----------------------------------------------------------------
>
>The trouble is, when I test the page, it does not report anything for
>$my_count.
Perl is doing what you told it to do. Tell it to do something else :-)
>I am new to PERL
Use the docs that you got along with perl.
>and can't see what the problem is.
^^^
You have more than one problem.
Enable warnings:
#!/usr/bin/perl -w
Enable strictures (and put "my" infront of the first use of a variable):
use strict;
Use foreach() for processing a list, use for() when your algorithm
requires access to the position in an array.
It us unclear whether you want to output just the total number
(in which case you don't need a hash at all!), or if you want
the count associated with each word.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 19 Nov 2000 17:09:13 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: New to Perl. Question
Message-Id: <a32g1t8014bnr3geth82d0mjjbbn72up5e@4ax.com>
hokiebear wrote:
>Now, I
>am trying to write a PERL program that counts the total number of words the
>user has entered in the textarea.
>for ($x = 0; $x < length(@wordCount); $x++ ) {
> $my_count{$wordCount[$x]}++;
> }
Drop that "length". It does NOT return the number of array elements
(the's Javascript). "$x < @wordCount" will do.
Simpler still:
foreach (@wordCount) {
$my_count{$_}++;
}
This fills a hash, %
my_count, with counts of *individual* words.
> print("<BODY>The number of words in your document is
>$my_count.</BODY>\n");
This prints the scalar $my_count. Now the scalar $my_count and the hash
%my_count are NOT the same variable.
To make the last this work, all you need to do is:
$my_count = @wordCount;
--
Bart.
------------------------------
Date: Sun, 19 Nov 2000 17:35:21 GMT
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: New to Perl. Question
Message-Id: <tbUR5.3181$ba3.670992@dfiatx1-snr1.gtei.net>
"Garry Williams" <garry@zweb.zvolve.net> wrote in message
news:mvSR5.1062$xb1.62143@eagle.america.net...
> On Sun, 19 Nov 2000 14:48:55 GMT, hokiebear <ayambema@adelphia.net>
wrote:
> ...
> >am trying to write a PERL program that counts the total number of
words the
> >user has entered in the textarea. This is the subroutine I have
written for
> ...
> >sub wordNumber {
> >
> >@wordCount=split(" ", $Message);
> >%my_count=();
> >
> >for ($x = 0; $x < length(@wordCount); $x++ ) {
>
> You need to read the manual. In the perlfunc manual page, the length
> function is described:
>
You should have pointed out that using an array in scalar context
returns the number of elements in that array.
Hence,
for ($x=0; $x<@wordCount; $x++) {}
is the correct form that the OP missed.
Of course, it could probably be better done using a foreach:
foreach $word (@wordCount) {
> > $my_count{$wordCount[$x]}++;
Could become
$my_count{$word}++;
> > }
> > print("Content-type: text/html\n\n");
> > print("<HTML>\n");
> > print("<HEAD><TITLE>Guestbook</TITLE></HEAD>\n");
> > print("<BODY>The number of words in your document is
> >$my_count.</BODY>\n");
> > print("</HTML>\n");
> > }
>
> If you had enabled warnings, you would already know what one of the
> problems was:
>
> Global symbol "$my_count" requires explicit package name at...
s/enabled warnings/used strict/;
>
> $ cat x
> #!/usr/local/bin/perl -w
> use strict;
> my $Message = 'Now is the time for all good men to
> come to the aid of their country.';
> wordNumber($Message);
> exit(0);
>
> sub wordNumber {
> my $my_count;
> for ( split ' ', shift ) {
> $my_count++;
> }
Why all the rigamarole?
sub get_word_count {
my $message = shift;
my $count = split ' ', $message;
$count;
}
and then use it like this:
$count = get_word_count ($Message);
Then you can use the value in places other than simply the sub.
> print <<EOF;
> Content-type: text/html
>
> <HTML>
> <HEAD><TITLE>Guestbook</TITLE></HEAD>
> <BODY>The number of words in your document is $my_count.</BODY>
> </HTML>
> EOF
SE101: How to make your programs easier to understand by making a
function do only one thing at a time.
>
> Why aren't you using the CGI module?
Hardly seems necessary for such a small program. Likewise, I can't find
any mention of 'wordcount' or 'word count', and 'count' only shows up in
contexts different from anything resembling counting words.
Lauren
------------------------------
Date: Sun, 19 Nov 2000 18:01:57 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: New to Perl. Question
Message-Id: <pAUR5.1068$xb1.62939@eagle.america.net>
On Sun, 19 Nov 2000 17:35:21 GMT, Lauren Smith
<lauren_smith13@hotmail.com> wrote:
>"Garry Williams" <garry@zweb.zvolve.net> wrote in message
>news:mvSR5.1062$xb1.62143@eagle.america.net...
>> On Sun, 19 Nov 2000 14:48:55 GMT, hokiebear <ayambema@adelphia.net>
>wrote:
>
>> for ( split ' ', shift ) {
>> $my_count++;
>> }
>
>Why all the rigamarole?
>
>sub get_word_count {
> my $message = shift;
> my $count = split ' ', $message;
> $count;
>}
Use of implicit split to @_ is deprecated at...
--
Garry Williams
------------------------------
Date: Sun, 19 Nov 2000 18:53:01 GMT
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: Re: New to Perl. Question
Message-Id: <hkVR5.3328$ba3.705837@dfiatx1-snr1.gtei.net>
"Garry Williams" <garry@ifr.zvolve.net> wrote in message
news:pAUR5.1068$xb1.62939@eagle.america.net...
> On Sun, 19 Nov 2000 17:35:21 GMT, Lauren Smith
> <lauren_smith13@hotmail.com> wrote:
> >
> >sub get_word_count {
> > my $message = shift;
> > my $count = split ' ', $message;
> > $count;
> >}
>
> Use of implicit split to @_ is deprecated at...
Well that's decidedly uncool. Easily worked around (not that it really
should have to be, IMO):
sub get_word_count {
my $message = shift;
my @words = split ' ', $message;
my $count = @words;
$count; # This line unnecessary
}
What does this deprecation do to some of my one-liners? Yikes.
Lauren
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 4923
**************************************