[18948] in Perl-Users-Digest
Perl-Users Digest, Issue: 1143 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 16 00:05:30 2001
Date: Fri, 15 Jun 2001 21:05:06 -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: <992664306-v10-i1143@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 15 Jun 2001 Volume: 10 Number: 1143
Today's topics:
Re: 500 Error <tony_curtis32@yahoo.com>
Re: Best way for batch renaming specific files <krahnj@acm.org>
Re: File::Find skips the leaf nodes in a directory tree <krahnj@acm.org>
having trouble with system <none@this.net>
Re: having trouble with system <tony_curtis32@yahoo.com>
Re: having trouble with system <none@this.net>
Re: having trouble with system <tony_curtis32@yahoo.com>
Re: How to pass parameter between two cgi programs??? <stingchung@kimo.com.tw>
Re: HTML input box variables? <der.prinz@gmx.net>
Re: Memory Issues/File Slurping (Doug McGrath)
perl/Expect.pm's interact function escape squence timer (Keith)
Porblem: Predesignated Runtime? (Kyle Vinson)
Re: Porblem: Predesignated Runtime? (Logan Shaw)
select weirdness/Net::Telnet install barf <mark@zzo.com>
Re: setting @INC at perl compile time <elijah@workspot.net>
Re: Testing if a cookie has been set <leapius@hotmail.com>
Re: Testing if a cookie has been set <mbudash@sonic.net>
Re: Testing if a cookie has been set <mbudash@sonic.net>
Re: Why is bare << deprecated ? (Tim Hammerquist)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Jun 2001 18:32:31 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: 500 Error
Message-Id: <87y9qt5ng0.fsf@limey.hpcc.uh.edu>
>> On Mon, 11 Jun 2001 03:29:02 +0300,
>> "kostantis" <kostantis@yahoo.com> said:
> I have made a simple Perl script and placed it in my
> cgi-bin folder but when I try to execute the cgi file I
> get a 500 error.I habe set permissions (chmod 755),ASCII
That's from the web server. You need to ask this question
in a group that concerns itself with the particular server
you are using, as the solution lies in the configuration
of that server. Head for e.g. the
comp.infosystems.www.servers.unix group, that sounds the
most likely place (fup set).
hth
t
--
Just reach into these holes. I use a carrot.
------------------------------
Date: Sat, 16 Jun 2001 02:13:10 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Best way for batch renaming specific files
Message-Id: <3B2AC0AF.F680013D@acm.org>
Chris Stith wrote:
>
> Michael Segulja <michael.segulja@kingwoodcable.net> wrote:
> > I have some files name filename.0001, filename.0002....filename.0450, etc.
> > I want to rename these files to filename.0001.tif,
> > filename.0002.tif....filename.0450.tif, but I'm not sure how. I'm sure Perl
>
> $file_name = s/(.)/$1\.tif/g;
Ouch, ouch, ouch!
perl -le '$file_name="filename.0450"; $file_name =~
s/(.)/$1\.tif/g;print $file_name'
f.tifi.tifl.tife.tifn.tifa.tifm.tife.tif..tif0.tif4.tif5.tif0.tif
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 16 Jun 2001 03:48:20 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: File::Find skips the leaf nodes in a directory tree?
Message-Id: <3B2AD72F.DC969227@acm.org>
jon chang wrote:
>
> Hi,
>
> I'm trying to write a small script that'd scan a directory recursively
> and create a blank index.html in each subdirectory where no index.html,
> index.htm, or index.cgi is found.
>
> I found the following script skipping the leaf nodes of a directory. Any
> help would be appreciated.
>
> Also, is there a better way of doing things below in Perl, instead
> of invoking system() call.
>
> Regards.
>
> #!/usr/local/bin/perl -w
>
> use File::Find;
> @ARGV = ('.') unless @ARGV;
> find sub {
> if ( !(-e 'index.cgi' || -e 'index.html' || -e 'index.htm') ) {
> system("touch index.html; chown www:www index.html; chmod 644 index.html")
> ;
> }
> }, @ARGV;
#!/usr/local/bin/perl -w
use strict;
use File::Find;
@ARGV = ('.') unless @ARGV;
my $indexfile = 'index.html';
find sub {
return if -e $indexfile or -e 'index.htm' or -e 'index.cgi';
if ( open TEMP, "> $indexfile" ) {
close TEMP;
chown scalar getpwnam( 'www' ), scalar getgrnam( 'www' ),
$indexfile;
chmod 0644, $indexfile;
return;
}
warn "Cannot create $indexfile: $!";
}, @ARGV;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 16 Jun 2001 02:17:27 GMT
From: "Eldorado" <none@this.net>
Subject: having trouble with system
Message-Id: <XkzW6.762$kI6.454362284@newssvr15.news.prodigy.com>
I'm having a bit of a problem using system(). Commands are being read from a
file into a hash, and then based on a user-selected option (the index) a
hash entry is split into scalars. For example:
----------
my $choice = getUserSelection;
return unless (defined $choice);
my ($action, $arg1, $arg2, $arg3) = split(/\|/, $options{$choice});
# some other error checking, not affect any scalars in the above line
system ($action);
----------
The above will fail on the system call, and perl dies.
In the data I'm working with, the commands that get split into $action are
(separately, so this would be across four invocations):
/bin/df -m
/bin/df -i
/usr/bin/top -s
/usr/local/sysstat -report | /usr/bin/less
Nothing special, as you can see.
Now, if I take the above code, assign a literal string to $action, then
everything works well. Like this:
----------
my $choice = getUserSelection;
return unless (defined $choice);
my ($action, $arg1, $arg2, $arg3) = split(/\|/, $options{$choice});
# some other error checking, not affect any scalars in the above line
# let's see if a literal will work
$action = "/bin/df -i"
system ($action);
----------
Bingo! Works like a charm.
Question is, why didn't the first version work?
Okay, to verify that strings are identical, I added the following:
----------
my $choice = getUserSelection;
return unless (defined $choice);
my ($action, $arg1, $arg2, $arg3) = split(/\|/, $options{$choice});
# some other error checking, not affect any scalars in the above line
# let's see if a literal will work
$action2 = "/bin/df -i"
# see if the scalars are equal
print length($action) . " == " . length($action2) . "\n";
system ($action);
----------
The output is "10 == 10", and then the script dies because I'm using $action
for system instead of $action2.
I'm totally baffled. Anyone have any ideas?
Thanks
grim
------------------------------
Date: 15 Jun 2001 21:29:40 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: having trouble with system
Message-Id: <87ofrpi2cr.fsf@limey.hpcc.uh.edu>
>> On Sat, 16 Jun 2001 02:17:27 GMT,
>> "Eldorado" <none@this.net> said:
> I'm having a bit of a problem using system(). Commands
> are being read from a file into a hash, and then based
> on a user-selected option (the index) a hash entry is
> split into scalars. For example:
> ----------
> my $choice = getUserSelection;
Try a
print "choice=<$choice>\n";
exit; # we don't need to do any more as we test
at this point.
Enlightenment should follow.
hth
t
--
Just reach into these holes. I use a carrot.
------------------------------
Date: Sat, 16 Jun 2001 02:45:13 GMT
From: "Eldorado" <none@this.net>
Subject: Re: having trouble with system
Message-Id: <ZKzW6.792$Ip7.457138214@newssvr15.news.prodigy.com>
> Try a
>
> print "choice=<$choice>\n";
> exit; # we don't need to do any more as we test
>
> at this point.
>
> Enlightenment should follow.
Tony
I guess I'm too far in the dark (and still too green) to see the light :-)
If I put this in choose the option for "Display free inodes", then $choice
== "inodes", which is what it should be. And:
print $options{$choice} == "/bin/df -i|yes|yes|yes"
All of which is correct according to what is in the file that drives
getUserSelection. Futher, after the split into scalars:
print $action == "/bin/df -i"
Sorry, the light isn't coming on :-(
grim
------------------------------
Date: 15 Jun 2001 22:21:17 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: having trouble with system
Message-Id: <87ofrpm7o2.fsf@limey.hpcc.uh.edu>
>> On Sat, 16 Jun 2001 02:45:13 GMT,
>> "Eldorado" <none@this.net> said:
>> Try a
>>
>> print "choice=<$choice>\n"; exit; # we don't need to do
>> any more as we test
>>
>> at this point.
>>
>> Enlightenment should follow.
> I guess I'm too far in the dark (and still too green) to
> see the light :-)
You managed to snip the important part of the context in
your reply. Note the "at this point", which was just
after assigning to $choice at
my $choice = getUserSelection;
(or whatever it was). Try the additional debugging lines
there, not in the literal assignment part.
FYI: why did I suggest what I did? Well, obviously you
noted that a literal assignment to $choice worked fine.
So therefore the value in $choice in the real code is
causing the problem. So locate the places where $choice
is assigned to. There's only one, therefore we need to
see what's in $choice after the assignment and that'll be
the source of the error.
hth
t
--
Just reach into these holes. I use a carrot.
------------------------------
Date: Sat, 16 Jun 2001 10:27:40 +0800
From: Have a nice day! <stingchung@kimo.com.tw>
Subject: Re: How to pass parameter between two cgi programs???
Message-Id: <mhglit8qophpjajpn42codnrf6alo6brpv@4ax.com>
If these two cgi programs locate in two different servers and use two
different databases.
and one of the parameters is password....
in that case, What solutions can I use???
thanks again!!
On Fri, 15 Jun 2001 17:55:17 -0000, Chris Stith
<mischief@velma.motion.net> wrote:
>Have a nice day! <stingchung@kimo.com.tw> wrote:
>> How can I pass parameter from a cgi program to another cgi program???
>
>1) as a cookie
>2) as a hidden form field
>3) in a temporary file keyed by some other info
>4) by using a session management module
>5) in a database, keyed by some other info
>6) search for 'session' and 'cgi' on CPAN and Google Groups, and
> read up
>
>Chris
------------------------------
Date: Sat, 16 Jun 2001 04:43:09 +0200
From: "Stefan Weiss" <der.prinz@gmx.net>
Subject: Re: HTML input box variables?
Message-Id: <3b2ac764@e-post.inode.at>
alan@ <alan@headru.sh> wrote:
> Alan J. Flavell <flavell@mail.cern.ch> wrote:
> > On Fri, 15 Jun 2001, alan@ wrote:
> >
> > > Hi, here you go :-
> > >
> > > #!/usr/bin/perl
> >
> > Bang!
>
> Is that good Bang or bad Bang ?
Hm, difficult say *after* the detonation, but judging from the
placement of the explosive, my best guess is that AJF was missing
a -T switch in your script. I don't see any reason to turn taint
mode on in this script though. Maybe he thought you should have
used strict and warnings? Or maybe he didn't like the unnecessary
sub? Maybe he thought you should have used plain HTML instead of
a Perl script?
Questions and questions.
cheers,
stefan
------------------------------
Date: 15 Jun 2001 18:05:38 -0700
From: doug.mcgrath@us.telegyr.com (Doug McGrath)
Subject: Re: Memory Issues/File Slurping
Message-Id: <a4e10296.0106151705.1d84a652@posting.google.com>
> my $string = qr[ \@((:[^\@]|\@\@)*))\@ ];
> (: \s* branch \s* ([^;]*) ; )?
I've been experimenting, and you're suggestions are a great help --
thank you! Doing the larger matches is reducing the memory usage
dramatically. Your suggestions are also giving me some new ideas on
how to better structure my regex's; they're obvious once I've seen
them, but I wouldn't have thought of it otherwise.
One further questions -- I can't find the "(:" combination in the docs
anywhere. It appears to be the equivalent of "(?:" but I haven't been
able to verify that.
Is it a newer feature? On the one machine I'm using, I have 5.6.1
installed, but most of our machines are at 5.004_04, and I don't have
the luxury of updating all of them.
Thanks again!
Doug McGrath
------------------------------
Date: 15 Jun 2001 15:14:18 -0700
From: keith@aztek-eng.com (Keith)
Subject: perl/Expect.pm's interact function escape squence timer
Message-Id: <8683bf68.0106151414.6642aa6@posting.google.com>
The Expect.pm documentation for the interact() function reads:
'Interaction ceases when $escape_sequence is read from FILEHANDLE'
I have an perl script using the Expect.pm module. I want to allow the user to
change from a manual interaction state to a automation state. When the
'$escape_sequence' is read from 'FILEHANDLE' it takes ~15 seconds to move
back to automation mode or out of the interaction mode.( I think this is to
allow for processes to die? I'm not sure) This seems very
ineffiecient to me. Is there some way to speed up this process? Can I modify
any internal timers in Expect.pm?
Thanks,
Keith
------------------------------
Date: 15 Jun 2001 17:05:43 -0700
From: tangfan01@hotmail.com (Kyle Vinson)
Subject: Porblem: Predesignated Runtime?
Message-Id: <abecba05.0106151605.63bfc5da@posting.google.com>
I have what seems to be a tricky problem. Using POE::Component::IRC I
have created a group of Perl IRC bots that do various things (log,
annoy, etc. ;) One of these bots I am trying to make able to announce
something in an IRC channel at a given set of times. Now, it can
announce fine, but it can't do it at the correct times. I've tried
using sleep, alarm, even using for loops to delay things until it
detects at the right time. I am easily able to get times using
localtime(), but to be able to detect the time in real time is
well-nigh impossible, simply because of the loops required for Perl to
watch the time constantly (along with the fact that it never
PROGRESSES past that loop to its other functions).
If I could use a cronjob or such, I would, but it is better if the bot
stays connected between announcements, I can't. Even having cron do
something that the script can then detect would require it to
constantly check this time, right?
The way I have it set now, it looks for IRC messages occuring within a
certain timeframe (IE, it checks time whenever there's a message, and
announces when it sees a message in the times I've set), but this is
clunky and unreliable at best, along with annoying, as it will often
blither at every message that falls within this time frame (normally a
minute long), which causes the Channel OPs to punt the bot.
I've been working at this one little problem for 6 hours now, and it
just refuses to crack. And the mighty Tom Christiansen doesn't seem
to have solved my problem previously, either ;-)
Thanks in Advance for your time,
Tangfan
------------------------------
Date: 15 Jun 2001 19:39:39 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Porblem: Predesignated Runtime?
Message-Id: <9ge9sb$lo$1@charity.cs.utexas.edu>
In article <abecba05.0106151605.63bfc5da@posting.google.com>,
Kyle Vinson <tangfan01@hotmail.com> wrote:
>I have what seems to be a tricky problem. Using POE::Component::IRC I
>have created a group of Perl IRC bots that do various things (log,
>annoy, etc. ;) One of these bots I am trying to make able to announce
>something in an IRC channel at a given set of times. Now, it can
>announce fine, but it can't do it at the correct times. I've tried
>using sleep, alarm, even using for loops to delay things until it
>detects at the right time. I am easily able to get times using
>localtime(), but to be able to detect the time in real time is
>well-nigh impossible, simply because of the loops required for Perl to
>watch the time constantly (along with the fact that it never
>PROGRESSES past that loop to its other functions).
Here's a little clock script I have that prints the time every minute,
right (about) as the minute changes:
#! /usr/local/bin/perl
$| = 1;
while (1)
{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)
= localtime(time);
if ($hour < 12)
{ $ampm = 'AM'; }
else
{ $hour = $hour - 12; $ampm = 'PM'; }
if ($hour eq 0)
{ $hour = 12; }
printf (" %2d:%2.2d%s\r", $hour, $min, $ampm);
sleep (60 - $sec) unless $sec >= 60;
}
Basically, what it does is it figures out the present time and uses
that information to figure out how long it should sleep. It doesn't
check the current time after the sleep, although it could if I were
paranoid (I might want to make it handle receiving asynchronous signals
like SIGALRM without printing the time unnecessarily).
The way I do the calculations works out to be very easy for me, because
I don't need to sleep until a particular time; I just need to sleep for
however many seconds remain of the current minute. That makes the
math a bit easier.
In your case, what I'd do is use the Time::Local module (which is
included in the Perl distribution) to convert your target time into a
an integer number of seconds (i.e. seconds since midnight January 1,
1970). Then, you can call the time() function to find the current time
in the same units, and if you subtract the two, you'll know how long
(in seconds) it will be until the target time, and then you know
how long to sleep.
For instance, to sleep until 8:00am Christmas morning this year:
use Time::Local;
$santa_time = timelocal (0, 0, 8, 25, 12-1, 2001);
$now = time;
sleep ($santa_time - $now);
print "The time now is ", scalar localtime, "\n";
Hope that helps.
- Logan
--
my your his her our their _its_
I'm you're he's she's we're they're _it's_
------------------------------
Date: Fri, 15 Jun 2001 14:34:29 -0700
From: <mark@zzo.com>
Subject: select weirdness/Net::Telnet install barf
Message-Id: <Pine.LNX.4.33.0106151428520.1488-100000@zzo.com>
On my RedHat 7.1 i586 (laptop) system perl 5.6.1
Net::Telnet won't install using CPAN since 'make test'
barfs.
The select call to read on a dummy handle returns 1!
briefly:
socket SOCK, AF_INET, SOCK_STREAM, 0;
$bitmask = '';
vec($bitmask, fileno(SOCK), 1) = 1;
$nfound = select ($bitmask, undef, undef, 0);
$nfound is 1 with SOCK allegedly ready to read!
Of course actually reading from it produces a SIGPIPE
since it's not connected to anything.
The 'socket' & 'select' calls themselves don't barf.
I'm afraid to force install if there's something deep down
wrong w/my select.
Any ideas greatly appreciated -thanks!
Mark
------------------------------------------
Mark Ethan Trostler mark@zzo.com
Computing Solutions http://www.zzo.com
------------------------------------------
------------------------------
Date: 15 Jun 2001 22:26:40 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: setting @INC at perl compile time
Message-Id: <eli$0106151808@qz.little-neck.ny.us>
In comp.lang.perl.misc, John Imrie <john.imrie@pa.press.net> wrote:
> > I've ended up pushing a bunch of stuff into the config.sh
> > "otherlibdirs" variable, but is that the right way? And how
> > much of a bad thing is it to have a directory appear multiple
> > times in @INC? I've still got my PERL5LIB environment variable
> > for now...
> use lib( 'dir', 'dir')
>
> will push the directories onto @INC
I know this.
> If you want to compleatly rewrite @INC then
>
> BEGIN {
> @INC=('new directory list')
> }
>
> Note I *STRONGLY* advise *NOT* using thesecond option unless you know
> *EXACTLY* what you are doing and why
I know this too.
Both of those require editing perl *scripts* to be in effect. I want
to permanently set the default perl @INC search path at the compile
time of the perl interpreter. perl.c makes some two dozen or so calls
to incpush(char*dir, int addsubdirs, int addoldvers) to set @INC.
A quick hack to perl.c to print out the dir of each of these calls
later, and this is what I have:
$ ./perl -e '$,="\n";print @INC' | fold -77
Pushing (/home/user/perl5lib, T, T) to @INC from PERL5LIB
Pushing (/usr/lib/perl5/5.6.1/i686-linux, F, F) to @INC from ARCHLIB_EXP
Pushing (/usr/lib/perl5/5.6.1, T, F) to @INC from PRIVLIB_EXP
Pushing (/usr/lib/perl5/site_perl/5.6.1/i686-linux, F, F) to @INC from SITEAR
CH_EXP
Pushing (/usr/lib/perl5/site_perl/5.6.1, F, F) to @INC from SITELIB_EXP
Pushing (/usr/lib/perl5/site_perl, F, T) to @INC from SITELIB_STEM
Pushing (/home/user/perl5lib/5.6.1/i686-linux, F, F) to @INC from PERL_VE
NDORARCH_EXP
Pushing (/home/user/perl5lib, F, F) to @INC from PERL_VENDORLIB_EXP
Pushing (/home/user/perl5lib, F, T) to @INC from PERL_VENDORLIB_STEM
Pushing (/usr/lib/perl5/site_perl:/usr/lib/perl5/site_perl/5.005:/usr/lib/per
l5/site_perl/5.005/i386-linux:/usr/lib/perl5/site_perl/5.6.0, T, T) to @INC f
rom PERL_OTHERLIBDIRS
Pushing (., F, F) to @INC from non-taint
/home/user/perl5lib/5.6.1/i686-linux
/home/user/perl5lib/5.6.1
/home/user/perl5lib
/usr/lib/perl5/5.6.1/i686-linux
/usr/lib/perl5/5.6.1
/usr/lib/perl5/site_perl/5.6.1/i686-linux
/usr/lib/perl5/site_perl/5.6.1
/usr/lib/perl5/site_perl/5.6.0
/usr/lib/perl5/site_perl/5.005
/usr/lib/perl5/site_perl
/home/user/perl5lib/5.6.1/i686-linux
/home/user/perl5lib
/home/user/perl5lib
/usr/lib/perl5/site_perl/5.6.0
/usr/lib/perl5/site_perl/5.005
/usr/lib/perl5/site_perl
/usr/lib/perl5/site_perl/5.005
/usr/lib/perl5/site_perl/5.005/i386-linux
/usr/lib/perl5/site_perl/5.6.0
There is a bit too many repeats in there for me to feel comfortable
'make install'ing this. The whole thing about which recurse and which
don't seems a bit under-documented, so I was looking for guidance. I
can puzzle it out on my own.
Elijah
------
and will probably have to
------------------------------
Date: Sat, 16 Jun 2001 00:37:28 +0100
From: "Leo Hemmings" <leapius@hotmail.com>
Subject: Re: Testing if a cookie has been set
Message-Id: <9ge66g$gn$1@uranium.btinternet.com>
Hi all,
I know this might have been gone through loads of times but I'm having
trouble detecting that a cookie has been set. My program is _not_ using
CGI.pm. A basic summary of the code is this:
# Set the cookie
print 'Set-Cookie: ' . "username" . '=' . $FORM{'username'} . ';';
print "\n";
print 'Set-Cookie: ' . "password" . '=' . $cryptedpassword . ';';
print "\n";
# Get the http header so we can test if the cookie has been set
print "Content-type: text/html\n\n";
# If the cookie has been set, redirect to the website
if ($ENV{'HTTP_COOKIE'}) { print "cookie set"; }
else { print "cookie not set"; }
This sets a cookie and then prints "\n\n" to send to http header and then
should pick up whether or not a cookie is received by seeing if
$ENV{'HHTP_COOKIE'} exists. Can anyone correct my code? What I need is to
set a cookie and test for it's existence in one go.
cheers,
Leo
------------------------------
Date: Fri, 15 Jun 2001 17:28:40 -0700
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Testing if a cookie has been set
Message-Id: <mbudash-A5FFCB.17284015062001@news.pacbell.net>
In article <9ge66g$gn$1@uranium.btinternet.com>, "Leo Hemmings"
<leapius@hotmail.com> wrote:
> Hi all,
>
> I know this might have been gone through loads of times but I'm having
> trouble detecting that a cookie has been set. My program is _not_ using
> CGI.pm. A basic summary of the code is this:
>
> # Set the cookie
> print 'Set-Cookie: ' . "username" . '=' . $FORM{'username'} . ';';
> print "\n";
> print 'Set-Cookie: ' . "password" . '=' . $cryptedpassword . ';';
> print "\n";
> # Get the http header so we can test if the cookie has been set
> print "Content-type: text/html\n\n";
> # If the cookie has been set, redirect to the website
> if ($ENV{'HTTP_COOKIE'}) { print "cookie set"; }
> else { print "cookie not set"; }
>
> This sets a cookie and then prints "\n\n" to send to http header and then
> should pick up whether or not a cookie is received by seeing if
> $ENV{'HHTP_COOKIE'} exists. Can anyone correct my code? What I need is to
> set a cookie and test for it's existence in one go.
your way won't work... you're misunderstanding how cookies work...
simply put, the Set-Cookie header is sent to a user agent (usually a
browser) 'asking' the agent to set a cookie. conversely, the next time a
user agent asks to get a document from a webserver in the same domain as
the one the cookie was set by, the agent sends a Cookie header along
with the request. note that there are two steps to this interchange, you
can't do it in one...
here's how i'm doing it in a cgi script for a recent project where the
specs say that a user must be notified if cookies are not enabled:
use CGI qw/:standard/;
# cookies must be enabled
unless (cookie('_COOKIES_ENABLED_')) {
if (param('_tc_')) {
$cookiemsg = qq|<p><font size="1">Please enable browser cookies
or you will not be able to order!</font>\n|;
}
else {
$cookieCookie = cookie(-name=>'_COOKIES_ENABLED_',
-value=>'yes',
-path=>'/');
print redirect(-location=>self_url() . '&_tc_=1',
-cookie=>$cookieCookie);
exit;
}
}
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Fri, 15 Jun 2001 17:32:52 -0700
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Testing if a cookie has been set
Message-Id: <mbudash-AEA718.17325215062001@news.pacbell.net>
oops.. a correction is embedded...
In article <mbudash-A5FFCB.17284015062001@news.pacbell.net>, Michael
Budash <mbudash@sonic.net> wrote:
> In article <9ge66g$gn$1@uranium.btinternet.com>, "Leo Hemmings"
> <leapius@hotmail.com> wrote:
>
> > Hi all,
> >
> > I know this might have been gone through loads of times but I'm having
> > trouble detecting that a cookie has been set. My program is _not_ using
> > CGI.pm. A basic summary of the code is this:
> >
> > # Set the cookie
> > print 'Set-Cookie: ' . "username" . '=' . $FORM{'username'} . ';';
> > print "\n";
> > print 'Set-Cookie: ' . "password" . '=' . $cryptedpassword . ';';
> > print "\n";
> > # Get the http header so we can test if the cookie has been set
> > print "Content-type: text/html\n\n";
> > # If the cookie has been set, redirect to the website
> > if ($ENV{'HTTP_COOKIE'}) { print "cookie set"; }
> > else { print "cookie not set"; }
> >
> > This sets a cookie and then prints "\n\n" to send to http header and
> > then
> > should pick up whether or not a cookie is received by seeing if
> > $ENV{'HHTP_COOKIE'} exists. Can anyone correct my code? What I need is
> > to
> > set a cookie and test for it's existence in one go.
>
> your way won't work... you're misunderstanding how cookies work...
> simply put, the Set-Cookie header is sent to a user agent (usually a
> browser) 'asking' the agent to set a cookie. conversely, the next time a
> user agent asks to get a document from a webserver in the same domain as
> the one the cookie was set by, the agent sends a Cookie header
containing the cookie data, of course
> along
> with the request. note that there are two steps to this interchange, you
> can't do it in one...
>
> here's how i'm doing it in a cgi script for a recent project where the
> specs say that a user must be notified if cookies are not enabled:
>
> use CGI qw/:standard/;
>
> # cookies must be enabled
> unless (cookie('_COOKIES_ENABLED_')) {
> if (param('_tc_')) {
> $cookiemsg = qq|<p><font size="1">Please enable browser cookies
> or you will not be able to order!</font>\n|;
> }
> else {
> $cookieCookie = cookie(-name=>'_COOKIES_ENABLED_',
> -value=>'yes',
> -path=>'/');
> print redirect(-location=>self_url() . '&_tc_=1',
> -cookie=>$cookieCookie);
> exit;
> }
> }
>
> hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Sat, 16 Jun 2001 02:25:28 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: Why is bare << deprecated ?
Message-Id: <slrn9ilhg7.5fl.tim@vegeta.ath.cx>
Kjetil Skotheim <kjetil.skotheim@usit.uio.no> wrote:
> Why is bare << deprecated?
> perl -we '$a=<<;'
perl -Mdiagnostics -we '$a=<<;'
can give you more information. I can't site the actual reason it's
deprecated, but it just _looks_ like a dangerous and ambiguous syntax.
You can still accomplish the same effect with '$a=<<"";'
HTH
--
-Tim Hammerquist <timmy@cpan.org>
M-x induce-carpal-tunnel-syndrome
-- Greg Bacon
------------------------------
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 1143
***************************************