[19311] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1506 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 13 03:10:32 2001

Date: Mon, 13 Aug 2001 00:10:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997686617-v10-i1506@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 13 Aug 2001     Volume: 10 Number: 1506

Today's topics:
        Parameter asserts?? <miscellaneousemail@yahoo.com>
    Re: Parameter asserts?? <miscellaneousemail@yahoo.com>
    Re: Perl with CGI with Cookies... HELP! <gnarinn@hotmail.com>
    Re: permuting extremely large string <tsee@gmx.net>
    Re: Searches on www.perl.com not returning phrases?? <comdog@panix.com>
    Re: searching files from linux to Internet (Tad McClellan)
    Re: Shouldn't sub foo {} be equivalent to sub foo {retu (John Lin)
    Re: Shouldn't sub foo {} be equivalent to sub foo {retu <mjcarman@home.com>
        small CGI.pm hack, code review request <shutupsteve@awdang.no.thanks.com>
    Re: Statement modifiers?? <miscellaneousemail@yahoo.com>
    Re: Unexplained process killing (Logan Shaw)
        URL Encode <jtjohnston@courrier.usherb.ca>
        Webpage & Link counter - help <didi@attglobal.net>
    Re: Webpage & Link counter - help <tsee@gmx.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 13 Aug 2001 03:11:52 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Parameter asserts??
Message-Id: <MPG.15e0f33714124496989734@news.edmonton.telusplanet.net>

Hi everyone,

Every day I try and read some more documentation about Perl.  In line 
with this I was reading some stuff from Tom Christiansen on Perl Style: 
Defensive Programming.  In his notes Tom mentions "Parameter asserts" as 
something to do.  

I tried searching www.perl.com for this phrase and although I came up 
with some articles I could not see much of anything in the one I was 
looking at about this phrase.  I even did a search for the exact phrase 
on the article I was looking at and this phrase was nowhere in it (even 
though it came up as one to match my search).  

Soooo....I figured this was another phrase to throw out on this newsgroup 
for clarification.  From what I can gather it seems that parameter 
asserts is a fancy way of saying function prototypes.  Is this right?

Thanks.

-- 
Carlos 
www.internetsuccess.ca


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

Date: Mon, 13 Aug 2001 06:18:13 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Parameter asserts??
Message-Id: <MPG.15e11f1e5b1786e3989738@news.edmonton.telusplanet.net>

In article <3b77582b@news.victoria.tc.ca>, Malcolm Dew-Jones at 
yf110@vtn1.victoria.tc.ca says...

> Before a program unit does anything you can notice (including taking up
> time, if possible) it should check that all its input is valid, and refuse
> to run if the input is not valid.

If that is what parameter asserts are, no problem (at least in terms of 
my using them).  I check just about every possible scenario I can think 
of in my most important functions.  I first write a basic function and 
get it working.  Then I rewrite the function in pseudocode.  Working into 
the pseudocode a check for every possible input that I can think of. Then 
I implement the pseudocode and flesh out the function to check for bad 
input.  It's a labor intensive work but I have to do this because of the 
nature of my web site.  Some of the stuff I will put on it may end up not 
being very popular and I have to make sure that my web site is as secure 
and free from the affects of surprises as I can reasonably make it.  Not 
to mention that I don't want any bugs to surprise my subscribers.  

Many times I spend more time trying to cover all the bases than writing 
the basic code of a function.

Thanks for giving me your input Malcolm.

-- 
Carlos 
www.internetsuccess.ca


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

Date: Mon, 13 Aug 2001 00:51:26 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Perl with CGI with Cookies... HELP!
Message-Id: <997663886.00361258769407868.gnarinn@hotmail.com>

