[19308] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1503 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 12 18:06:29 2001

Date: Sun, 12 Aug 2001 15:05:09 -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: <997653908-v10-i1503@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 12 Aug 2001     Volume: 10 Number: 1503

Today's topics:
    Re: Accessing a widget when defined local to a sub <bkennedy99@Home.com>
        confused - can't print to file <dcsnospam@ntlworld.com>
    Re: confused - can't print to file <dcsnospam@ntlworld.com>
    Re: confused - can't print to file <krahnj@acm.org>
    Re: cvs and perl-modules <bkennedy99@Home.com>
        FAQ: How can I translate tildes (~) in a filename? <faq@denver.pm.org>
    Re: Need help with error trying to use string as ARRAY  <shutupsteve@awdang.no.thanks.com>
    Re: Need help with error trying to use string as ARRAY  <hinson@home.com>
        Newbie <jayne.heger@ntlworld.com>
    Re: Newbie <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Perl -w and -W flags (Tad McClellan)
        Perl with CGI with Cookies... HELP! <jerseycat10@yahoo.com>
    Re: Perl with CGI with Cookies... HELP! <ilya@martynov.org>
    Re: Perl with CGI with Cookies... HELP! <jerseycat10@yahoo.com>
    Re: Perl with CGI with Cookies... HELP! <ilya@martynov.org>
    Re: Perl with CGI with Cookies... HELP! <jerseycat10@yahoo.com>
    Re: Regular expression to take HTML comments out?? <gnarinn@hotmail.com>
    Re: searching files from linux to Internet (David Efflandt)
    Re: searching files from linux to Internet (brian)
    Re: searching files from linux to Internet <gnarinn@hotmail.com>
        Statement modifiers?? <miscellaneousemail@yahoo.com>
    Re: Statement modifiers?? <tinamue@zedat.fu-berlin.de>
    Re: Using the Term::ANSIColor <murat.uenalan@gmx.de>
    Re: voodoo cookie hash problem (Mongo)
    Re: Warning  pragma -w (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 12 Aug 2001 18:39:49 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Accessing a widget when defined local to a sub
Message-Id: <V3Ad7.96677$EP6.24157059@news1.rdc2.pa.home.com>

"Peter Mann" <Pcmann1@btinternet.com> wrote in message
news:9l6g85$a0g$1@uranium.btinternet.com...
> Dear All,
> In the following example, 'my' is used to keep combo1 local to the sub
> 'donotebook', because otherwise I get errors when using 'strict', such as:
>
>            "Global symbol "$combo1" requires explicit package name at
nb4.pl
> line 48."
>
> But then, since its local to 'denotebook' how can I access it from the
other
> sub 'fillCombo'?
>
> I wanted to avoid moving all items from denotebook out of the function and
> global because in my full version, I have more pages in the notebook, and
> hence it would get messy.

Theres about a million ways to do this in Tk, but one nice technique is to
create an anonymous subroutine within the donotebook() sub, e.g.

sub donotebook {
    # construct stuff
    my $combo1 = ... # create the combo box widget

    my $insert_combo = sub {
        my($text) = @_;
        $combo1->insert('end', $text);
    }; # don't forget the ; !

    # now you have a sub that inserts text into the combo box
    # note it could be expanded to take an array of parameters, etc

    $insert_combo->('one');
    $insert_combo->('two);
    $insert_combo->('three');

    return $insert_combo; # donotebook is now a closure
}

Now that returned ref can be used anywhere:

my $combo_inserter = donotebook();
$combo_inserter->("four");

Its nice because your widget building subroutines can encapsulate all the
logic required to operate themselves, and provide the simplest interface
possible.  In this case, it means returning a sub that does the inserting
for you rather than returning the widget itself and forcing the external
code to know how to use the widget properly.  Properly documented, it can
make code a lot easier to understand.  I would really suggest learning as
much as you can about anonymous subroutines and closures before progressing
much further in Tk, see "perldoc -q closure" and "perldoc perlref".

--Ben Kennedy





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

Date: Sun, 12 Aug 2001 21:07:50 +0100
From: "Terry" <dcsnospam@ntlworld.com>
Subject: confused - can't print to file
Message-Id: <YjBd7.40458$e%3.5465953@news2-win.server.ntlworld.com>

Hello

I'm using the following piece of script to open, read, truncate and then
update a file.
I have stepped through this using perl -d and $filename, @prog,
$in{progname}, $in{memnum} and $prog[x] all have the expected values. The
file is truncated but the 'print' statement doesn't print to the file.
=======================================
$filename = "+<progs/inf/".$in{progname}.".txt";
open (PROG, $filename);
  flock PROG, 2;
  chomp (my @prog = <PROG>);
  truncate (PROG, 0);
  print PROG
$prog[0]."\n".$prog[1]."\n".$prog[2]."\n".$prog[3]."\n".$prog[4].";".$in{mem
num};
close (PROG);
=======================================

Can anyone spot my mistake?

TIA

Terry
--
remove nospam to reply




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

Date: Sun, 12 Aug 2001 21:50:57 +0100
From: "Terry" <dcsnospam@ntlworld.com>
Subject: Re: confused - can't print to file
Message-Id: <nYBd7.40736$e%3.5530076@news2-win.server.ntlworld.com>

Hello again,

I'll answer my own question as it may be of help to someone else :)
I assumed that truncating the file would set the filepointer at the start of
the truncated file. Apparently it doesn't because if I add

seek (PROG, 0, 0);

straight after the truncate statement then everything works fine :o)

--
remove nospam to reply




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

Date: Sun, 12 Aug 2001 21:56:59 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: confused - can't print to file
Message-Id: <3B76FC4E.60DA677D@acm.org>

Terry wrote:
> 
> I'm using the following piece of script to open, read, truncate and then
> update a file.
> I have stepped through this using perl -d and $filename, @prog,
> $in{progname}, $in{memnum} and $prog[x] all have the expected values. The
> file is truncated but the 'print' statement doesn't print to the file.
> =======================================

#!/usr/bin/perl -w
use strict;
use Fcntl qw(:flock :seek);

> $filename = "+<progs/inf/".$in{progname}.".txt";
               ^^ this is _not_ part of the file name

my $filename = "progs/inf/$in{progname}.txt";

> open (PROG, $filename);

open PROG, "+< $filename" or die "Cannot open $filename: $!";

>   flock PROG, 2;

flock PROG, LOCK_EX or die "Cannot lock $filename: $!";

>   chomp (my @prog = <PROG>);

my @prog = <PROG>;

>   truncate (PROG, 0);

truncate PROG, 0 or die "Cannot truncate $filename: $!";
seek PROG, 0, SEEK_SET or die "Cannot seek on $filename: $!";

>   print PROG
> $prog[0]."\n".$prog[1]."\n".$prog[2]."\n".$prog[3]."\n".$prog[4].";".$in{mem
> num};

chomp $prog[4];
print PROG "@prog[0..4];$in{memnum}"

> close (PROG);
> =======================================
> 
> Can anyone spot my mistake?

Only one?  :-)



