[11661] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5260 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 30 18:03:57 1999

Date: Tue, 30 Mar 99 15:00:28 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 30 Mar 1999     Volume: 8 Number: 5260

Today's topics:
    Re: Can Anyone Help With a Layered Variable Substitutio (Tad McClellan)
    Re: CGI Script <camerond@mail.uca.edu>
    Re: Change data of file (Tad McClellan)
    Re: changing to numeric month (Larry Rosler)
    Re: changing to numeric month (Charles DeRykus)
    Re: changing to numeric month <uri@home.sysarch.com>
        Comment controls <cantrela@agcs.com>
    Re: Comment controls (Tad McClellan)
    Re: Control C's still a problem! (Charles DeRykus)
    Re: Database utilisation in web site design <greg2@surfaid.org>
        Download through cgi script (Christopher Parent)
    Re: foreach loop works, for loop not <gellyfish@gellyfish.com>
    Re: FTP automation w/o module (Christian M. Aranda)
    Re: Graphics in Perl <gellyfish@gellyfish.com>
        Help! <fuchin@mail.nwos.lucent.com>
        How to Check to see if a cookie was written before exit <tag@io.com>
    Re: How to Check to see if a cookie was written before  <gregm@well.com>
    Re: How to create NT service in Perl? <gellyfish@gellyfish.com>
    Re: How to create NT service in Perl? <doug@mcbride.net>
    Re: how to find local system IP address in Perl (Greg Bacon)
    Re: how to find local system IP address in Perl <mtsprd@carol.net>
    Re: how to find local system IP address in Perl <mtsprd@carol.net>
    Re: how to find local system IP address in Perl (Greg Bacon)
        including perl scripts in Server Side Includes (SHTML) <larsplessmann@gmx.de>
    Re: including perl scripts in Server Side Includes (SHT <grichard@uci.edu>
    Re: Internal Timer <gellyfish@gellyfish.com>
        LWP..to use or not? <horizon@internetexpress.com.au>
    Re: Newbie: How to debug Perl CGI script on server <gellyfish@gellyfish.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Tue, 30 Mar 1999 11:01:15 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Can Anyone Help With a Layered Variable Substitution Problem Please
Message-Id: <bgsqd7.lo.ln@magna.metronet.com>

Neville Jennings (nj2@soton.ac.uk) wrote:

: When I print out the "line" I want to be able to substitute in the values of
: e.g. $value_expireday rather than have it just write out $value_expireday


   The Perl FAQ explains how to do that.


: This means that I somehow have to evaluate the same line twice, once to get
: the string containing $value_expireday from the $line variable, then again
: to further substitute in the value of this variable.


   Right.

   That is how the Perl FAQ suggests.


: Can anyone help ? 


   You can help yourself.

   Look for your question in the FAQ before posting it yet again.

   Perl FAQ, part 4:

     "How can I expand variables in text strings?"


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 30 Mar 1999 15:35:27 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
To: Solder182 <solder182@aol.com>
Subject: Re: CGI Script
Message-Id: <3701439F.6756A188@mail.uca.edu>

[cc'd to de]

Solder182 wrote:
> 
> I am looking for someone that will, in there free time, install a script for me
> or teach me how to do it. Please contact me Later

The foremost gurus of the perl language will be glad to teach yu how to
do it, but if you want them to teach you in their "free time" you will
have to buy their book. It's called "Learning Perl" and is available for
a very nominal proce from O'Reilly and Assoc., found in better
bookstores everywhere. Now, if you wanted a CGI script, the author of
CGI.pm will be glad to do the same, as he has provided "The Official
Guide to CGI.pm," pub. by Wiley. These books, along with the
explanations in the PODs and examples provided will teach you everything
you wanted to know (at least all you could eat in one long sitting) and
would be FAR more helpful than someone sitting over your shoulder. If
you REALLY believe that "Knowledge is Power," you'll take this tack. If
not, YGWYPF.

Cameron
camerond@mail.uca.edu


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

Date: Tue, 30 Mar 1999 10:57:19 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Change data of file
Message-Id: <v8sqd7.lo.ln@magna.metronet.com>

Alex (ex5316@netvigator.com) wrote:

: After I open the file, then change the data. How can I save the new data
: to the file ?


   By looking up your Frequently Asked Question instead of
   asking it for the bazillionth time.

   Perl FAQ, part 5:

      "How do I change one line in a file/
       delete a line in a file/
       insert a line in the middle of a file/
       append to the beginning of a file?"


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 30 Mar 1999 13:42:41 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: changing to numeric month
Message-Id: <MPG.116ae52a661e44d39897f1@nntp.hpl.hp.com>

In article <x7r9q6wvj5.fsf@home.sysarch.com> on 30 Mar 1999 15:51:42 -
0500, Uri Guttman <uri@home.sysarch.com> says...
> >>>>> "JS" == John Stanley <stanley@skyking.OCE.ORST.EDU> writes:
>   JS> In article <37021c27.10918169@news.bmc.com>,
>   JS> Christian M. Aranda <christianarandaOUT@OUTyahoo.com> wrote:
>   >> I wrote a small function which changes the written month (Jan Feb Mar,
>   >> etc.) to it's corresponding number (1 2 3, etc...
 ...
>   JS> %months = qw(Jan 0 Feb 1 Mar 2 Apr 3 May 4 Jun 5 Jul 6 Aug 7 Sep 8 Oct 9
>   JS> Nov 10 Dec 11);
> 
> ugly init!
> 
> hash slices to the rescue!
> 
> @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
> 
> @month2num{ @months } = 0 .. $#months ;

Indeed, that is a cleaner and somewhat faster initialization.  But the 
initialization of the hash overwhelms the time for the lookup.  Unless 
the lookup is taking place lots of times and the initialization is done 
once only, the simple 'index' solution that I posted it a clear winner.  


#!/usr/local/bin/perl -w
use Benchmark;

@months{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)} = 0 .. 11;
$months = 'JanFebMarAprMayJunJulAugSepOctNovDec';

timethese(1 << (shift || 0), {
  Hash1  => sub { $months{$_[0]} },
  Hash2  => sub { my %months =
                    qw(Jan 0 Feb 1 Mar 2 Apr 3 May 4  Jun 5
                       Jul 6 Aug 7 Sep 8 Oct 9 Nov 10 Dec 11);
                  $months{$_[0]} },
  Hash3  => sub { my %months;
                  @months{qw(Jan Feb Mar Apr May Jun
                             Jul Aug Sep Oct Nov Dec)} = 0 .. 11;
                  $months{$_[0]} },
  Index1 => sub { index($months, 'Jan')/3 },
  Index2 => sub { index($months, 'Dec')/3 },
  Index3 => sub { index($months, 'foo')/3 },
});
__END__

Benchmark: timing 131072 iterations of Hash1, Hash2, Hash3, Index
x3...
     Hash1:  1 wallclock secs ( 0.78 usr +  0.00 sys =  0.78 CPU)
     Hash2: 21 wallclock secs (21.61 usr +  0.00 sys = 21.61 CPU)
     Hash3: 18 wallclock secs (17.00 usr +  0.00 sys = 17.00 CPU)
    Index1:  1 wallclock secs ( 0.95 usr +  0.00 sys =  0.95 CPU)
    Index2:  0 wallclock secs ( 1.06 usr +  0.00 sys =  1.06 CPU)
    Index3:  0 wallclock secs ( 1.06 usr +  0.00 sys =  1.06 CPU)

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 30 Mar 1999 20:20:04 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: changing to numeric month
Message-Id: <F9FCHG.6r8@news.boeing.com>

In article <37021c27.10918169@news.bmc.com>,
Christian M. Aranda <christianarandaOUT@OUTyahoo.com> wrote:
>I wrote a small function which changes the written month (Jan Feb Mar,
>etc.) to it's corresponding number (1 2 3, etc.).  Here is the
>function:
>
>$gmonth = "Dec";
>@months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
>
>for ($x = 0; $x < @months; $x++) {
>   if ($gmonth eq $months[$x]) {
>      $monthnum = $x + 1;
>      last;
>   }
>}
>
>print "month number is $monthnum\n";
>
>I am looking to improve this code because there must be a better way
>to do this (perhaps a foreach, but I'm not sure how to go about it).
>Commence the shredding!!  All suggestions are appreciated!
>

perhaps just:

@month2num{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)} = 1..12; 

print "month number is $month2num{$gmonth}\n";   


hth,
--
Charles DeRykus


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

Date: 30 Mar 1999 17:59:51 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: changing to numeric month
Message-Id: <x7oglawplk.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> In article <x7r9q6wvj5.fsf@home.sysarch.com> on 30 Mar 1999 15:51:42 -
  LR> 0500, Uri Guttman <uri@home.sysarch.com> says...

  >> hash slices to the rescue!
  >> 
  >> @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
  >> 
  >> @month2num{ @months } = 0 .. $#months ;

  LR> Indeed, that is a cleaner and somewhat faster initialization.  But the 
  LR> initialization of the hash overwhelms the time for the lookup.  Unless 
  LR> the lookup is taking place lots of times and the initialization is done 
  LR> once only, the simple 'index' solution that I posted it a clear winner.  

true. the original poster never mentioned the need for speed. he was
stumped on how to do it in general. also the hash idea is good to
promote as it handle variable length strings, dynamically created arrays
(that could be done with the index too), 


where is $_[0] coming from in the hash subs? i don't see any real month
names being passed around there.

also try using a list of '' month names for the init. i think it would
be a lot faster than the runtime call of split used by qw. (that is
changed to a compile time call of split in some new version or perl).
also you should test the failure mode of the hashes (unless $_[0] WAS
failure mode).

  LR> timethese(1 << (shift || 0), {
  LR>   Hash1  => sub { $months{$_[0]} },
  LR>   Hash2  => sub { my %months =
  LR>                     qw(Jan 0 Feb 1 Mar 2 Apr 3 May 4  Jun 5
  LR>                        Jul 6 Aug 7 Sep 8 Oct 9 Nov 10 Dec 11);
  LR>                   $months{$_[0]} },
  LR>   Hash3  => sub { my %months;
  LR>                   @months{qw(Jan Feb Mar Apr May Jun
  LR>                              Jul Aug Sep Oct Nov Dec)} = 0 .. 11;
  LR>                   $months{$_[0]} },

  LR> Benchmark: timing 131072 iterations of Hash1, Hash2, Hash3, Index
  LR> x3...
  LR>      Hash1:  1 wallclock secs ( 0.78 usr +  0.00 sys =  0.78 CPU)
  LR>     Index1:  1 wallclock secs ( 0.95 usr +  0.00 sys =  0.95 CPU)
  LR>     Index2:  0 wallclock secs ( 1.06 usr +  0.00 sys =  1.06 CPU)
  LR>     Index3:  0 wallclock secs ( 1.06 usr +  0.00 sys =  1.06 CPU)

interesting that a plain hash is still faster than a short index and
/. i bet the / kills the time for index as it takes 2 perl ops while a
hash is one.


uri


-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Tue, 30 Mar 1999 14:18:40 -0700
From: Andy Cantrell <cantrela@agcs.com>
Subject: Comment controls
Message-Id: <37013FB0.2E9B279F@agcs.com>

Came across the following.  Not sure if this is
a desired effect or what.  Looking around to see
what others have to say.

Say I have a syntax error in a script.  Perl give
an error message to the effect of:

 "Scalar found where operator expected at /home/cantrela/t.pl line 50"

Now consider the following comment line:
   # line 1 bla bla bla
If this comment line shows up in the code prior to the error
example given above, the text of the error message changes
to reflect the number of lines X from that comment.  For grins
I tried the comment line:
   # line 20 bla bla bla
and sure enough the error message now drifted to indicate the
error was at line 20+X.

This example code will indicate an error in line 51.
#!/usr/local/bin/perl
# line 50
$str = 'error line, no semicolan'
print "$str\n";


I haven't poured over the camel book looking for this.
The index has a few things to say about #'s but I guess
they didn't hit the right note with me and so I turned
here.  Any feedback?

-- 
Andy Cantrell
AG Communication Systems
E-Mail: cantrela@agcs.com
Office (AZ) (602) 582-7495 (Voice mail)
Office (WI) (414) 249-0215
Modem  (WI) (414) 249-0239


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

Date: Tue, 30 Mar 1999 10:51:53 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Comment controls
Message-Id: <purqd7.lo.ln@magna.metronet.com>

Andy Cantrell (cantrela@agcs.com) wrote:
: Came across the following.  Not sure if this is
: a desired effect or what. 


   Not "or what".  :-)


: Say I have a syntax error in a script.  Perl give
: an error message to the effect of:

:  "Scalar found where operator expected at /home/cantrela/t.pl line 50"

: I tried the comment line:
:    # line 20 bla bla bla
     ^^^^^^
     ^^^^^^
: and sure enough the error message now drifted to indicate the
: error was at line 20+X.


: I haven't poured over the camel book looking for this.


   Well that's OK, since books are a fourth level resource anyway,
   and it is covered in the Standard Docs (perlsyn.pod), which
   are the first level authority on all things Perl.

   Perhaps not blindingly obvious where it is though. I could not
   remember.

   grepping for the underlined part of your code found it handily
   enough though:

---------------------
=head2 Plain Old Comments (Not!)

Much like the C preprocessor, Perl can process line directives.  Using
this, one can control Perl's idea of filenames and line numbers in
error or warning messages
 ...
---------------------


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Tue, 30 Mar 1999 20:02:25 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Control C's still a problem!
Message-Id: <F9FBo1.5vC@news.boeing.com>

In article <3700BAB6.C41798C0@internetexpress.com.au>,
Mick  <horizon@internetexpress.com.au> wrote:
>Hi...
>I cannot seem to catch a ^C (control c), while my program is executing.
>As you can see (From the code), I've read the FAQ on it, but can't get
>it to work!
>What I wanted to do was, while waiting for user input from STDIN, if a
>control-C or control-Z is pressed, this is ignored, so the user cannot
>exit from the program.
>Code simplified -
>
>#Get all signal names
>
>use Config;
>
>    defined $Config{sig_name} || die "No sigs?";
>
>    foreach $name (split(' ', $Config{sig_name})) {
>
>        $signo{$name} = $i;
>
>        $signame[$i] = $name;
>
>        $i++;
>
>    }
>
>print STDOUT "Please enter text: ";
>while($month=<STDIN>){
> $SIG{INT} = \&catch_zap;
>}
>
>sub catch_zap {
>
>        my $signame = shift;
>
>        $shucks++;
>
>        die "Somebody sent me a SIG$signame";
>
>    }
>

If you don't need to do anything with the signal, you
could simply ignore them: 

{
  local $SIG{INT} = local $SIG{TSTP} = 'IGNORE';
  while ($month = <STDIN>) { 
     ...
  }
}

hth,
--
Charles DeRykus


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

Date: Tue, 30 Mar 1999 23:49:08 +0100
From: Greg Griffiths <greg2@surfaid.org>
To: liu singloon <sing.loon@uq.net.au>
Subject: Re: Database utilisation in web site design
Message-Id: <370154E4.B5252696@surfaid.org>

I too would go with msql ,which is a very good little database, although
if they are providing you wiht MS extensions then perhaps a quick look
at Active Server Pages, as you are not very experienced, judging from
your posting then using a lot of Perl or Python to interact with a DB is
probably a bit too much, I suggest that you investigate the ASP roiute
first and then the mSQL, and also talk to your ISP and see what help
they can be.

liu singloon wrote:
> 
> Hi need some info and advice on the following,
> 
> I have recently signed up with a paid web hosting provide and registered my
> own domain name.
> 
> My web host package supports the following:
> 
> SSI, Server Side Support for Java, PERL 4, 5, 5.003, 5.004, C++, TCL, and
> Python, IMAP4 and Procmail. mySQL 2.0.3 AND 3.22
> 
> and
> 
> Support For MS Frontpage 97 and 98 Extensions and HTML Script Applets and
> Miva Mia ?.
> 
> What I want to do is be able to easily update my entertainment web sites
> movie release dates listing and to generate a html file which I have
> designed around my web site layout etc.  It can be generated offline and I
> can upload it or can be done on the fly.
> 
> The site will be divided among 2 -7 countries = each with categories listed
> by month from Jan - Dec - showing release dates for that country.
> 
> I have no experience with databases - apart from my 1 single uni subject on
> Access 2 which I have little memory of.
> 
> My current set of design tools are,
> 
> Dreamweaver 1.2/2, Homesite 3/4, Adobe Pagemaker, Adobe Photoshop 4.01,
> Fireworks 1, Flash 3, GIF Movie Gear 2.6, MS GIF Animator and WS_FTP LE and
> Pro 6.
> 
> Does anyone know of some programs that will allow me to
> 
> 1. Create an easy to use database ? - I have Access 7 but don't know much
> about it.
> 2. Generate custom designed html files for database data on movie release
> dates ?
> 
> I tried Drumbeat 2000 evaluation but it crashes my pc and stalls ....
> 
> Thanks, my current web site is below, but will be moving to the new paid web
> host hopefully by the end of the month or middle of next month.
> 
> --
> George Liu
> 
> =====================================
> http://georges-place.webjump.com/
> - Australian/US/HK movie release dates
> - Oscars, Movies, Trailers & Info  for  1999
> - Oscars Winners List
> =====================================


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

Date: Tue, 30 Mar 1999 22:57:55 GMT
From: parenc@rpi.edu (Christopher Parent)
Subject: Download through cgi script
Message-Id: <370156d4.154581842@usenet.rpi.edu>

I have 2 simple questions.

First. How can I send a file to a client through a CGI script?

Second. I want to delete the file as soon as it's downloaded. How can
I acknowledge the file has been downloaded, and then delete it?


Thanks
Chris


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

Date: 30 Mar 1999 21:33:38 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: foreach loop works, for loop not
Message-Id: <7drfvi$f4$1@gellyfish.btinternet.com>

On 30 Mar 1999 19:15:43 GMT David Efflandt wrote:
> 
> Anyone know why this hangs after the first iteration?  Subroutine is being
> executed once, but then something hangs and the second $url never prints:
>     
> for ($i=1; $i<=3; $i++) {
>     $url = 'http://192.168.1.' . $i;
>     print "$url\n";
>     &wwwtest($url);
> )
>     

Without the subroutine call it works fine for me :

gellyfish@gellyfish:/home/gellyfish/clpmtest > perl ftest.pl
http://192.168.1.1
http://192.168.1.2
http://192.168.1.3

I guess that something wierd is happening in your subroutine.

BTW your loop can also be written as:

for $i ( 1 ... 3 )
  {
    # blah
   }

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Tue, 30 Mar 1999 22:48:03 GMT
From: christianarandaOUT@OUTyahoo.com (Christian M. Aranda)
Subject: Re: FTP automation w/o module
Message-Id: <37035421.25248104@news.bmc.com>

On Tue, 30 Mar 1999 18:02:52 GMT, christianarandaOUT@OUTyahoo.com
(Christian M. Aranda) wrote:

>
>My other thought is to do something like:
>(sorry.. it's off the top of my head)
>
>`ftp $host <<ENDFTP
>   user $name $pass
>   prompt off
>..
>..
>..
>ENDFTP`

Here is my attempt at this:

print <<`FTP`;
/usr/bin/ftp -ni aix7
user john password
cd catest
put myfile.txt
quit
FTP

this sucker just hangs when I run it.  ps tells me that
ftp is running.  When I copy and paste the exact text
into ftp manually it works.  I've changed the `FTP` to
'FTP' and inserted echo in front of each line.  what
comes out looks correct.  In short, I'm stumped (and
frustrated)!

TIA -

Christian

>
>
>All suggestions are welcome and appreciated!
>
>Christian M. Aranda



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

Date: 30 Mar 1999 21:07:44 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Graphics in Perl
Message-Id: <7dref0$dv$1@gellyfish.btinternet.com>

On Mon, 29 Mar 1999 23:03:40 GMT link@ipass.net wrote:
> I believe someone asked earlier if there was a way to draw pixels in Perl. 

There are the modules

GD
Image::Magick

Available from CPAN that will create graphic image files.

Alternatively you can use Tk::* or X11::* modules etc to render directly
to a screen or window I guess. There might be some facility via Win32::GUI
perhaps but I wouldnt want to comment on that.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Tue, 30 Mar 1999 17:47:12 -0500
From: Fu Chin Liu <fuchin@mail.nwos.lucent.com>
Subject: Help!
Message-Id: <37015470.AC836BC8@mail.nwos.lucent.com>

Does anyone know how to set uid in Perl?
e.g. How can I set the user id to root while the perl process is ran by
other uid and get the permission to change the permission of the files
which are owned by root.
Then uid can be changed back to continue running the rest of the script?

Thanks



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

Date: Tue, 30 Mar 1999 15:36:59 -0500
From: "Todd A. Guillory" <tag@io.com>
Subject: How to Check to see if a cookie was written before exiting th escript
Message-Id: <370135E9.A083E7F7@io.com>

I want to make sure a user has Cookies enabled.  I thought I could set a
cookie and then check to make sure it exist, but that doesn't work,
since the cookie doesn't exist until the PERL script that set it has exited.

I tried using the eval() function on the line that set the cookie. 
Didn't work.

Here's my code

use CGI;

if ( $q->param('poll') eq 'total' )
  {
  print "Content-type:text/html\n\n";
  $Out_Msg = "Here are the results of the poll so far.";
  %Data = &get_results();
  }
elsif ( cookie($Cookie) )
  {
  print "Content-type:text/html\n\n";
  $Out_Msg = "No ballot stuffing allowed! You've already voted for " .
cookie($Cookie) . ".";
  %Data = &get_results();
  }
else
  {
  &set_cookie();
  if ( cookie($Cookie) )
    {
    $Out_Msg = "Thanks for voting for!";
    %Data = &update_results();
    }
  else
    {
    $Out_Msg = "You need cookies to participate in the poll.";
    %Data = &get_results();
    }
  }

the part that's failing is the inner if.

else
  {
  &set_cookie();
  if ( cookie($Cookie) )
    {
    $Out_Msg = "Thanks for voting for!";
    %Data = &update_results();
    }
  else
    {
    $Out_Msg = "You need cookies to participate in the poll.";
    %Data = &get_results();
    }

&set_cookie() creates the cookie, but because my code is still running,
the if ( cookie($Cookie) ) will evaluate to false

here's the set_cookie() function

sub set_cookie
  {
  my $cookie;
  
  $cookie = cookie(-name=>$Cookie, -value=>$q->param('poll'), -expires=>$Expire);
  print header(-cookie=>[$cookie]); 
  return;
  }

Is there another way to check to see if a cookie got set so that people
can't bypass it by simply refusing to accept the cookie???

Thanks!

-- 
**********************************************************************
* Todd A. Guillory                         * home      281/461-0378  *
* Web Assistant                            * work      713/743-1514  *
* Electrical & Computer Engineering (PB)   * pager/VM  713/318-6057  *
* Information Technology                   * tag@io.com              *
* Information Services                     * http://www.io.com/~tag/ *
* The University of Houston                * AOL IM: taguillory      *
**********************************************************************


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

Date: Tue, 30 Mar 1999 14:06:52 -0800
From: Greg McCann <gregm@well.com>
To: tag@io.com
Subject: Re: How to Check to see if a cookie was written before exiting th escript
Message-Id: <37014AFC.1F1567AB@well.com>

I don't know how to do it in Perl, but here is something in JavaScript from
http://www.citibank.com...

function hasCookies() {
        SetCookie("_tst","Y");
        var tst = GetCookie("_tst");
        DeleteCookie("_tst");
        if (tst == "Y")
                return 1;
        return 0;
}



Todd A. Guillory wrote:

> I want to make sure a user has Cookies enabled.  I thought I could set a
> cookie and then check to make sure it exist, but that doesn't work,
> since the cookie doesn't exist until the PERL script that set it has exited.
>
> I tried using the eval() function on the line that set the cookie.
> Didn't work.
>
> Here's my code
>
> use CGI;
>
> if ( $q->param('poll') eq 'total' )
>   {
>   print "Content-type:text/html\n\n";
>   $Out_Msg = "Here are the results of the poll so far.";
>   %Data = &get_results();
>   }
> elsif ( cookie($Cookie) )
>   {
>   print "Content-type:text/html\n\n";
>   $Out_Msg = "No ballot stuffing allowed! You've already voted for " .
> cookie($Cookie) . ".";
>   %Data = &get_results();
>   }
> else
>   {
>   &set_cookie();
>   if ( cookie($Cookie) )
>     {
>     $Out_Msg = "Thanks for voting for!";
>     %Data = &update_results();
>     }
>   else
>     {
>     $Out_Msg = "You need cookies to participate in the poll.";
>     %Data = &get_results();
>     }
>   }
>
> the part that's failing is the inner if.
>
> else
>   {
>   &set_cookie();
>   if ( cookie($Cookie) )
>     {
>     $Out_Msg = "Thanks for voting for!";
>     %Data = &update_results();
>     }
>   else
>     {
>     $Out_Msg = "You need cookies to participate in the poll.";
>     %Data = &get_results();
>     }
>
> &set_cookie() creates the cookie, but because my code is still running,
> the if ( cookie($Cookie) ) will evaluate to false
>
> here's the set_cookie() function
>
> sub set_cookie
>   {
>   my $cookie;
>
>   $cookie = cookie(-name=>$Cookie, -value=>$q->param('poll'), -expires=>$Expire);
>   print header(-cookie=>[$cookie]);
>   return;
>   }
>
> Is there another way to check to see if a cookie got set so that people
> can't bypass it by simply refusing to accept the cookie???
>
> Thanks!
>
> --
> **********************************************************************
> * Todd A. Guillory                         * home      281/461-0378  *
> * Web Assistant                            * work      713/743-1514  *
> * Electrical & Computer Engineering (PB)   * pager/VM  713/318-6057  *
> * Information Technology                   * tag@io.com              *
> * Information Services                     * http://www.io.com/~tag/ *
> * The University of Houston                * AOL IM: taguillory      *
> **********************************************************************



--

======================
Gregory McCann
http://www.calypteanna.com

"Be kind, for everyone you meet is fighting a great battle."  Saint Philo of
Alexandria




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

Date: 30 Mar 1999 20:58:42 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How to create NT service in Perl?
Message-Id: <7drdu2$cs$1@gellyfish.btinternet.com>

On Mon, 29 Mar 1999 13:43:00 -0800 Doug McBride wrote:
> 
> I see that the Win32::Service module lets me control services, but how
> do I create a new service?  I think there's a Win32 API call to do this,
> but has it been exported to Perl already?

A quick search of this group on DejaNews for Win32 Service will give you
the solution - someone posted a very complete solution a couple of months
back.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Tue, 30 Mar 1999 13:35:55 -0800
From: Doug McBride <doug@mcbride.net>
To: Chuck Hirstius <chirstius@mediaone.net>
Subject: Re: How to create NT service in Perl?
Message-Id: <370143BB.2259A097@mcbride.net>

Thanks for the detailed info, but I'm not trying to make a Perl script
_run_ as a service.  I'm trying to make a Perl script _create_ a
service.  I'm writing an installation script in Perl that needs to make
another (non-perl) program into a service.  I suppose I could just have
the Perl script run this srvany.exe program and then modify the
registry, but I thought someone might have incorporated this
functionality into a module I could use.

Thanks again for your time!

Chuck Hirstius wrote:
> 
> You need the NT server Resource kit.  On it you will find srvany.exe, and
> instsrv.exe,  these are your ticket to making anything an NT service.  If
> you look at the notes on the NT CD it explains in detail how to install an
> app as a service.  Basically:
> [...]

-- 
Doug McBride - doug@mcbride.net - n|c - http://www.nc.com - 650.631.5268


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

Date: 30 Mar 1999 21:32:01 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: how to find local system IP address in Perl
Message-Id: <7drfsh$7o3$1@info2.uah.edu>

In article <922825471.502.45@news.remarq.com>,
	"Ken Bauman" <mtsprd@carol.net> writes:
: This is probably only marginally a Perl question.  How can you find
: your own machine's IP address in a Perl script?

This is a FAQ.  Please consult Section 9 of the Perl FAQ.

Greg
-- 
In a literary light, if UNIX is the Great Novel, Perl is the Cliffs Notes.
    -- Thomas Scoville


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

Date: Tue, 30 Mar 1999 16:56:52 -0500
From: "Ken Bauman" <mtsprd@carol.net>
Subject: Re: how to find local system IP address in Perl
Message-Id: <yObM2.389$H5.17025@news3.ispnews.com>

Greg Bacon wrote in message <7drfsh$7o3$1@info2.uah.edu>...
>This is a FAQ.  Please consult Section 9 of the Perl FAQ.


Thanks for the tip 8-) ... but ... FAQ 9 says to use modules Socket,
Sys::Hostname and the functions hostname(), gethostbyname(), etc.  As I
stated in my original message, I already tried those.  Actually, hostname()
did return a name, because I happen to be running M$ Personal Web Server (I
don't have a lot of choice right now), but gethostbyname() fails.  I assume
it fails because my web server name isn't registered with any DNS, or
something like that.

My expectation is that there should be a way to get the IP address of a
local machine, even if it is not running any "host" services.  Incidentally,
the IP addresses are assigned by DHCP on the systems on which I want to run
the script.

Ken Bauman




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

Date: Tue, 30 Mar 1999 17:04:57 -0500
From: "Ken Bauman" <mtsprd@carol.net>
Subject: Re: how to find local system IP address in Perl
Message-Id: <6WbM2.391$H5.17211@news3.ispnews.com>

I should probably add that I am running ActivePerl
on a Win95 machine.  I am running Micro$oft
Personal Web Server also, however, that should be
irrelevant.  The script I am attempting to write
is NOT a CGI script and is NOT being run by the
server.  I believe I should be able to get the IP
address of the local machine, regardless of
whether I am running a web server of any type.
Someone please tell me I'm not wrong!!  :)

Ken Bauman




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

Date: 30 Mar 1999 22:35:42 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: how to find local system IP address in Perl
Message-Id: <7drjju$8gk$1@info2.uah.edu>

In article <6WbM2.391$H5.17211@news3.ispnews.com>,
	"Ken Bauman" <mtsprd@carol.net> writes:
: I believe I should be able to get the IP
: address of the local machine, regardless of
: whether I am running a web server of any type.

I share this believe as do the writers of decent operating systems. :-)
Did you try getting your nodename from POSIX::uname?

Greg
-- 
Cop:     McManus told us another story altogether.
Fenster: Is that the one about the hooker with dysentery?


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

Date: 30 Mar 1999 21:50:16 GMT
From: Lars Plessmann <larsplessmann@gmx.de>
Subject: including perl scripts in Server Side Includes (SHTML)
Message-Id: <370147F4.93DDA5A4@gmx.de>

How can I include perlscripts with the #include tag to a shtml file?
That is right, isn't it?

     <!--include file="file.pl"-->

When I include it in windows ist works. But in Linux there happens
nothing. Even on a webserver in the internet it doesn't work (there even
is an error message)!
What have I done wrong?
Please help me, it's very important!
Thx,

     Lars



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

Date: Tue, 30 Mar 1999 14:44:49 -0800
From: "Gabriel Richards" <grichard@uci.edu>
Subject: Re: including perl scripts in Server Side Includes (SHTML)
Message-Id: <7drjv9$1vd@news.service.uci.edu>


Lars Plessmann <larsplessmann@gmx.de> wrote in message
news:370147F4.93DDA5A4@gmx.de...
> How can I include perlscripts with the #include tag to a shtml file?
> That is right, isn't it?
>
>      <!--include file="file.pl"-->

You must ensure that the following line exists in .htaccess (wherever your
other login files are located probably):

AddType text/x-server-parsed-html .shtml

Maybe that's your trouble? Hope it helps.

Gabe




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

Date: 30 Mar 1999 21:25:24 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Internal Timer
Message-Id: <7drfg4$ep$1@gellyfish.btinternet.com>

On Tue, 30 Mar 1999 21:53:24 -0800 Alvin Yong wrote:
> Hi,
>    I need some urgent help in perl...I wonder if I cld use an internal timer
> function or code one so I can execute my main program every 5 mins, do I
> have resort to writing a very large loop or do I have to use an external
> scheduler program to automate that.....

You could use alarm() but I seem to recall that it doesnt work on Win32.
You could use the atrocious NT 'at' I suppose.

>                                           also can I open a connection to a
> Unix server and execute unix commands on it while my program sits on an NT
> server...I need help pls !!!
> 

You can you use Net::Telnet or Net::Rexec or similar to do this.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Wed, 31 Mar 1999 08:32:53 +1000
From: Mick <horizon@internetexpress.com.au>
Subject: LWP..to use or not?
Message-Id: <37015115.A099CE19@internetexpress.com.au>

Hi...
I need to be able to fetch multiple data files from remote locations.
The data files are processed as the script runs.
I've had a look at LWP, but am not sure if this is the correct method
to use?
Say remote address http://127.0.0.1/datafiles/ contains 30 data files
I need to process, but I only want to parse the data files with a
particular extension -
No problems if local
@data_files = grep { /\.data$/ } readdir(DIR);
closedir(DIR);

But how do I go about this with remotely located files?
Can I parse each one like I normally can with local files -?

foreach(@data_files){

      print "Parsing file $_";
     open(INFILE, "$path\\" . $_) or die "$path - Couldn't open file $_:
$!\n";
     @lines = <INFILE>;
     close(INFILE);
}

Hope someone can help!!
Thanks in advance,
Mick

--




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

Date: 30 Mar 1999 20:50:34 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Newbie: How to debug Perl CGI script on server
Message-Id: <7drdeq$cp$1@gellyfish.btinternet.com>

On Tue, 30 Mar 1999 00:26:49 GMT nawkboy@yahoo.com wrote:
> In article <7bpch9$akd@bgtnsc01.worldnet.att.net>,
>   "JR Noorda" <jrnoorda@worldnet.att.net> wrote:
>>
<snip>
>> I have modified the first statement of the Perl script:
>> #!/usr/local/bin/perl -dT
>>
<snip>
>> This looks like the output of a debugger.   How does one get it redirected
>> to a terminal
>> on the server??
>>
> 
> Does anyone know the answer to this question?  Has the author figured it out
> yet?
>>

The author of the perldebug manpage knows.  I guess the original poster
probably figured that out.

I would guess that his problem was probably caused because he put his
 .perldb in some other directory than the home directory of the user that
ran his CGI program.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5260
**************************************

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