In article <9l6qok$3oh$1@bob.news.rcn.net>, AJ M <jerseycat10@yahoo.com> wrote:
>Hello, everyone.   I have modest experience with perl writing cgi's, but my
>knowledge of cookies (writing them) on any platform or language is nil.
>However, I decided to read up on the topic, since I thought that using
>cookies would be neat on my site.  Right now, I am have a login script that
>takes a username and password, does some error checking, and prints out some
>html depending on whether or not the username/password combo matches a flat
>test file database.  If it does, I try to set a cookie like so:
>
>print "Set-Cookie:validity=$status; expires=Sat, 11-Aug-2001 00:00:00
>GMT;domain=.rowan.edu ;path=/\n";
>
>I then have another CGI, for members only, which attempts to determine
>whether or not the above cookie has been set or not:
>
>if($ENV{'HTTP_COOKIE'})
>{
>  read(STDIN, $buffer, $ENV{'HTTP_COOKIE'});
>
>  @cookies = split (/;/, $buffer);
>
>  foreach $cookie (@cookies)
>  {
>    ($name, $value) = split (/=/, $cookie);
>    $crumbs{$name} = $value;
>  }
>  $status = $crumbs{'validity'};
>
>and so on....
>
>
>I know there is probably some flaws in the above snippets of code, can
>someone tell me what I am doing wrong, it would be greatly appreciated,

yes. you should be using the CGI module

gnari



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

Date: Mon, 13 Aug 2001 08:42:19 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: permuting extremely large string
Message-Id: <9l7sm8$gl$02$1@news.t-online.com>

"Godzilla!" <godzilla@stomp.stomp.tokyo> schrieb im Newsbeitrag
news:3B770824.FEC02294@stomp.stomp.tokyo...

> my big butt

Cute. That's what I thought.

How many elephants do you have sitting in your butt that sing Creed's "My
Own Prison"?

;)

Steffen. Same Troll.




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

Date: Mon, 13 Aug 2001 01:10:56 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Searches on www.perl.com not returning phrases??
Message-Id: <comdog-D61BF5.01105613082001@news.panix.com>

In article <MPG.15e0f9baa6eba0d9989736@news.edmonton.telusplanet.net>, 
Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:

> I have noticed that when I search for an item on www.perl.com the 
> searched for phrase does not seem to appear in articles that suppossedly 
> match my search.  

> Search for "statement modifiers"

    returns one hit which contains the whole phrase

> Search for "true and false"

    returns no hits

> Link into the first articles that appear and search for the phrases in 
> the articles.  They are not there.  

it appears that you are searching without the quotation marks
and that you are getting near hits.

-- 
brian d foy <comdog@panix.com>
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



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

Date: Sun, 12 Aug 2001 20:00:20 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: searching files from linux to Internet
Message-Id: <slrn9ne64k.1vr.tadmc@tadmc26.august.net>

brian <brian@numenor.screaming.net> wrote:
>hi, thanks to both of you
>
>yeah should have used:
> 
>   #!/usr/bin/perl -w
>   use strict;
>
>would have spotted this: 
>
>> That should be: use CGI:


No, perl would have spotted that ( "Use" instead of "use") even 
_without_ warnings or strictures.

perl always notices syntax errors, you cannot disable syntax checking :-)

Did you know that you can check syntax, even for CGI programs,
from the command line?

   perl -cw counter.cgi


You should probably also have a look at all of the FAQs that
mention CGI programming:

   perldoc -q CGI

particularly this one:

   "How can I get better error messages from a CGI program?"




But you've still left me wondering what the "files on the internet"
bit was about...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 12 Aug 2001 18:08:16 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: Shouldn't sub foo {} be equivalent to sub foo {return} or sub foo {()} ?
Message-Id: <a73bcad1.0108121708.5cb81b49@posting.google.com>

Tina Mueller wrote
> there's another unspecified behaviour:

I can explain them.  If we invent a term "literal @_" (sub's argument list)
and separate it with the dynamic global @_ then you will see.

(This is just an invention that happen to explain.  Not a real thing.)

> 03:56pm tina@lux:perl 665> perl -wle'
> sub test {@_}

sub test will return dynamic @_.

> @_ = (2,3,4);
> @x = &test;
> print "<@x>"'
> <2 3 4>

Yes, dynamic @_ (2,3,4) is returned.

> 03:57pm tina@lux:perl 666> perl -wle'
> sub test {}

sub test will return literal @_ (its argument list)

> @_ = (2,3,4);

This sets the dynamic @_.

> @x = &test;

literal @_ (its argument list) is empty.

> print "<@x>"'
> <>

Yes, result is empty.

> 03:57pm tina@lux:perl 667> perl -wle'
> sub test {}
> @_ = (2,3,4);
> @x = &test(@_);
> print "<@x>"'
> <2 3 4>

literal @_, which is set to the dynamic @_ (2,3,4), is returned.

> and perlsub says:
> |        &foo;               # foo() get current args, like foo(@_) !!

This is true.  It refers to the dynamic @_.

sub foo { &test }
sub test { 1,@_ }
@x = foo(2,3,4);
print "<@x>";
<1 2 3 4>

And no contradiction to my theory in the following example

sub foo { &test }
sub test {}
@x = foo(2,3,4);
print "<@x>";
<>

because sub test {} return literal @_ which is empty.

Best regards.
John Lin


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

Date: Mon, 13 Aug 2001 02:38:13 GMT
From: Michael Carman <mjcarman@home.com>
Subject: Re: Shouldn't sub foo {} be equivalent to sub foo {return} or sub foo {()} ?
Message-Id: <3B773D26.50403@home.com>

Martien Verbruggen wrote:
 >

> An empty sub will actually return @_.

 > [...]

> I don't know where, if anywhere, this is documented.

 > [...]

> somehow I must have heard about it in the past, somewhere.


It came up here in a different thread last week, which was no more 
conclusive.

One oddity: this doesn't hold if the sub is called in scalar context:

#!/usr/local/bin/perl

@x = test(1, 2, 3);
$x = test(1, 2, 3);

print "\@: [@x]\n";
print "\$: [$x]\n";

sub test {}
__END__
@: [1 2 3]
$: []

I expected to get "$: [3]"

> Does anyone have a documentation reference for this? Or is it just
> unspecified behaviour?


As near as I can tell it's unspecified.

-mjc



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

Date: Sun, 12 Aug 2001 18:22:42 -0700
From: "Stephen Deken" <shutupsteve@awdang.no.thanks.com>
Subject: small CGI.pm hack, code review request
Message-Id: <tneauhre8vs8e4@corp.supernews.com>

Hi all,

I posted a message here via Google groups yesterday, before realizing my =
ISP carries clpm.  Google evidently hasn't perfected their =
message-posting code, because the message I wrote has yet to appear.  =
When it does, feel free to ignore it.

In my original post, I asked if there was any method provided by CGI.pm =
to add or remove cookies from the internal data structure, so I could =
'fake' the cookies for the newly logged in and newly logged out pages.  =
Since then I've read the sources and discovered that there isn't, so I =
hacked it up to make my own.

Basically, what I need to do is this.  Within the lifetime of a single =
HTTP / CGI request, I need to be able to set a cookie and then read its =
value later on.  Essentially I need to do this:

  use CGI ':cookie';
  my $cookie =3D cookie( -name=3D>'a_cookie', -value=3D>'this is the =
value' );
  print "Set-cookie: $cookie\n";
  print "Content-type: text/html\n\n";
  print "a_cookie: " . cookie('a_cookie') . "\n";

The first time you load this page, it claims that there is no cookie =
named a_cookie (because it wasn't sent in the request).  Subsequent =
calls succeed assuming that the cookie was set successfully.  I need the =
cookie to be there in the lifetime of the first request (and I need to =
be able to fake like it isn't there at some points, as well).

To achieve this, I added two routines to CGI.pm: add_cookie() and =
remove_cookie().  add_cookie() adds a cookie to the internal data =
structure of CGI.pm, while remove_cookie() removes one.  It's purely a =
hack to allow other parts of the program to recognize that the cookie =
has been set / cleared, even if it's it was / was not sent to the server =
in the first place.

Anyway, below is the patch.  If someone could look over it for me, make =
sure I'm not doing anything that I shouldn't be doing, and basically =
just give me a rubber stamp of approval, I'd appreciate it.

Thanks,

--sjd;

__DATA__
*** CGI.pm.orig Sun Aug 12 20:45:16 2001
--- CGI.pm      Sun Aug 12 20:46:19 2001
***************
*** 164,170 ****
                          submit reset defaults radio_group popup_menu =
button autoEscape
                          scrolling_list image_button start_form =
end_form startform endform
                          start_multipart_form end_multipart_form =
isindex tmpFileName uploadInfo URL_ENCODED MULTIPART/],
!               ':cgi'=3D>[qw/param path_info path_translated url =
self_url script_name cookie Dump
                         raw_cookie request_method query_string Accept =
user_agent remote_host=20
                         remote_addr referer server_name server_software =
server_port server_protocol
                         virtual_host remote_ident auth_type http =
use_named_parameters=20
--- 164,170 ----
                          submit reset defaults radio_group popup_menu =
button autoEscape
                          scrolling_list image_button start_form =
end_form startform endform
                          start_multipart_form end_multipart_form =
isindex tmpFileName uploadInfo URL_ENCODED MULTIPART/],
!               ':cgi'=3D>[qw/param path_info path_translated url =
self_url script_name add_cookie remove_cookie cookie Dump
                         raw_cookie request_method query_string Accept =
user_agent remote_host=20
                         remote_addr referer server_name server_software =
server_port server_protocol
                         virtual_host remote_ident auth_type http =
use_named_parameters=20
***************
*** 2159,2164 ****
--- 2159,2204 ----
      return $url;
  }
 =20
+ END_OF_FUNC
+=20
+ #### Method: add_cookie
+ # Adds a cookie to the internal structure.
+ #  Parameters:
+ #   -name -> name for this cookie (required)
+ #   -value -> value for this cookie (required)
+ ####
+ 'add_cookie' =3D> <<'END_OF_FUNC',
+ sub add_cookie
+ {
+   my ($self, @p) =3D self_or_default(@_);
+   my ($name, $value) =3D $self->rearrange([NAME,VALUE],@p);
+   return undef unless (defined $value);
+   require CGI::Cookie;
+   $self->{'.cookies'} =3D CGI::Cookie->fetch unless =
$self->{'.cookies'};
+   $self->{'.cookies'}->{$name}->{'name'} =3D $name;
+   push( @{$self->{'.cookies'}->{$name}->{'value'}} =3D> $value );
+   bless( $self->{'.cookies'}->{$name}, 'CGI::Cookie' );
+   return 1;
+ }
+ END_OF_FUNC
+=20
+ #### Method: remove_cookie
+ # Removes a cookie from the internal structure.
+ #  Parameters:
+ #   -name -> name for this cookie (required)
+ ####
+ 'remove_cookie' =3D> <<'END_OF_FUNC',
+ sub remove_cookie
+ {
+   my ($self, @p) =3D self_or_default(@_);
+   my ($name) =3D $self->rearrange([NAME],@p);
+   return undef unless (defined $name);
+   require CGI::Cookie;
+   $self->{'.cookies'} =3D CGI::Cookie->fetch unless =
$self->{'.cookies'};
+   delete $self->{'.cookies'}->{$name}
+     if (exists $self->{'.cookies'}->{$name});
+   return 1;
+ }
  END_OF_FUNC
 =20
  #### Method: cookie



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

Date: Mon, 13 Aug 2001 02:55:53 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: Statement modifiers??
Message-Id: <MPG.15e0ef7751a1dab7989733@news.edmonton.telusplanet.net>

In article <20010812200902.398$NG@newsreader.com>, ctcgag@hotmail.com at 
ctcgag@hotmail.com says...

> When you wish to use a foreach, if, while, unless, etc with only one
> statement, you can put the statement first, then the modifier, without
> using braces.

I believe the above statement is as good as one could hope to find in a 
single sentence explaining what a statement modifier is and how to use 
one.

Thank you.

-- 
Carlos 
www.internetsuccess.ca


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

Date: 12 Aug 2001 20:53:31 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Unexplained process killing
Message-Id: <9l7bur$inr$1@charity.cs.utexas.edu>

In article <223f9ce4.0108120730.524f2d57@posting.google.com>,
Moran Goldstein <moran-gy@actcom.co.il> wrote:
>I tried the test script you posted, and it works consistently up to
>around 200x200x200. At 250x250x250 it's almost always killed.

That wasn't a test script.  It was a script meant to demonstrate a
fact: that the Perl interpreter uses several times as much space as a
language like C does in order to store floating point numbers.  A
second fact too: that Perl requires more space for the same number of
elements if they're stored in a multidimensional array.

Anyway, these are facts that you should take into account when
designing a solution.

>I sent an E-mail to my hosting service asking if they have any
>specific limits setup, at that point I'll know more. It's hosted on a
>dedicated server, so there aren't other users on the server that might
>effect server load.

That's good, because otherwise they probably won't be happy.

Chances are, though, sending an e-mail to your provider isn't going to
solve the problem for you.  You need to either use another design that
isn't as demanding of memory, or you need to learn how the operating
system that you're using works and how to determine what's going to fly
and what isn't.

>Is the problem the amount and type of values, or the amount of
>processes?

The number of values, the size of each value, and the overhead Perl
requires to store them.

> ie - if I write something to loop 20,000,000 times through
>"my $foo = 2+2", and discard the results, will it still drain
>resources?

It won't use more and more memory, if that's what you're asking.
It will drain a resource known as "cpu time", though.  :-)

>Will it help to limit the values to integers?

I don't think so.  Actually, I don't even think you can.  If you
do "$x = 3", it will be stored as a floating point number anyway.

>Are there any methods to
>keep the values handy, but not drain so much memory?  I was referred to
>the 'vec' function which stores integers, might that help?

One method is to store them in a temporary file on disk.

Another is to store a bunch of numbers into a byte string.  Normally
each number is stored as a separate scalar value, and the large
overhead of storing a scalar is incurred once for every number.  If you
store a bunch of numbers all into a single scalar, you'll save a lot of
overhead.  But, it will be a pain.  This is the vec() method (although
you can also do it with pack() and substr(), which can be better if you
need to store floating point numbers, for instance).  Both methods let
you access the individual bytes (or even bits) of a big long string of
bytes, i.e. of a Perl scalar.

>How do image editing programs do it?

I haven't looked at them in detail, but my guess is that they
accomplish it by doing that part in C code, which is then given an
interface so it can be called from Perl.  :-)

  - Logan
-- 
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)


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