John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 12 Aug 2001 18:14:53 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: cvs and perl-modules
Message-Id: <xIzd7.96611$EP6.24136038@news1.rdc2.pa.home.com>


"peter pilsl" <pilsl_@goldfisch.at> wrote in message
news:3b75a021$1@e-post.inode.at...

> As soon as I rerun make, the whole blib-structure is recreated and I cant
> commit to CVS, cause the CVS-subdirs in blib are missing ...

Are you building to some location in the project tree?  And if so, why
bother with h2xs-made modules, you may was well create a lib directory in
your project and make sure PERL5LIB points to it.  In a project I am working
on, we have all the Perl stuff under a lib directory, and we have a modules
directory that contains any perl modules that require XS code.  We then
build to inside the lib directory, but have a .cvsignore file that includes
the subdirs 5.6.1 and site_perl within lib, which are automatically
generated during module installation.  Anyway, hope some of this helps

--Ben Kennedy




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

Date: Sun, 12 Aug 2001 18:17:00 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I translate tildes (~) in a filename?
Message-Id: <wKzd7.61$V3.170723840@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How can I translate tildes (~) in a filename?

    Use the <> (glob()) operator, documented in the perlfunc manpage. Older
    versions of Perl require that you have a shell installed that groks
    tildes. Recent perl versions have this feature built in. The Glob::KGlob
    module (available from CPAN) gives more portable glob functionality.

    Within Perl, you may use this directly:

            $filename =~ s{
              ^ ~             # find a leading tilde
              (               # save this in $1
                  [^/]        # a non-slash character
                        *     # repeated 0 or more times (0 means me)
              )
            }{
              $1
                  ? (getpwnam($1))[7]
                  : ( $ENV{HOME} || $ENV{LOGDIR} )
            }ex;

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           05.11
-- 
    This space intentionally left blank


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

