[17165] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4577 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 11 00:05:28 2000

Date: Tue, 10 Oct 2000 21:05:10 -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: <971237110-v9-i4577@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 10 Oct 2000     Volume: 9 Number: 4577

Today's topics:
    Re: Cookie implmentation with Perl/Linux <elephant@squirrelgroup.com>
    Re: Deleting named files? (Martien Verbruggen)
    Re: Deleting named files? (Gwyn Judd)
    Re: Error message from cgi-lib.pl (Gwyn Judd)
        Help for a CGI newbie <byron@dreamtech.org>
    Re: How do I change the position on screen where to pri (Ron D. Smith~)
    Re: how to remove unprintable  chars with Perl script <lr@hpl.hp.com>
        included files: missing one important concept... <mcdonabNO@SPAMyahoo.com>
    Re: Keeping data structures private. (Brett W. McCoy)
    Re: Keeping data structures private. (Gwyn Judd)
    Re: LWP, URI, HTTP brainfart <mbudash@sonic.net>
    Re: Multiple CGI objects (Brett W. McCoy)
    Re: perl resource <someone@world.earth>
    Re: Reading a whole file into a string <uri@sysarch.com>
    Re: Reading a whole file into a string <godzilla@stomp.stomp.tokyo>
    Re: Reading a whole file into a string <01031149@3web.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Oct 2000 14:57:51 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: Cookie implmentation with Perl/Linux
Message-Id: <MPG.144e9e5d1d872dd398980a@localhost>

  [ posted to comp.lang.perl.misc and CCed to whyip@pacific.net.sg ]

Bryan wrote ..
> OS : Linux
> Perl Ver : 5; cgi.pm
>
>Aim : To write a html form that send POST data to a cgi script that
>save in a cookie, & access by another cgi script to reflect contents
>of the cookie in a dynamically created html page.
>
>
>Hi.
> I'm trying to write a html form that send POST data to a cgi script.
>The script is ex1.gi, stored in /cgi-bin/exp1/exp1.cgi.
>The script should save the info to a cookie, where defaulted path='/'.
>
>
>Partial Script of exp1.cgi :
>
># code read in STDIN and parse to $formdata #
>...
>$query = new CGI();
>
>$my_cookie = new CGI::Cookie(
>		-name=>'anycookie',
>		-value=>$formdata.
                               ^..this period will create a problem by 
creating a value that is the result of $formdata concatenated with the 
string '-expires' .. it should be a comma instead

the other problem that this will create is that the -expires value is 
never used .. however - neither of these are likely to be your problem 
(see below)

>		-expires=>'+15m'
>);
>
>print $query->header(-cookie=>$my_cookie);
>...
>
> Everything works well until here. The above script - exp1.cgi,
>provided
>a link to another script - exp2.cgi
> exp2.cgi is stored in /cgi-bin/exp2/exp2.cgi.
>exp2.cgi script SHOULD create a html page that printout the contents
>of the cookie - 'anycookie'. However, none of the cookie's contents
>are printed.

you're missing the PATH attribute of your cookie .. have a look at the 
cookie spec - this is not a Perl question

  http://home.netscape.com/newsref/std/cookie_spec.html

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Wed, 11 Oct 2000 02:07:28 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Deleting named files?
Message-Id: <slrn8u7iqm.8q8.mgjv@verbruggen.comdyn.com.au>

On Wed, 11 Oct 2000 00:26:18 +0100,
	CrinkleFish <longusername@NOSPAMhotmail.com> wrote:
> 
> #!/usr/local/bin/perl
> foreach (<STDIN>) {
> $file = $_;
> unlink $file;
> print "just unlinked $file";
> }


Did you notice anything when you looked at the output? Like a newline
that you didn't put there? Do your filenames contain newlines? If not,
you might want to have a look at chomp().

# perldoc -f chomp

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | What's another word for Thesaurus?
NSW, Australia                  | 


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

Date: Wed, 11 Oct 2000 03:04:47 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Deleting named files?
Message-Id: <slrn8u7m6d.3sj.tjla@thislove.dyndns.org>