Date: Mon, 13 Aug 2001 06:00:22 GMT
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: URL Encode
Message-Id: <3B776D65.6E4A85A4@courrier.usherb.ca>

Is there a way to url encode $message ?

$message = "what a nice day it's going to be!"

http://www.nowhere.com/something.cgi?$message

whereby $message becomes:

"what%20a%20nice%20day%20it's%20going%20to%20be%3f"



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

Date: Mon, 13 Aug 2001 14:20:49 +0800
From: "Bob" <didi@attglobal.net>
Subject: Webpage & Link counter - help
Message-Id: <3b77734b_2@news1.prserv.net>

I would like a relatively simple counter to count webpage hits and Link
clicks with the results saved in a file which I can subsequently check &
clear. Where can I find such code, I assume it would be written in Pearl?

Thanks, Bob.




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

Date: Mon, 13 Aug 2001 08:46:12 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Webpage & Link counter - help
Message-Id: <9l7sti$bnr$03$1@news.t-online.com>

"Bob" <didi@attglobal.net> schrieb im Newsbeitrag
news:3b77734b_2@news1.prserv.net...
> I would like a relatively simple counter to count webpage hits and Link
> clicks with the results saved in a file which I can subsequently check &
> clear. Where can I find such code, I assume it would be written in Pearl?

I don't think you can write that in *Pearl*.

I'd say you can find that in the FAQ.

RTFM

Steffen Müller




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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 1506
***************************************


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