Date: Sun, 12 Aug 2001 11:12:59 -0700
From: "Stephen Deken" <shutupsteve@awdang.no.thanks.com>
Subject: Re: Need help with error trying to use string as ARRAY ref...
Message-Id: <tndhojb4l03e97@corp.supernews.com>

"Tintin" wrote:
> > Roger Hinson wrote:
> >   system "echo PRODDB1_$group establish DEV001 BCV dev $bcvset1";
>
> Am I the only one here who can't see why the above line is
> needed?  None of the solutions changed it, so I can only
> assume I'm missing something obvious.

I changed it, but I was drunk and not thinking clearly.  All I did was make
it a list with 'echo' as the first argument.

It should, without a doubt, be changed to a print statement:

  print "PRODDB1_$group establish DEV001 BCV dev $bcvset1\n";

All calling the system's `echo` command buys you is lack of portability and
processing overhead.

--sjd;




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

Date: Sun, 12 Aug 2001 19:25:52 GMT
From: "Roger Hinson" <hinson@home.com>
Subject: Re: Need help with error trying to use string as ARRAY ref...
Message-Id: <4LAd7.47361$MC1.14954134@news1.elcjn1.sdca.home.com>


"Stephen Deken" <shutupsteve@awdang.no.thanks.com> wrote in message
news:tndhojb4l03e97@corp.supernews.com...
> "Tintin" wrote:
> > > Roger Hinson wrote:
> > >   system "echo PRODDB1_$group establish DEV001 BCV dev $bcvset1";
> >
> > Am I the only one here who can't see why the above line is
> > needed?  None of the solutions changed it, so I can only
> > assume I'm missing something obvious.
>
> I changed it, but I was drunk and not thinking clearly.  All I did was
make
> it a list with 'echo' as the first argument.
>
> It should, without a doubt, be changed to a print statement:
>
>   print "PRODDB1_$group establish DEV001 BCV dev $bcvset1\n";
>
> All calling the system's `echo` command buys you is lack of portability
and
> processing overhead.
>
> --sjd;
>
>

    Actually, I'll eventually take the echo out and use the real command.  I
just don't have the application on my local machine or the hardware to
support the application.

    Roger





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

Date: Sun, 12 Aug 2001 17:03:05 +0100
From: Jayne Heger <jayne.heger@ntlworld.com>
Subject: Newbie
Message-Id: <jb96l9.jr9.ln@bealzebub.ntlworld.com>


HI,

I am new to this newsgroup and have never used the Perl language before.

What I want to do is quickly and easily convert text files into CSV, (comma 
separated values), so I can then import the information into a database.

I have heard off the grapevine that Perl can do this.

Also, are there any recommended books for Newbies, nothing too heavy.;)

Thanks

Jayne




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

Date: Sun, 12 Aug 2001 21:55:20 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Newbie
Message-Id: <3B76DF28.5080506@post.rwth-aachen.de>

Jayne Heger wrote:
> HI,
> 
> I am new to this newsgroup and have never used the Perl language before.
> 
> What I want to do is quickly and easily convert text files into CSV, (comma 
> separated values), so I can then import the information into a database.
> 
> I have heard off the grapevine that Perl can do this.

This...and a little more. ;-)

> 
> Also, are there any recommended books for Newbies, nothing too heavy.;)

As for Perl, I can really recommend the O'Reilly books. For an overview, 
there are mainly two sort of 'Bibles'. One is of course the Camel book 
"Programming Perl", 3rd edition written by the inventor of this 
language, Larry Wall.
The other one (probably the book you should go for) is "Learning Perl" 
written by Randal Schwarzt who's also a regular in this newsgroup and 
Tom Phoenix.