I was shocked! How could CrinkleFish <longusername@NOSPAMhotmail.com>
say such a terrible thing:
>Thank you Tony. Are you that famous actor guy. Chomp , chomp.

Note that this would have been obvious had you tested for an error:

unlink $file or warn "Cannot delete '$file': $!";

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Don't let anyone steal your Dreams.
Follow your heart, no matter what.
		-- Jack Cainfield, "Chicken Soup for the Soul"


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

Date: Wed, 11 Oct 2000 03:13:14 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Error message from cgi-lib.pl
Message-Id: <slrn8u7mm9.3sj.tjla@thislove.dyndns.org>

I was shocked! How could anmu4141@my-deja.com <anmu4141@my-deja.com>
say such a terrible thing:
>I have a problem with the cgi-lib.pl (I have
>taken V 2.18).

There is your problem. Don't use cgi-lib. Use CGI.pm instead:

#!/usr/bin/perl -w
use strict;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser);

print header;

you can add the rest. Hope that helps. Also read the documentation:

perldoc CGI
perldoc CGI::Carp

etc..

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Time sure flies when you don't know what you're doing.


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

Date: Tue, 10 Oct 2000 23:38:05 -0400
From: "newsgroups" <byron@dreamtech.org>
Subject: Help for a CGI newbie
Message-Id: <8s0nl5$cao$1@slb6.atl.mindspring.net>

I was wondering if someone would be willing to help a CGI newbie out with
some misbehaving code.  I am trying to write a CGI program that will allow a
user to update a webpage through an HTML form.  I am testing on an NT4
server running IIS4 with Active State's Active Perl 5.2.2.  Essentially what
the code is supposed to do is create a new file and copy all of the HTML
file into the new file with changes according to the variables passed.  It
then renames the old file to a backup and renames the new file to the old
files name.  This code worked as a stand alone perl script but as soon as I
tried to run it as a CGI script it started creating a blank new file.
Here's the code:

---------------------------------------begin code
snippet--------------------------
use CGI ':standard';
$section=param("section");
$data=param("data");

print header;
print start_html('Web Editor ver. 1.0');

if (param()) {

#here I open the existing file and create the new file for writing
open (html, 'd:\inetpub\wwwroot\webpage.htm')||die "can't open html file!";
open (nwhtml, '> d:\inetpub\wwwroot\newwebpage.htm')||die "can't create html
file";

while (<html>) {
 #this line searches out the text between the two unique char sets and
assigns it as a variable to $1
 $_=~/<!---$section--->(.*?)<!---$section--->/;
 #for every line in the file it checks to see if the above condition is met
 if ($1) {
  #here is the magic, this line replaces all text between the two unique
character sets with the variable $data
  $_=~s/$1/$data/gm
 }
 #this line merely copies all data from the original file to the new file
with the appropriate changes
 print nwhtml $_;
}

#must close the filehandles before renaming them
close (html)||die "can't close html";
close (nwhtml)||die "can't close nwhtml";
#rename the original file as .old and then rename the new file with the same
name as the original
rename 'd:\inetpub\wwwroot\webpage.htm',
'd:\inetpub\wwwroot\webpage.htm.old';
rename 'd:\inetpub\wwwroot\newwebpage.htm',
'd:\inetpub\wwwroot\webpage.htm';

print p("Updated successfully!");

} else {
 print start_form,
 "Section: ", textfield(-name=>'section',-size=>40),
 p,
 "Text: ", textarea(-name=>'data',-size=>40),
 p,
 submit,
 reset,
 end_form;
}
print end_html;
-----------------------------------------end code
snippet---------------------------

Thanks for any help

byron




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

Date: 11 Oct 2000 01:14:48 GMT
From: rdsmith@sedona.intel.com (Ron D. Smith~)
Subject: Re: How do I change the position on screen where to print?
Message-Id: <8s0eu8$f61@news.or.intel.com>

