[19870] in Perl-Users-Digest
Perl-Users Digest, Issue: 2065 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 4 18:05:31 2001
Date: Sun, 4 Nov 2001 15:05:08 -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: <1004915108-v10-i2065@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 4 Nov 2001 Volume: 10 Number: 2065
Today's topics:
Re: .cgi program <creafin1998@yahoo.com>
Re: Can perl open a new browser window without embeddin <tintin@snowy.calculus>
Re: Failed scripts leave Perl behind <perl@omnibus-systems.net>
Re: Failed scripts leave Perl behind <perl@omnibus-systems.net>
Re: Failed scripts leave Perl behind <mgjv@tradingpost.com.au>
Re: Good Perl Tutorials ??? <mgjv@tradingpost.com.au>
Re: Handling file in perl.....please help (Clinton A. Pierce)
Re: Pattern matching with "(" complains... <uri@stemsystems.com>
Re: Pattern matching with "(" complains... <tinamue@zedat.fu-berlin.de>
Perl-Bug? It crashes while accessing hash value!!! <markus.cl@gmx.de>
Re: Perl-Bug? It crashes while accessing hash value!!! <markus.cl@gmx.de>
Please help beginner with using cookies! <msisto@chat.carleton.ca>
Re: Please help beginner with using cookies! (Mark Taylor)
Re: Please help beginner with using cookies! <tintin@snowy.calculus>
Re: Please help beginner with using cookies! <msisto@chat.carleton.ca>
Retrieving Perl variables from C (Gary R. Day)
Serial Port control under Win32::SerialPort (David)
Software error with -T using sendmail <spamfree@go-away.net>
Re: Untainting globally with regular expression? <spamfree@go-away.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 4 Nov 2001 13:45:45 -0600
From: "John Smith" <creafin1998@yahoo.com>
Subject: Re: .cgi program
Message-Id: <tub6kc9s0i8q1b@corp.supernews.com>
When the..
in data file is: the out data file is:
40000 lines 27 lines and the 500 server error
1800 lines 1011 lines and the 500 server error
1700 1243 and the 500 server error
1650 1515 and the 500 server error
1624 1624 (as expected)
1600 1600 (as expected)
Interestingly, I took several fields (columns) out of the 'in data file'
shrinking the size down for an equal # of lines from the above example and
found:
When the...
in data file is: the out data file is:
1799 lines 1799 lines (as expected)
3899 lines 585 lines and the 500 server error
I'm not getting any error messages from the server log that I have access to
on any of these 500 server errors I get through my browser.
Here's a copy of the entire program with generic names replacing the actual
variable names. I know that it's a little sloppy. For those of you who are
professionals, I apologize.
#!/usr/local/bin/perl
use CGI qw(param);
###################
# Execution Order #
###################
&parse;
use LWP::Simple;
&page_data;
#############
# Sub Routines #
#############
sub page_data {
print "Content-type: text/html\n\n";
# Example input data file line entry after removing some fields (columns) as
I outlined in my email above #
#text1,text2,data1,data2,data3,data4,data5#
open (LOGFILE, "</path/to/datafile.csv");
@lognfile = <LOGFILE>;
# Main for loop starts with 2nd line of input data file
for ($z = 1; $z <= $#lognfile; $z++) {
$s = 0;
$count = 0;
$tv = 0;
$tc = 0;
($text01, $text02, $data01, $data02, $data03, $data04, $data05) = split /,/,
$lognfile[$z];
$sum = $data01 + $data02 + $data03 + $data04 + $data05;
if ($data01 > 0) { $s = $s + 1; $count = $count + 1;}
if ($data02 > 0) { $s = $s + 1; $count = $count + 1;}
if ($data03 > 0) { $s = $s + 1; $count = $count + 1;}
if ($data04 > 0) { $s = $s + 1; $count = $count + 1;}
if ($data05 > 0) { $s = $s + 1; $count = $count + 1;}
if ($data01 <= 0) { $count = $count + 1;}
if ($data02 <= 0) { $count = $count + 1;}
if ($data03 <= 0) { $count = $count + 1;}
if ($data04 <= 0) { $count = $count + 1;}
if ($data05 <= 0) { $count = $count + 1;}
$z = $z + 1;
($text1, $text2, $data1, $data2, $data3, $data4, $data5) = split /,/,
$lognfile[$z];
# BEGIN FOR LOOP
for ($y = $z+1; $y <= $#lognfile; $y++) {
if (($text1 eq "$text01") & ($text2 eq "$text02")) {
$sum = $sum + $data1 + $data2 + $data3 + $data4 + $data5;
if ($data1 > 0) { $s = $s + 1; $count = $count + 1;}
if ($data2 > 0) { $s = $s + 1; $count = $count + 1;}
if ($data3 > 0) { $s = $s + 1; $count = $count + 1;}
if ($data4 > 0) { $s = $s + 1; $count = $count + 1;}
if ($data5 > 0) { $s = $s + 1; $count = $count + 1;}
if ($data1 <= 0) { $count = $count + 1;}
if ($data2 <= 0) { $count = $count + 1;}
if ($data3 <= 0) { $count = $count + 1;}
if ($data4 <= 0) { $count = $count + 1;}
if ($data5 <= 0) { $count = $count + 1;}
}
($text1, $text2, $data1, $data2, $data3, $data4, $data5) = split /,/,
$lognfile[$y];
# END FOR LOOP
}
$tv = $sum / ($count + 0.0001);
$tc = 100 * ($s / ($count + 0.0001));
$tv = sprintf ("%01.2f", $tve);
$tc = sprintf ("%01.1f", $tc);
open (OUT, ">>/path/to/outdatafile.csv") or die "can't open output file:
$!";
print OUT "$text01,$text02,$tv,$tc\n";
close (OUT);
$z = $z - 1;
#end main for loop
}
close (LOGFILE);
#end subroutine
}
#######################
# Parse subroutine #
#######################
sub parse {
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
} else {
print "Content-type: text/html\n\n";
print "ERROR: Bad Method";
exit;
}
foreach $pair (@pairs) {
($key, $value) = split(/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;
if ($form{$key}) {
$form{$key} .= ", $value";
}
else {
$form{$key} = $value;
}
}
}
"John Smith" <creafin1998@yahoo.com> wrote in message
news:tuaut67vl0im2e@corp.supernews.com...
> It has something to do with my data file size. If I keep the file size
down
> (around 1500 lines or less), then the program works fine. The 500 server
> error starts once I increase the number of lines in the data file. The
more
> lines I add to the input file, the fewer lines of output I end up with in
> the output file. Still working on it.
>
> Weird.
>
>
> "Tim Hammerquist" <tim@vegeta.ath.cx> wrote in message
> news:slrn9u9ek4.553.tim@vegeta.ath.cx...
> > Me parece que John Smith <creafin1998@yahoo.com> dijo:
> > > I have a very annoying problem occurring with a new cgi program I
> wrote.
> > > I'm opening a text file and processing data from the file, then
placing
> the
> > > results in another file. Done it a million times with no problems.
> This
> > > one is a little different in the since that I have 2 'for' loops
which
> will
> > > cause the program to loop approximately 40,000 * (40,000 - n) times,
> where n
> > > starts at 1 and is incremented. This is more looping than I usually
> deal
> > > with in a program.
> > >
> > > Anyway, the problem is that the program writes to my output file
about
> 22-27
> > > lines, then terminates. It was consistantly 27 lines, then went down
> to 23
> > > lines after I made a change, then down to 22 lines after another
> change.
> > > After undo-ing my changes, then it still consistantly writes only 22
> lines,
> > > then I get a the "
> > > Internal Server Error
> > > The server encountered an internal error or misconfiguration and was
> unable
> > > to complete your request." error that's so common. I am running the
> program
> > > through my browser and do not have access to telnet.
> > >
> > > Any advise? It seems like I'm bumping up against some kind of buffer
> limit.
> > > Like I said part of my output file gets written (only 22 lines out of
> about
> > > 40,000 that need to be written). I'm totally unfamilar with these
> types of
> > > limitations in the cgi/perl world
> > >
> > > Thanks in advance.
> >
> > You're going to need to give us more details, such as Perl version,
> > platform that your perl's running on, the type of data it's processing,
> > and an example of the code that processes it.
> >
> > And unless you're running your script on a pre-286 processor, your
> > program should be able to process a lot more than 27 lines before
> > croaking.
> >
> > It sounds like an error in your loop logic (you said it's more than
> > you're used to dealing with, right?) but post some code and sample data
> > and we'll see what we can do.
> >
> > Cheers,
> > Tim
> > --
> > You are utterly the stupidest, most self-centered, appallingest excuse
> > for an anthropomorphic personification on this or any other plane!
> > -- Death, The Sandman
>
>
------------------------------
Date: Mon, 5 Nov 2001 08:06:04 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Can perl open a new browser window without embedding Javascript?
Message-Id: <s3iF7.2$Q34.94301@news.interact.net.au>
"Qunfeng Dong" <qfdong@iastate.edu> wrote in message
news:9s3uqe$ec0$1@news.iastate.edu...
>
> Hi there,
>
> Is there a way in perl itself to open a new browser window similar to
> javascript's window.open()? Thanks!
You use the javascript window.open function in a print statement.
------------------------------
Date: Sun, 04 Nov 2001 17:09:52 -0500
From: Ken <perl@omnibus-systems.net>
Subject: Re: Failed scripts leave Perl behind
Message-Id: <u0fbuts6ft0jsst845mdbnqvtvh5pbj4on@4ax.com>
On Thu, 1 Nov 2001 22:45:01 -0600, trammell@haqq.hypersloth.invalid
(John J. Trammell) wrote:
>Use Linux.
Its not a Windows problem, its a Perl problem. Try this, write a Perl
cgi script that contains an infinite loop. When you access the page
the script begins but it will never stop! Leaving the page does not
stop a script on any server that I am aware of. Basically, I need a
process scanner to catch orphaned processes.
------------------------------
Date: Sun, 04 Nov 2001 17:11:16 -0500
From: Ken <perl@omnibus-systems.net>
Subject: Re: Failed scripts leave Perl behind
Message-Id: <06fbutsh4a0s3v3q6qfa976vavnupf8igb@4ax.com>
On Fri, 2 Nov 2001 09:56:53 -0000, "Kevin Brownhill"
<BROWNHIK@Syntegra.Bt.Co.Uk> wrote:
>I think it's Windows. I had a similar problem when writing CGI programs on
>IIS, using visual C++ on NT4. If the program failed, the process was left
>open, leaving lots of processes which could only be killed from task
>manager.
>
>Hope this helps (though I didn't find a solution).
>
>Kevin Brownhill
>
Its not a Windows problem, its a Perl problem. Try this, write a Perl
cgi script that contains an infinite loop. When you access the page
the script begins but it will never stop! Leaving the page does not
stop a script on any server that I am aware of. Basically, I need a
process scanner to catch orphaned processes.
------------------------------
Date: Sun, 04 Nov 2001 22:52:57 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Failed scripts leave Perl behind
Message-Id: <slrn9ubhmi.ctg.mgjv@verbruggen.comdyn.com.au>
On Sun, 04 Nov 2001 17:11:16 -0500,
Ken <perl@omnibus-systems.net> wrote:
> On Fri, 2 Nov 2001 09:56:53 -0000, "Kevin Brownhill"
><BROWNHIK@Syntegra.Bt.Co.Uk> wrote:
>
>>I think it's Windows. I had a similar problem when writing CGI programs on
>>IIS, using visual C++ on NT4. If the program failed, the process was left
>>open, leaving lots of processes which could only be killed from task
>>manager.
>>
>>Hope this helps (though I didn't find a solution).
>>
>>Kevin Brownhill
>>
>
> Its not a Windows problem, its a Perl problem. Try this, write a Perl
> cgi script that contains an infinite loop. When you access the page
> the script begins but it will never stop! Leaving the page does not
> stop a script on any server that I am aware of. Basically, I need a
> process scanner to catch orphaned processes.
That is not a Perl problem. If you wrote an infinite loop in another
language, you;d have the same problem.
Martien
--
|
Martien Verbruggen | I used to have a Heisenbergmobile.
Trading Post Australia Pty Ltd | Every time I looked at the
| speedometer, I got lost.
------------------------------
Date: Sun, 04 Nov 2001 22:44:02 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Good Perl Tutorials ???
Message-Id: <slrn9ubh5q.ctg.mgjv@verbruggen.comdyn.com.au>
On 3 Nov 2001 20:17:06 GMT,
Graham Drabble <graham.drabble@lineone.net> wrote:
> brown@mad.scientist.com (brown) wrote in
> news:4ad84303.0111031149.7a4fd97e@posting.google.com:
>
>> Hi does anyone knows a good site that offers Perl Tutorials, well
>> done, easy to naviguate and accurate???
>>
> I've found
>
><URL:http://www.netcat.co.uk/rob/perl/win32perltut.html> and
\begin{review}
I just skimmed it quickly. A few points that sort of stood out (there
are many smallish and pedantic ones which should feature in an indepth
review, but I'll skip those):
This tutorial was last updated in April 1999. This is old, and it
shows. it also looks like the author had a mindset which was brought
up on Perl 4, and hadn't adapted to Perl 5 yet.
BAD!
There is no mention of strict. This should be mentioned right away, at
the beginning. There is no encouragement to use warnings. both are
extremely bad signs. Any tutorial should mention these at the start,
and encourage readers to always use them.
Subroutines are usually called by prefixing their name with an
ampersand, that is one of these -- & , like so &print_results; . It
used to be cool to omit the & prefix but all perl hackers are now
encouraged to use it to avoid ambiguity. Ambiguity can hurt you if
you don't avoid it.
This of course is utterly wrong. The ampersand changes the semantics
of the subroutine call. "Perl hackers" are not at all encouraged to
use the ampersand, but they are encouraged to _not_ use it, unless
they need the semantic changes.
The definition of what a true or false value is, is incomplete, since
the empty list is left out.
When you add the semicolon(s), the program runs correctly. The chop
function removes the last character of whatever it is given to chop,
in this case removing the newline for us. In fact, that can be
shortened:
This of course is out of date. We no longer use chop() for this
purpose, but we use chomp(). The author mentions chomp() later on, but
he should not even have brought up chop() for this purpose.
There is confusion about what lists are in Perl. The author calls both
arrays and hashes lists. This confusion keeps popping up. He also
seems to be confused about what parens do:
@names=("Muriel","Gavin","Susanne","Sarah","Anna");
print "The elements of \@names are @names\n";
print "The first element is $names[0] \n";
print "The third element is $names[2] \n";
print 'There are ',scalar(@names)," elements in the array\n";
Firstly, notice how we define @names . As it is in a list context,
we are using parens. Each value is comma separated, which is Perl's
default list delimiter. The double quotes are not necessary, but as
these are string values it makes it easier to read and change later
on.
The parens do not produce list context. The assignment to an array
does. The parens are not necessary because of the list context.
The two variables $myvar and @myvar are not, in any way, related.
Not even distantly. Technically, they are in different namespaces.
*sigh*
Then I stopped reading (about 25% through). The whole tutorial is
often inaccurate, and seems to give information when it really
doesn't, or it gives you misinformation. It uses constructions that
shouldn't be encouraged (ampersands for subroutine calls, unnecessary
quotes as in print "$person";).
It fails to encourage the most important tools for new programmers,
which a tutorial is aimed at, namely warnings and strict.
I wouldn't read it.
\end{review
><URL:http://www.inlink.com/~perlguy/internet99/part1.html> and found
> them OK. I'll let someone more qualified say whether or not they
> teach good practices.
This one does not teach good practices.
Martien
--
|
Martien Verbruggen | Freudian slip: when you say one thing
Trading Post Australia Pty Ltd | but mean your mother.
|
------------------------------
Date: Sun, 04 Nov 2001 20:08:06 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Handling file in perl.....please help
Message-Id: <GehF7.231700$K6.110381161@news2>
In article <9s3t20$n6t$1@news.kabelfoon.nl>,
"MAGiC MANiAC^mTo" <no_mto@hotmail.com> writes:
>
> is it also possible to let the script wait for xxx seconds,
> and automatic retry it xxx times before it shows the error?...
>
> and how can we do this?...
With a loop, sleep, a counter and a little bit of thinking. :)
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Sun, 04 Nov 2001 20:30:48 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Pattern matching with "(" complains...
Message-Id: <x7zo62uvkl.fsf@home.sysarch.com>
>>>>> "CM" == Carsten Menke <bootsy52@gmx.net> writes:
>>> P.S. you better define
>>> $text1='helloworld(';
>>> $text2='helloworld(hello';
>>
>> why?
CM> Avoid unessary trouble, you'll always on the save site to use ''
CM> if there are no variables to subsitute, so why not? And ( is a
CM> metacharacter in the regexp, so why should he not use ''?
while i agree about using '' when there is no interpolation, it has no
bearing on the string being used in a regex. regex metachars in general
don't have special meanings in strings. the obvious case of $ should be
known to the code and escape or not as desired.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 4 Nov 2001 21:47:25 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Pattern matching with "(" complains...
Message-Id: <9s4d1d$11lunl$1@fu-berlin.de>
Carsten Menke <bootsy52@gmx.net> wrote:
> On Sun, 04 Nov 2001 17:48:48 +0100, Tina Mueller wrote:
>>
>>
>> why? m/^$text1/ should be alright (supposing there are no
>> metacharacters). m/^$text1/ has got an open end, so anything can follow
>> after $text1
> Look at the $text1 and $text2, isn't ( a metacharacter within a pattern
> match?
yes, i said: "supposing", meaning providing, assumed,
in case.
i was aiming at the fact that m/^PATTERN/ is just enough and that
m/^PATTERN.*$/, like you proposed, is the same but unnecessary
and probably slower. and even more, it makes a difference if
the text that you are matching against contains newlines.
>>> P.S. you better define
>>
>>> $text1='helloworld(';
>>> $text2='helloworld(hello';
>>
>> why?
> Avoid unessary trouble, you'll always on the save site to use '' if there
> are no variables to subsitute, so why not? And ( is a metacharacter in
> the regexp, so why should he not use ''?
he can use '', or "", AFAIR it doesn't make a difference concerning
efficiency. ok, i tend to use '', too, if i don't have a variable
to interpolate, but here i was aiming at the fact that your proposal
sounded like the OP's problems would go away just by using
single quotes. ok, that's overstated.
but what difference should there be between "test(" and 'test(' ?
regards,
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Sun, 4 Nov 2001 21:06:43 +0100
From: "Markus Dehmann" <markus.cl@gmx.de>
Subject: Perl-Bug? It crashes while accessing hash value!!!
Message-Id: <9s476n$1156j6$1@ID-101658.news.dfncis.de>
I found a really mysterious perl behavior. It returns a hash value that I
have never put into the hash. And moreover, SuSe7.0/KDE terminal windows are
destroyed by perl whenever it tries to print this certain hash value !!!
This is what I am doing:
Within an object method, I read a data file into a hash.
A line in the file looks like that: 12---AB CD (2)---27;13 27;19
...
while( <POS> ){
next if( m/^$/ );
my ($posTemplate, $content, $indicesStr ) =
m/([0-9]+)---(.+)\s\([0-9]+\)---(.+)/;
my @posIndices = split ' ', $indicesStr;
${$self->{'pos'}}{$posTemplate . ($self->{'SEP'}) . $content} =
\@posIndices;
}
...
$self->{'SEP'} is a string: "§§".
The hash %{ $self->{'pos'} } contains keys with array references as values.
It's usually no problem. In the example, the array, stored to the key
"AB§§CD" is ("27;13", "27;19")
When I later want to access the values of a certain key the value is totally
wrong (the string "I" instead of two semicolon-separated numbers, the "I"
comes actually from another data structure) and, as described above, the KDE
terminal window vanishes immediately.
Both under Linux and Windows Perl (see below), the hash value contains a
wrong array element.
The problem with the crashing window is just under SuSe 7.0 Linux, Kernel
2.2.16. The used Perl version there is Perl 5.005_03 built for i586-linux.
But the general problem that in the stored array reference, there are wrong
elements that have never read into the array, is the same under Win98Me,
Perl
v5.6.0 built for MSWin32-x86-multi-thread (Binary build 613).
Is it a perl bug? The data file looks normal, and the perl code worked in
many tests before, with other data files.
------------------------------
Date: Sun, 4 Nov 2001 21:45:31 +0100
From: "Markus Dehmann" <markus.cl@gmx.de>
Subject: Re: Perl-Bug? It crashes while accessing hash value!!!
Message-Id: <9s49eg$10kt6b$1@ID-101658.news.dfncis.de>
> I found a really mysterious perl behavior. It returns a hash value that I
> have never put into the hash. And moreover, SuSe7.0/KDE terminal windows
are
> destroyed by perl whenever it tries to print this certain hash value !!!
> ${$self->{'pos'}}{$posTemplate . ($self->{'SEP'}) . $content} =
> \@posIndices;
I found a way to hinder the crash/error. The perl behavior is more
reasonable now but still a bit strange.
Before the certain value is accessed and contains errors, I work with a
reference to $self->{'SEP'}. The reference is called $hashRef
foreach ( @{$ {$hashRef}{$key}} ){
my ($num1, $num2) = split (';', $_);
...
# Later:
$_ = 'I'; # Causes the error later
print; # print an I
}
So, it seems, $_ = 'I' has inserted the char 'I' into the array that is
stored in the hash. And so, the perl interpreter crashed when accessing this
element later becauseit is not properly inserted and allocated.
But why did $_ = 'I' insert the char into the array????
------------------------------
Date: 4 Nov 2001 20:15:13 GMT
From: "Marianne Sisto" <msisto@chat.carleton.ca>
Subject: Please help beginner with using cookies!
Message-Id: <9s47kh$1al$1@bertrand.ccs.carleton.ca>
Hi, I have a question about cookies. I need to create multiple cookies, one
for each person who 'logs on' to my website so it should store the userID
for example - this is no problem I can do this part. But, when the person
logs on AGAIN, I then need to read these cookies and find the one containing
their ID and then display other information stored in the cookie - is there
a way to do this? Like read a certain field of each cookie such as userID,
until I find the one I want, and then read the rest of the information? Or
is there a simpler way to do this?
Thank you
------------------------------
Date: 4 Nov 2001 14:49:43 -0600
From: mtaylor@lrim.com (Mark Taylor)
Subject: Re: Please help beginner with using cookies!
Message-Id: <Xns914F96EFD1728maintainersetifaqorg@128.242.171.114>
"Marianne Sisto" <msisto@chat.carleton.ca> wrote in
<9s47kh$1al$1@bertrand.ccs.carleton.ca>:
>Hi, I have a question about cookies. I need to create multiple cookies,
>one for each person who 'logs on' to my website so it should store the
>userID for example - this is no problem I can do this part. But, when
>the person logs on AGAIN, I then need to read these cookies and find the
>one containing their ID and then display other information stored in the
>cookie - is there a way to do this? Like read a certain field of each
>cookie such as userID, until I find the one I want, and then read the
>rest of the information? Or is there a simpler way to do this?
>Thank you
>
>
>
>
As I understand cookies, you will be writing one cookie per visitor to your
site, on his computer, not yours. And you can store multiple values in a
cookie like in...
print "Set-cookie: user$COOKIE_ID=$username_in; expires=Tuesday, 4-Jul-2000
12:00:00 GMT; path=/\n";
And you can read and parse the values with something like:
sub read_cookie {
$buffer = $ENV{'HTTP_COOKIE'};
@pairs = split(/; /, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$COOKIE{$name} = $value;
}
}
Store one cookie with multiple values. Is this the answer you were looking
for? There may also be a module somewhere to make it easier...
Cheers,
Mark
______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net
------------------------------
Date: Mon, 5 Nov 2001 08:16:59 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: Please help beginner with using cookies!
Message-Id: <HdiF7.5$754.146468@news.interact.net.au>
"Mark Taylor" <mtaylor@lrim.com> wrote in message
news:Xns914F96EFD1728maintainersetifaqorg@128.242.171.114...
> "Marianne Sisto" <msisto@chat.carleton.ca> wrote in
> <9s47kh$1al$1@bertrand.ccs.carleton.ca>:
>
> >Hi, I have a question about cookies. I need to create multiple cookies,
> >one for each person who 'logs on' to my website so it should store the
> >userID for example - this is no problem I can do this part. But, when
> >the person logs on AGAIN, I then need to read these cookies and find the
> >one containing their ID and then display other information stored in the
> >cookie - is there a way to do this? Like read a certain field of each
> >cookie such as userID, until I find the one I want, and then read the
> >rest of the information? Or is there a simpler way to do this?
> >Thank you
>
> And you can read and parse the values with something like:
>
> sub read_cookie {
> $buffer = $ENV{'HTTP_COOKIE'};
> @pairs = split(/; /, $buffer);
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $COOKIE{$name} = $value;
> }
> }
>
> Store one cookie with multiple values. Is this the answer you were
looking
> for? There may also be a module somewhere to make it easier...
Sure is. Comes in the standard CGI.pm module. There are also other modules
specifically designed for dealing with cookies on CPAN
------------------------------
Date: 4 Nov 2001 21:30:59 GMT
From: "Marianne Sisto" <msisto@chat.carleton.ca>
Subject: Re: Please help beginner with using cookies!
Message-Id: <9s4c2j$4qs$1@bertrand.ccs.carleton.ca>
Hi, thank you for that information. I have to write the code myself rather
than use a module though.
Also, I need to store for each user, a list of courses. I have these
courses stored in an array. How can I store the data from an array into a
cookie?
Thank you
"Mark Taylor" <mtaylor@lrim.com> wrote in message
news:Xns914F96EFD1728maintainersetifaqorg@128.242.171.114...
> "Marianne Sisto" <msisto@chat.carleton.ca> wrote in
> <9s47kh$1al$1@bertrand.ccs.carleton.ca>:
>
> >Hi, I have a question about cookies. I need to create multiple cookies,
> >one for each person who 'logs on' to my website so it should store the
> >userID for example - this is no problem I can do this part. But, when
> >the person logs on AGAIN, I then need to read these cookies and find the
> >one containing their ID and then display other information stored in the
> >cookie - is there a way to do this? Like read a certain field of each
> >cookie such as userID, until I find the one I want, and then read the
> >rest of the information? Or is there a simpler way to do this?
> >Thank you
> >
> >
> >
> >
>
> As I understand cookies, you will be writing one cookie per visitor to
your
> site, on his computer, not yours. And you can store multiple values in a
> cookie like in...
>
> print "Set-cookie: user$COOKIE_ID=$username_in; expires=Tuesday,
4-Jul-2000
> 12:00:00 GMT; path=/\n";
>
>
> And you can read and parse the values with something like:
>
> sub read_cookie {
> $buffer = $ENV{'HTTP_COOKIE'};
> @pairs = split(/; /, $buffer);
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $COOKIE{$name} = $value;
> }
> }
>
> Store one cookie with multiple values. Is this the answer you were
looking
> for? There may also be a module somewhere to make it easier...
>
> Cheers,
> Mark
>
____________________________________________________________________________
__
> Posted Via Binaries.net = SPEED+RETENTION+COMPLETION =
http://www.binaries.net
------------------------------
Date: 4 Nov 2001 14:03:49 -0800
From: grday@afterlife.ncsc.mil (Gary R. Day)
Subject: Retrieving Perl variables from C
Message-Id: <857b4fcc.0111041403.2ee26c7@posting.google.com>
When I try to compile the C program that appears below, which I copied
from the book "Programming PERL," I get the messages that follow. The
program is supposed to demonstrate how to retrieve the values of PERL
variables from a C program. Does anyone know what I'm doing wrong?
Many of the warnings can be
fixed with a cast, but I don't know what to do about the warnings
about '->'.
gcc -c -I/interix/usr/lib/perl5/opennt/5.00305/CORE perlex.c
perlex.c: In function `main':
perlex.c:10: warning: assignment makes pointer from integer without a
cast
perlex.c:18: invalid type argument of `->'
perlex.c:18: invalid type argument of `->'
perlex.c:18: warning: passing arg 1 of `Perl_sv_2iv' makes pointer
from integer without a cast
perlex.c:22: invalid type argument of `->'
perlex.c:22: invalid type argument of `->'
perlex.c:22: warning: passing arg 1 of `Perl_sv_2nv' makes pointer
from integer without a cast
perlex.c:27: invalid type argument of `->'
perlex.c:27: invalid type argument of `->'
perlex.c:27: invalid type argument of `->'
perlex.c:27: warning: passing arg 1 of `Perl_sv_2pv' makes pointer
from integer without a cast
*** Error code 1
/* perlex.c */
1 #include <EXTERN.h>
2 #include <perl.h>
3
4 static PerlInterpreter *my_perl;
5
6 main(int argc, char **argv, char **env)
7 {
8 STRLEN n_a;
9 char *embedding[] = { "", "-e", "0" };
10 my_perl = perlalloc();
11 perl_construct( my_perl );
12
13 perl_parse(my_perl, NULL, 3, embedding, NULL);
14 perl_run(my_perl);
15
16 /** treat $a as an integer **/
17 eval_pv("$a = 3; $a **= 2", TRUE);
18 printf("a = %d\n", SvIV(get_sv("a", FALSE)));
19
20 /** treate $a as a float **/
21 eval_pv("$a = 3.14; $a **= 2", TRUE);
22 printf("a = %f\n", SvNV(get_sv("a", FALSE)));
23
24 /** treate $a as a string **/
25
26 eval_pv("$a = 'relreP kcaH rehtonA TsuJ'; $a = reverse($a);",
TRUE);
27 printf("a = %s\n", SvPV(get_sv("a", FALSE), n_a));
28
29 perl_destruct(my_perl);
30 perl_free(my_perl);
31 }
Gary R. Day
grday@afterlife.ncsc.mil
------------------------------
Date: 4 Nov 2001 12:25:10 -0800
From: dgoldman@msn.com (David)
Subject: Serial Port control under Win32::SerialPort
Message-Id: <c7681ff1.0111041225.682597dc@posting.google.com>
I have been trying for days to understand Win32::SerialPort (I'm on a
Win98 box running ActivePerl 5.6.1) and related information. Needless
to say I'm a newbie. The problem I'm trying to solve is to talk to
some hardware that is using RS-232, but I believe it using a
non-standard signaling approach. Basically I need to bring the RTS pin
low to send and high to receive. I also need to be able to check the
CD pin to determine if someone is sending.
I am attempting to write code that sets the RTS pin high and waits
until the CD goes low. Then I want to read raw binary data until the
CD goes high. The data being sent at 2400 Baud (8N1). From what I can
glean - this isn't really a handshaking scheme per se, but some sort
of modified one. I am looking for 9 bytes and the first one is always
supposed to be 0x54.
I can't seem to figure out how to
1) Set RTS high/low
2) Detect CD high/low
3) Capture raw binary data (i.e. 0x01, 0x00, etc.)
Can this be done with Perl?? I looked at Win32API::CommPort and these
lower level functions look like the right thing, but I still can't
figure out the afterfore mentioned things.
What sort issues do I have to worry about if I want to do the same
under Linux?
--David Goldman
------------------------------
Date: Sun, 04 Nov 2001 22:00:33 GMT
From: "spamfree" <spamfree@go-away.net>
Subject: Software error with -T using sendmail
Message-Id: <5UiF7.38350$4x3.4030583@news1.cableinet.net>
I wish to enable taint but get software error opening sendmail.
Do I need to untaint path?
If so, how to do that.
#!/usr/bin/perl -Tw
#<code cut>
open (MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;
# Insecure $ENV{PATH} while running with -T switch ?
------------------------------
Date: Sun, 04 Nov 2001 21:06:05 GMT
From: "spamfree" <spamfree@go-away.net>
Subject: Re: Untainting globally with regular expression?
Message-Id: <15iF7.38102$4x3.4004913@news1.cableinet.net>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9u7upt.g7m.tadmc@tadmc26.august.net...
> spamfree <spamfree@go-away.net> wrote:
> >I want to throw in some code which untaints input from all params in one
> >foul swoop...
> >
> >$all_variables = "$firstname, $familyname, $email"; #etc.
>
>
> I dunno if it will matter in your application, but in some cultures
> the "first" name is the surname (family name).
>
Whatever
>
> >#untaint
> >unless ($all_variables =~ /^([^<]*$/) { #disallow < char
> ^^^^^^^^^^^^^^^
>
> Too weak of a test. Your code is only a "little bit" more
> secure than with no taint checking at all. There is lots
> of mischief possible that does not use that character.
>
(<) just to illustrate my intention to disallow html
Not necessarily to check email addresses though, I agree.
> It is nearly always better to say what you will allow rather
> than what you will disallow. If you go the disallow route,
> you might forget Something Important (as you have done above).
>
Good advice.
As an example, I currently have this in one of my error checking routines:
sub check_data{
if ($firstname =~ tr/a-zA-Z\n\t //c) { #excludes everything else
die $errormessage = "Special characters are forbidden.";
&errorpage;}
{ die 'PLEASE NOTE: The FIRSTNAME field is restricted to Max = 50
characters including spaces! Software error checking' if length $firstname
> 50;
}
>
> > die "Couldn't untaint all variables: $all_variables\n";
> > }
> >$all_variables = $1;
> >
> >Is this possible globally?
>
>
> Possibly. It depends on what characters are allowed in each
> variable and what you are going to do with each variable.
>
> Of course if you don't happen to be doing anything "dangerous"
> with a variable, you don't need to untaint it at all.
>
Its users input I'm worried about!
>
> >or do I have to laboriously untaint each variable
> >individually?
>
>
> You should laboriously untaint each variable, since they should
> probably have different patterns.
OK
>
> I expect you want to allow at-signs in email addresses, but
> not in the proper names for instance. Note that '<' is *legal*
> in email addresses, yet your pattern above disallows them.
>
>
>
> You _could_ use evil symbolic references:
>
> { no strict; # entering "expert only" mode!
>
> foreach my $varname ( qw/firstname familyname email/ ) { # untested
> if ( $$varname =~ /(a much better pattern than the one above)/ )
> { $$varname = $1 }
> else
> { warn "could not untaint \$$varname\n" }
> }
> }
>
>
> But *don't do that!* You will be asking for trouble:
>
> http://www.plover.com/~mjd/perl/varvarname.html
> http://www.plover.com/~mjd/perl/varvarname2.html
> http://www.plover.com/~mjd/perl/varvarname3.html
>
>
> Use scalar values in a hash instead of individual stand-alone
> scalars:
>
> my %var; # all "variables" are colleced here as hash keys
> # load up %var from somewhere
> foreach my $key ( keys %var ) { # untested
> if ( $var{$key} =~ /(a much better pattern than the one above)/ )
> { $var{$key} = $1 }
> else
> { warn "could not untaint '$key'\n" }
> }
Is my %var; a special variable?
-I'll check the docs.
>
> Or, better yet, use a HoH to associate each pattern with the
> scalar that it is to be applied to (untested):
>
> my %var = (
> firstname => { value => 'wherever the value comes from',
> untaint => qr/[\w .,-]+/
> },
> ...
> )
> foreach my $key ( keys %var ) {
> if ( $var{$key} =~ /^($var{$key}{untaint})$/ {
> { $var{$var}{value} = $1 }
> else
> { warn "could not untaint '$key'\n" }
> }
I don't fully understand the line: untaint => qr/[\w .,-]+/
what does qr mean?
and whats a HoH?
Thanks for your help.
------------------------------
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 2065
***************************************