Tassilo



-- 
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};



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

Date: Sun, 12 Aug 2001 13:26:53 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl -w and -W flags
Message-Id: <slrn9ndf2t.1ca.tadmc@tadmc26.august.net>

Ilya Martynov <ilya@martynov.org> wrote:
>
>SH>      Could someone please tell where I can find a description of which
>SH> warnings the -w and -W flags turn on.  


   perldoc perldiag


>SH> I've not been able to find it
>SH> in perldoc, but it is possible that I am missing the obvious.  


Which ones did you look in?


>SH> The
>SH> only description that I have been able to find is from running perl
>SH> with the -h flag.
>
>SH>   -w              enable many useful warnings (RECOMMENDED)
>SH>   -W              enable all warnings


Perl's command line switches are documented in perlrun.pod:

   perldoc perlrun

The description for -w refers to several other places in the docs.


>It is described in 'perldoc perllexwarn' chapter 'Controlling Warnings
>from the Command Line'.


That is not at all about what the OP was asking (though it is entirely
possible that he/she meant to ask some other question :-)

The Subject clearly talks about "command line switch" warnings (old).

perllexwarn.pod is all about "lexical" warnings (new).

The "warnable offenses" are the same for both methods though.


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


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

Date: Sun, 12 Aug 2001 16:57:30 -0400
From: "AJ M" <jerseycat10@yahoo.com>
Subject: Perl with CGI with Cookies... HELP!
Message-Id: <9l6qok$3oh$1@bob.news.rcn.net>

Hello, everyone.   I have modest experience with perl writing cgi's, but my
knowledge of cookies (writing them) on any platform or language is nil.
However, I decided to read up on the topic, since I thought that using
cookies would be neat on my site.  Right now, I am have a login script that
takes a username and password, does some error checking, and prints out some
html depending on whether or not the username/password combo matches a flat
test file database.  If it does, I try to set a cookie like so:

print "Set-Cookie:validity=$status; expires=Sat, 11-Aug-2001 00:00:00
GMT;domain=.rowan.edu ;path=/\n";

I then have another CGI, for members only, which attempts to determine
whether or not the above cookie has been set or not:

if($ENV{'HTTP_COOKIE'})
{
  read(STDIN, $buffer, $ENV{'HTTP_COOKIE'});

  @cookies = split (/;/, $buffer);

  foreach $cookie (@cookies)
  {
    ($name, $value) = split (/=/, $cookie);
    $crumbs{$name} = $value;
  }
  $status = $crumbs{'validity'};

and so on....


I know there is probably some flaws in the above snippets of code, can
someone tell me what I am doing wrong, it would be greatly appreciated,
thanks!

AJ






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

Date: 13 Aug 2001 01:15:55 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Perl with CGI with Cookies... HELP!
Message-Id: <87k809nfn8.fsf@abra.ru>


AM> I then have another CGI, for members only, which attempts to determine
AM> whether or not the above cookie has been set or not:

AM> if($ENV{'HTTP_COOKIE'})
AM> {
AM>   read(STDIN, $buffer, $ENV{'HTTP_COOKIE'});

AM>   @cookies = split (/;/, $buffer);

AM>   foreach $cookie (@cookies)
AM>   {
AM>     ($name, $value) = split (/=/, $cookie);
AM>     $crumbs{$name} = $value;
AM>   }
AM>   $status = $crumbs{'validity'};

AM> and so on....

What is

    read(STDIN, $buffer, $ENV{'HTTP_COOKIE'});

supposed to do?

Your code anyway should look like (untested):

if($ENV{'HTTP_COOKIE'})
{
  @cookies = split (/;/, $ENV{'HTTP_COOKIE'});

  foreach $cookie (@cookies)
  {
    ($name, $value) = split (/=/, $cookie);
    $crumbs{$name} = $value;
  }
  $status = $crumbs{'validity'};
}

But actually instead of reinventing the wheel probably it is better to
use existing Perl module CGI::Coookie:

use CGI::Coookie;

%cookies = fetch CGI::Cookie;
$status = $cookies{validity}->value;

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Sun, 12 Aug 2001 17:33:37 -0400
From: "AJ M" <jerseycat10@yahoo.com>
Subject: Re: Perl with CGI with Cookies... HELP!
Message-Id: <9l6ssk$d3l$1@bob.news.rcn.net>

I knew there had to be an easier way :)   However, when I use your code, I
get the following error:

"Can't call method "value" without a package or object reference at
members.cgi l
ine 14."

where line 14 is:
     $status = $cookies{validity}->value;

thanks,
  AJ


Ilya Martynov <ilya@martynov.org> wrote in message
news:87k809nfn8.fsf@abra.ru...
>
> AM> I then have another CGI, for members only, which attempts to determine
> AM> whether or not the above cookie has been set or not:
>
> AM> if($ENV{'HTTP_COOKIE'})
> AM> {
> AM>   read(STDIN, $buffer, $ENV{'HTTP_COOKIE'});
>
> AM>   @cookies = split (/;/, $buffer);
>
> AM>   foreach $cookie (@cookies)
> AM>   {
> AM>     ($name, $value) = split (/=/, $cookie);
> AM>     $crumbs{$name} = $value;
> AM>   }
> AM>   $status = $crumbs{'validity'};
>
> AM> and so on....
>
> What is
>
>     read(STDIN, $buffer, $ENV{'HTTP_COOKIE'});
>
> supposed to do?
>
> Your code anyway should look like (untested):
>
> if($ENV{'HTTP_COOKIE'})
> {
>   @cookies = split (/;/, $ENV{'HTTP_COOKIE'});
>
>   foreach $cookie (@cookies)
>   {
>     ($name, $value) = split (/=/, $cookie);
>     $crumbs{$name} = $value;
>   }
>   $status = $crumbs{'validity'};
> }
>
> But actually instead of reinventing the wheel probably it is better to
> use existing Perl module CGI::Coookie:
>
> use CGI::Coookie;
>
> %cookies = fetch CGI::Cookie;
> $status = $cookies{validity}->value;
>
> --
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> | Ilya Martynov (http://martynov.org/)
|
> | GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6
|
> | AGAVA Software Company (http://www.agava.com/)
|
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-




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

Date: 13 Aug 2001 01:41:42 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Perl with CGI with Cookies... HELP!
Message-Id: <87bsllneg9.fsf@abra.ru>


AM> I knew there had to be an easier way :)   However, when I use your code, I
AM> get the following error:

AM> "Can't call method "value" without a package or object reference at
AM> members.cgi l
AM> ine 14."

AM> where line 14 is:
AM>      $status = $cookies{validity}->value;

AM> thanks,
AM>   AJ

Indeed my example has a bug. It doesn't handle case when cookie
'validity' is undefined. Correct code should look like:

use CGI::Coookie;
 
%cookies = fetch CGI::Cookie;
$status = defined $cookies{validity} ? $cookies{validity}->value : undef;

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Sun, 12 Aug 2001 17:43:20 -0400
From: "AJ M" <jerseycat10@yahoo.com>
Subject: Re: Perl with CGI with Cookies... HELP!
Message-Id: <9l6teu$fi1$1@bob.news.rcn.net>

ok, thanks, that works!  Now I have to figure out why my cookie is unset, or
blank. Thanks again for your help and timely replies.

AJ M


Ilya Martynov <ilya@martynov.org> wrote in message
news:87bsllneg9.fsf@abra.ru...
>
> AM> I knew there had to be an easier way :)   However, when I use your
code, I
> AM> get the following error:
>
> AM> "Can't call method "value" without a package or object reference at
> AM> members.cgi l
> AM> ine 14."
>
> AM> where line 14 is:
> AM>      $status = $cookies{validity}->value;
>
> AM> thanks,
> AM>   AJ
>
> Indeed my example has a bug. It doesn't handle case when cookie
> 'validity' is undefined. Correct code should look like:
>
> use CGI::Coookie;
>
> %cookies = fetch CGI::Cookie;
> $status = defined $cookies{validity} ? $cookies{validity}->value : undef;
>
> --
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> | Ilya Martynov (http://martynov.org/)
|
> | GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6
|
> | AGAVA Software Company (http://www.agava.com/)
|
>  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-




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

Date: Sun, 12 Aug 2001 21:07:26 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Regular expression to take HTML comments out??
Message-Id: <997650446.762998686637729.gnarinn@hotmail.com>

In article <9l4dve$ll9$3@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>According to Carlos C. Gonzalez  <miscellaneousemail@yahoo.com>:
>> Hi everyone,
>> 
>> Since I am relatively new at using regular expressions and Perl in 
>> general I was wondering if someone could give me some feedback on the 
>> following regexp.  It strips the $string of the HTML comment statement 
>> and any text in between them.  
>> 
>> Is there a faster and / or clearer, better way to do this?  
>> 
>> The code:
>> 
>> #!/usr/bin/perl -w
>> 
>> use CGI::Carp qw(carpout fatalsToBrowser);
>> use diagnostics;
>> use strict;
>> 
>> my $string = "Hello<!-- BEGIN -->there!<!-- END --> How are you?";
>> $string =~s/<!-- BEGIN -->.+<!-- END -->//;
>> print $string;
>
>Oh dear... regex parsing of HTML.  It won't work.
>
>For one, your substitution will erase everything between the first
>comment in a sting and the last, because the .+ in the middle is greedy.
>But even if you fixed that (which is possible) there are places in HTML
>where the string "<!-- BEGIN -->" can appear without introducing
>a comment, which will confuse the hell out of your regex. 
>

actually, that IS what the OP wanted to do (i think)

gnari


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

Date: Sun, 12 Aug 2001 18:07:32 +0000 (UTC)
From: see-sig@from.invalid (David Efflandt)
Subject: Re: searching files from linux to Internet
Message-Id: <slrn9ndhf3.ls6.see-sig@typhoon.xnet.com>

On 12 Aug 2001 09:43:12 -0700, brian <brian@numenor.screaming.net> wrote:
> hi, i've written a program which searches the text for specified words
> or phrases in all of the files in specified directories. it works as
> hoped when tested on my linux box but when i make a couple of small
> changes to make it search folders on the internet i keep getting
> server error 500.

Try running it in the shell first to check for major errors:

Can't locate object method "Use" via package "CGI" at some.cgi line 16.

That should be: use CGI:

-- 
David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: 12 Aug 2001 13:50:45 -0700
From: brian@numenor.screaming.net (brian)
Subject: Re: searching files from linux to Internet
Message-Id: <1b9ec5ec.0108121250.56ca0691@posting.google.com>

hi, thanks to both of you

yeah should have used:
 
   #!/usr/bin/perl -w
   use strict;

would have spotted this: 

> That should be: use CGI:

folders = directories ## should have made myself clear, sorry...

cheers
brian


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

Date: Sun, 12 Aug 2001 21:00:44 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: searching files from linux to Internet
Message-Id: <997650044.330872758291662.gnarinn@hotmail.com>

In article <1b9ec5ec.0108120843.27b75c9c@posting.google.com>,
brian <brian@numenor.screaming.net> wrote:
>hi, i've written a program which searches the text for specified words
>or phrases in all of the files in specified directories. it works as
>hoped when tested on my linux box but when i make a couple of small
>changes to make it search folders on the internet i keep getting
>server error 500.

first: did you test the (cgi) script with 
  perl -c script.pl
  
>heres the code for the one that works:
(snipped)

>
>the second one accepts the search text and search options from an html
>form:
>

>Use CGI;

use CGI;

>$searchQuery = new CGI;
>$search = $searchQuery->param('search');
>$option = $searchQuery->param('option');
>
>print "Content-type: text/html\n\n";

why not use the CGI function header()

>
>print qq|
><html>
><title> Search Result </title>
><body>
>Search results for $search<br><br>
>|;

do you know about here documents?
print <<EODOC;
<html>
<title> Search Result </title>
<body>
Search results for $search<br><br>
EODOC


>$found = 0;
>@directoryList = ("/home/hinkiec/www/search"); ###add directories to
>be searched

hopefully, these two lines are actually one, and were split by the
news software

(snip)

>    opendir(DIR, $dir)||print("could not open $dir\n");

a few comments:
 a) when an open commands fails, usually it is not safe just to
    print a message and then continue execution as if the open was
    successful. either call die(), or use a if-else structure
 b) in a cgi, you must be careful about error prints. in this case
    it is okey, but a common trap is to print them before the html
    header, resulting in invalid cgi output
 c) in this kind of construct, get used to use 'or' instead of '||'
    or you will be bitten by precedence sooner or later
 d) a cgi may not have the same permissions as you the user, so
    make sure that the directory or file in questions is
    readable/writable/executable by the user cgis ar run as,
    usually 'nobody'