In article <3fpC5.163$u23.12398@news000.worldonline.dk>, Anders Lund <anders@wall.alweb.dk> writes:
|> Peter Levi wrote:
|> 
|> > Help guys!I want to show on the screen the process of downloading a file -
|> > so I have to print for example "12%, 12520 bytes read".And I want this to
|> > appear on one and the same place on the screen. (to replace the previous
|> > "10%, 10380 bytes read" for
|> > example).How do I do this!Because currently  I print the new data on a new
|> > line - very embarassing and ugly!How can I change the position of the
|> > marker where I want to print?Peter
|> > 
|> 
|> You'd like to take a look at Term::Screen

Another suggestion that is easy to implement is:

print "\c[[0Kfile: $file bytes: $bytes_read\r";

this works iff your xterm behaves like a vt100.  The '\c[[0k' is "clear to end of
line" in vt100-speak. Next, you print the string, then you do a carriage return 
(*not* a newline) which does not advance the output.

This is hardly general (x,y) cursor positioning but it *does* help the
"scrolling forever" problem, and it is an easy hack for most cases.


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

Date: Tue, 10 Oct 2000 18:09:53 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how to remove unprintable  chars with Perl script
Message-Id: <MPG.144d5db99ccbb76098ae20@nntp.hpl.hp.com>

In article <39E25037.EEDA60FB@acm.org> on Mon, 09 Oct 2000 16:09:43 -
0700, John W. Krahn <krahnj@acm.org> says...
> This should work:
> 
> s/[:^print:]//g;

Perhaps you think it 'should work', but it doesn't (it needs another set 
of square brackets), as you could have found out trivially by trying it 
before posting it, or even by checking it out in perlre.

  This should work:

  s/[[:^print:]]//g;

The POSIX 'print' class includes the four whitespace control characters 
"\t" "\n" "\f" "\r", which is different from the C isprint() class.  I 
haven't been able to find a definitive reference on the Web to the 
definitions of the POSIX character classes; without such a definition or 
a reference to it, the Perl documentation is incomplete.

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

If locale-dependent issues aren't involved, then the following is much 
faster.  The four whitespace control characters can be included if 
desired:

  tr/\x20-\x7e//cd;

Or, to save keystrokes,

  tr/ -~//cd;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 10 Oct 2000 18:13:27 -0700
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: included files: missing one important concept...
Message-Id: <y9PE5.4889$Wq1.1799186@nnrp5-w.sbc.net>

Hi again.

I believe that I am missing one important concept that will enable me to
proceed.

I have created a module called, datadefs.pm, that I want to include in my
script txt2xml.pl. It goes something like this...

datadefs.pm:
----

my $roottag  = "<lsdml>";
my $rootetag = "</lsdml>";

# LSDml child start tags
my @lsdml_child_st = qw( <Document> );

# LSDml child end tags
my @lsdml_child_et = qw( </Document> );

(plus a whole lotta other defs...)

----

In txt2xml.pl I have...

----

#!\usr\bin\perl -w
use strict;
use DBI;
use datadefs;

(plus a whole lotta logic...)

----

The problem is that when I compile this I get the following errors (which
another poster once posted... but got no response!):

Global symbol "$roottag" requires explicit package name at txt2xml.pl line
75
Global symbol "@lsdml_child_et" requires explicit package name at txt2xml.pl
line 87
Global symbol "@rootetag" requires explicit package name at txt2xml.pl line
88

Do I have to preface each variable in txt2xml.pl with something like
'Package::' in order that the variable is understood?

Something else?

Thanks,
Brian










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

Date: Wed, 11 Oct 2000 01:21:54 GMT
From: bmccoy@news.speakeasy.org (Brett W. McCoy)
Subject: Re: Keeping data structures private.
Message-Id: <slrn8u7g6o.trk.bmccoy@chapelperilous.net>

On Tue, 10 Oct 2000 22:22:46 GMT, 13_hellfish@my-deja.com
<13_hellfish@my-deja.com> wrote:

>How do I keep a data structure private?  I need to access both a hash
>and an array in a subroutine.  So, I'm passing references to the
>subroutine via \.
>
>Now in the subroute, It's easy to to get at the data, with @$, but I
>would like this data read only.  I'm not yet so great of a coder and
>would like this extra protection.

There really isn't 'private' data in Perl as you are accustomed to in C++
and Java.  It's sort of on the programmer's own personal honor to poke
around where she isn't invited.  You can control access to data in sone
cases with the intelligent use of 'my' and 'local', but it's not exactly
the same, I would think.

-- 
Brett W. McCoy
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
No man in the world has more courage than the man who can stop after
eating one peanut.
		-- Channing Pollock


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

Date: Wed, 11 Oct 2000 03:41:20 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Keeping data structures private.
Message-Id: <slrn8u7oar.3sj.tjla@thislove.dyndns.org>

I was shocked! How could Brett W. McCoy <bmccoy@news.speakeasy.org>
say such a terrible thing:
>On Tue, 10 Oct 2000 22:22:46 GMT, 13_hellfish@my-deja.com
><13_hellfish@my-deja.com> wrote:
>
>>How do I keep a data structure private?  I need to access both a hash
>>and an array in a subroutine.  So, I'm passing references to the
>>subroutine via \.
>>
>>Now in the subroute, It's easy to to get at the data, with @$, but I
>>would like this data read only.  I'm not yet so great of a coder and
>>would like this extra protection.
>
>There really isn't 'private' data in Perl as you are accustomed to in C++
>and Java.  It's sort of on the programmer's own personal honor to poke
>around where she isn't invited.  You can control access to data in sone
>cases with the intelligent use of 'my' and 'local', but it's not exactly
>the same, I would think.

You need to read "perldoc perltoot" especially the bit about "Closures
as Objects".

Also consider what happens when you do "#define private public" in a C++
program. Perl does much better than that, I think.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
It's always darkest just before it gets pitch black.


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

Date: Tue, 10 Oct 2000 20:55:42 -0700
From: Michael Budash <mbudash@sonic.net>
Subject: Re: LWP, URI, HTTP brainfart
Message-Id: <mbudash-BF94BE.20554210102000@news.pacbell.net>

In article <8rvb42$5n3$1@nnrp1.deja.com>, lim_k@my-deja.com wrote:

> I'm needing to create a script which connects to a authenticated web
> site.  I had created a script in the past for this but I had forgotten
> which mod and the format of the mod I used.  I'm pretty sure I used
> LWP::Simple, but I wouldn't be my job on it.  Any assistance is greatly
> appreciated!
> 
> Thanks!
> 

from 'perldoc lwpcook':

ACCESS TO PROTECTED DOCUMENTS
       Documents protected by basic authorization can easily be
       accessed like this:

         use LWP::UserAgent;
         $ua = new LWP::UserAgent;
         $req = new HTTP::Request GET => 'http://www.sn.no/secret/';
         $req->authorization_basic('aas', 'mypassword');
         print $ua->request($req)->as_string;

hope this helps-
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


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

Date: Wed, 11 Oct 2000 01:24:41 GMT
From: bmccoy@news.speakeasy.org (Brett W. McCoy)
Subject: Re: Multiple CGI objects
Message-Id: <slrn8u7gc0.trk.bmccoy@chapelperilous.net>

On Tue, 10 Oct 2000 21:38:53 GMT, rbfitzpa@my-deja.com
<rbfitzpa@my-deja.com> wrote:

>Can someone give me a brief explanation to why someone would need
>multiple CGI objects in one perl script? I'm sure there are some good
>reasons why but up till now I've always been able to accomplish what I
>needed to without multiple CGI's. I want to make sure I'm not missing
>out on anything.

Yes -- you might be using another CGI object to restore data from a
previously saved CGI query.  In general you don't need more than one CGI
object, though.

-- 
Brett W. McCoy
                                              http://www.chapelperilous.net
---------------------------------------------------------------------------
Rome wasn't burnt in a day.


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

Date: Tue, 10 Oct 2000 23:21:23 -0400
From: "JS/PL" <someone@world.earth>
Subject: Re: perl resource
Message-Id: <su7nbvtdbmgte9@corp.supernews.com>