gnari


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

Date: Sun, 12 Aug 2001 19:52:31 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Statement modifiers??
Message-Id: <MPG.15e08c417f84a30d989731@news.edmonton.telusplanet.net>

Hi everyone,

Uri stated in another thread...

"learn to use perl's statement modifiers as it will clean up your
code. one big win for them is reducing the unneeded braces and indents
of simple conditionals..."

I have looking all over the place for info on statement 
modifiers (searching www.perl.com and Google) and have come up with very 
scant stuff.  I looked through a bunch of articles at www.perl.com that 
came up in my search and clicked on a bunch of links on Google.  There 
seems to be very little about them. 

Does anyone know a good link to a full explanation of what statement 
modifiers are and examples of how to use them?

Thanks.

-- 
Carlos 
www.internetsuccess.ca


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

Date: 12 Aug 2001 20:07:50 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Statement modifiers??
Message-Id: <9l6nmm$7o1io$1@fu-berlin.de>

Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:

> Uri stated in another thread...

> "learn to use perl's statement modifiers as it will clean up your
> code. one big win for them is reducing the unneeded braces and indents
> of simple conditionals..."

well, i believe Uri meant modifiers like "if" or "unless".
for example, you can write

# loop
 next if /unwanted/;

which is shorter and (IMHO) clearer then:
 if (/unwanted/) {next}