Thanks! I will give the suggestions a try. Much appreciated!

"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn8u75ah.8nu.mgjv@verbruggen.comdyn.com.au...
> On Tue, 10 Oct 2000 12:13:25 -0400,
> JS/PL <admin@news.dynip.com> wrote:
> > Hello,
> > I realize this may be pure begging. I have a list of city names which is
> > composed of one city per line in a plain text file. There are 42,000
lines
> > but many duplicate city names (eg. Waco is entered 22 times on 22 lines
> > between Wacissa and Waconia) I know perl is probably a great tool to
remove
> > all the duplicate names but leaving one name, what I don't have is a
script
> > to do it. I have almost no knowlege of writing scripts (actually none),
> > could someone show me the way to a resource for finding such a script?
Thank
> > You
>
> Assuming that your file is already sorted, which you seem to indicate,
> you can just use uniq, if you're on a *nix system (as others have
> suggested. Yet others have suggested that you may not be on a unix
> system. I do know you have perl, so a poor man's version of uniq could
> be:
>
> # cat uniq.pl
> #!/usr/local/bin/perl -n
> print unless $o eq $_;
> $o = $_;
> # ./uniq.pl data > data.uniq
>
> If your file isn't sorted yet, you should sort it. Even win platforms
> have a sort program that will work much better for large files than
> perl's internal sort.
>
> For a more elaborate version of uniq, and perl implementations of
> other standard Unix tools, see http://language.perl.com/ppt/
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      | For heaven's sake, don't TRY to be
> Commercial Dynamics Pty. Ltd.   | cynical. It's perfectly easy to be
> NSW, Australia                  | cynical.




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

Date: Wed, 11 Oct 2000 03:00:32 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Reading a whole file into a string
Message-Id: <x766n013qq.fsf@home.sysarch.com>

>>>>> "G" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:


  G> Clearly this is a woman's job, a task for a woman
  G> who both understands and knows how to use local ()
  G> correctly and effectively.

SNORFLE!! you don't understand anything in perl, let alone local. watch!

  G> sub Local
  G>   { 

put this in there:

	$/ = 0 ;

  G>    if (!($/))
  G>     { print "\$/ Does Not Exist."; }

it will print that, but $/ exists. you don't even understand boolean vs
defined tests.

  G> print "Global After Subroutine: $/\n";

  G> undef local ($/);

local outside a scope is meaningless. its purpose is to save a value IN
A SCOPE. 

  G> print "Globally Localized: $/";

  G> if (!($/))
  G>  { print "\$/ Does Not Exist."; }

the undef did that, not the local. and you can't say $/ does not exist
without testing with defined. try that test with $/ = ''.


oh, well, shooting fish in a barrel with dynomite isn't too hard. let's
see the latest mule manure comment. it use to be we are all hateful. now
it is mule manure. in a few months it will be something else. sounds
like someone with a very small vocabulary.

go away. you say you are annoyed by us, so why do you stay? no one is
interested in your rantings or bad code.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 10 Oct 2000 20:15:40 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Reading a whole file into a string
Message-Id: <39E3DB5C.F114A963@stomp.stomp.tokyo>

Uri Guttman ignorantly rants:
 
> > Godzilla! well exemplifies what he doesn't understand:


(snipped)


I am quite convinced you are psychotically obsessed with me.


Godzilla!


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

Date: Tue, 10 Oct 2000 21:13:28 -0600
From: "Duke Normandin" <01031149@3web.net>
Subject: Re: Reading a whole file into a string
Message-Id: <c_QE5.3573$Jd4.43724@jekyl.ab.tac.net>

Godzilla! wrote in message <39E3B9DF.6F6AE374@stomp.stomp.tokyo>...

>Clearly this is a woman's job, a task for a woman
>who both understands and knows how to use local ()
>correctly and effectively.


Godzilla rules....!!!


[snip the script for brevity and global peace]

-duke



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4577
**************************************


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