read about it in
 perldoc perlsyn

hth, tina
-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception
---   Warning: content of homepage hopelessly out-dated   ---


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

Date: Sun, 12 Aug 2001 23:56:04 +0200
From: "Murat Uenalan" <murat.uenalan@gmx.de>
Subject: Re: Using the Term::ANSIColor
Message-Id: <9l6trs$7qd1s$1@ID-71895.news.dfncis.de>

ansi.sys at:

www.ntfaq.com

Good luck,
Murat


"Wolfgang Vogel" <w.a.vogel@t-online.de> schrieb im Newsbeitrag
news:9l4lrj$21l$06$1@news.t-online.com...
> High group,
>
> can someone give me a hint how I can realize colored text output in
> a WIN2000 DOSBOX.
>
> Thanks for any constructive hint
>
> Wolfgang Vogel
>
>
>




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

Date: 12 Aug 2001 13:46:11 -0700
From: mongo@firewallx.com (Mongo)
Subject: Re: voodoo cookie hash problem
Message-Id: <dc31dfbf.0108121246.673a2bb@posting.google.com>

> show us an example that both outputs $ENV{'HTTP_COOKIE'} to browser
> and to your email, and show us both outputs
> 
> gnari

this would print the cookie values to the browser:

foreach $name (keys %cookies) {
	print "\n$name = $cookies{$name}<br>";
}

but anything i've tried for putting a value in email doesn't work, like:

$cookies{'user'}  #for the user value

or even just a more general value like:

$ENV{'HTTP_COOKIE'}<br>
$ENV{'REMOTE_HOST'}


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

Date: Sun, 12 Aug 2001 13:28:39 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Warning  pragma -w
Message-Id: <slrn9ndf67.1ca.tadmc@tadmc26.august.net>

gnari <gnarinn@hotmail.com> wrote:

>maybe you edited the file on pc and uploaded it to unix in bin mode?
>
>in that case there may be a carriage return at the end each line,
>that can interfere with the correct execution of your script


So you fix it (strip the carriage returns), and try it again :-)


   perl -p -i -e 'tr/\r//d' file_from_DOS


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


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

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 1503
***************************************


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