[18813] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 981 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 24 21:11:15 2001

Date: Thu, 24 May 2001 18:10:15 -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: <990753015-v10-i981@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 24 May 2001     Volume: 10 Number: 981

Today's topics:
    Re: Question on the "use strict" pragma <leapius@hotmail.com>
    Re: Question on the "use strict" pragma <godzilla@stomp.stomp.tokyo>
    Re: Question on the "use strict" pragma <ahamm.NO$PAM@sanderson.NO$PAM.net.au>
    Re: Search and replace text in a file based on a specif <drobert@caissepop.mb.ca>
    Re: Search and replace text in a file based on a specif <ren@tivoli.com>
    Re: Search and replace text in a file based on a specif <uri@sysarch.com>
    Re: setting priority from perl on linux <dball@bnb-lp.com>
    Re: sounder <thunderbear@bigfoot.com>
    Re: Win32::OLE -> How to query a Microsoft Catalog <skilchen@swissonline.ch>
    Re: wwwboard.pl - Taint and Use Strict (Jill)
    Re: wwwboard.pl - Taint and Use Strict <uri@sysarch.com>
    Re: wwwboard.pl - Taint and Use Strict <godzilla@stomp.stomp.tokyo>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 25 May 2001 01:27:26 +0100
From: "Leo" <leapius@hotmail.com>
Subject: Re: Question on the "use strict" pragma
Message-Id: <9ek8l3$58n$1@plutonium.btinternet.com>

Hi all,

I have a few questions regarding the "use strict" pragma:

1. Does adding use strict to my program slow it's execution down in any way?
If so would it be a good idea to use strict when developing a program and
then remove it when the code is final (so my code is syntatically correct),
or would that be pointless?

2. I am confused about how strict evaluates my code. I have a program which
"requires" a lot of other cgi scripts in it's execution. Each of these
scripts is a collection of sub-routines associated with a particular
function. The main program is where all these scripts are called. I have the
line "use strict" in this main program file and it evaluates the variables
and so forth for the contents of that file.

When I run my program, and it loads in the other cgi scripts (sub routines)
during it's operation, the use strict pragma does not seem to extend into
these other files. E.g. I have a load of sub-routines in a sepearte file
which break all the use strict rules and yet it compiles and runs ok without
any errors. Does the use strict pragma _only_  evaluate the code in the
particular file it is called? How can it evaluate all my code in the other
files?

3. Why does this give me errors:

Main program file
====================================
#!/usr/bin/perl
use strict;
require "settings.cgi";
require "$sourcedir/subs.cgi";
====================================

settings.cgi
====================================
our $sourcedir = "./source";
====================================

Shouldn't $sourcedir be declared as a global variable in the program when it
is "required"?

Thanks for any anwers you can give me,

Leo




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

Date: Thu, 24 May 2001 17:32:36 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Question on the "use strict" pragma
Message-Id: <3B0DA824.E7AB3DCD@stomp.stomp.tokyo>

Leo wrote:
 
> I have a few questions regarding the "use strict" pragma:

(snipped)

First, I have a question. To which article are you responding?


Godzilla!


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

Date: Fri, 25 May 2001 10:56:45 +1000
From: "Andrew Hamm" <ahamm.NO$PAM@sanderson.NO$PAM.net.au>
Subject: Re: Question on the "use strict" pragma
Message-Id: <3b0dadee$1@news.iprimus.com.au>

Leo wrote in message <9ek8l3$58n$1@plutonium.btinternet.com>...
>
>1. Does adding use strict to my program slow it's execution down in any
way?
>
It's an instruction to the compiler. It may affect the speed of the initial
compilation (can't say whether it slows it down or actually speeds it up)
but it shouldn't have ANY affect at runtime. Not that I can think of.

>If so would it be a good idea to use strict when developing a program and
>then remove it when the code is final (so my code is syntatically correct),
>or would that be pointless?
>
It's pointless in the sense that a program is never correct. Don't argue -
you won't win! It's considered well-worth leaving this kind of thing so that
even in production a program is protected from itself.

Stepping away from the hard line now, in practice a simple program could be
considered correct after it seems to work properly for a while, but in the
case of Perl, removing use strict has sod-all effect on efficiency anyway
that it's not an issue.

Some languages support assertions, which are actual bits of code that
attempt to test the correctness of the state of the program as it runs. For
example, C programmers often work with ASSERT() macros, and Eiffel has a
concept of preconditions, postconditions and class assertions which are
designed to catch faults. It's fairly common to disable these testings when
you deploy a production product, but it's surprising how many fresh bugs
show up after real users start running the program.

It's probably best to leave your assertions indefinitely, even if they are
somewhat inefficient. Some pieces of code have really hard-core assertions
which very savagely test data correctness, and these are switched on by the
developers when they first develop the code, or when they get desperate
sometime further down the line.

>2. I am confused about how strict evaluates my code. I have a program which
<SNIP>
>
>When I run my program, and it loads in the other cgi scripts (sub routines)
>during it's operation, the use strict pragma does not seem to extend into
>these other files.
Yup - that's true. It's an instruction into the currently compiling file -
it's scope is local. Unlike the -w or $^W warning flag which is a runtime
setting. It often disappoints me to set -w or $^W in my script, only to have
a CPAN module raise warnings. By the way, that's the only disappointment
I've ever had from CPAN - all modules I've collected are wonderful useful
fun or all of the above.

>which break all the use strict rules and yet it compiles and runs ok
without
>any errors.
>
You can program Perl in complete violation of the use strict pragma and
still make a valid working program. It's just trickier. You are on your own
and if you make an innocent typing error or similar then you'll have no
assistance finding the bug.

 Does the use strict pragma _only_  evaluate the code in the
>particular file it is called? How can it evaluate all my code in the other
>files?
>
Put use strict at the top of each of them if you like and see what happens.
But be prepared for some modules that deliberately violate the rules because
they'll spit the dummy half-way across the room.

>3. Why does this give me errors:
>
>Main program file
>====================================
>#!/usr/bin/perl
>use strict;
>require "settings.cgi";
>require "$sourcedir/subs.cgi";
>====================================
>
>settings.cgi
>====================================
>our $sourcedir = "./source";
>====================================
>
>Shouldn't $sourcedir be declared as a global variable in the program when
it
>is "required"?
>
The "included" file is treated as it's own compilation unit. Any "our"
declarations in there are for it's own benefit. It's possible for that
module to inject a variable into another module, but require isn't the best
mechanism for that. It will only be invoked once even if you require it
several times in different places. Try using "use module" instead, and check
out the export and import options - they can be used to inject variables and
subs into the calling module.

--
"Dis act ain't about lafter - it's about comedy" - Andrew Dice Clay





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

Date: Thu, 24 May 2001 17:18:00 -0500
From: "Daniel Robert" <drobert@caissepop.mb.ca>
Subject: Re: Search and replace text in a file based on a specific line
Message-Id: <tQfP6.3723$gg2.39421@news1.mts.net>


"Michael Heiming" <michael@heiming.de> wrote in message
news:3B0D8485.D6D9375A@heiming.de...
> Daniel Robert wrote:
> [SNIP]
> >
> > PS I have tried the awk solution and, as mentionned it repeats th line
in
> > the file.
> Err. it repeats what? You wrote:
> "The original file must containt the original lines but with the changes
> we
> specified."     ^^^^^^^^^^^^^^^^^^^^
>
> That's exactly what the line awk does, I posted...

I will explain with an example.  Here is the ORIGINAL file (called
testfile):
-------------------------------------
This is test #21****line 5
Another test #ab****line 6
Second last test #xyz****line 7
Last test #&&****line 8
-------------------------------------

I run the sh script: replinfile testfile "line 8" "???? test" "Final test"
would result the testfile file be modified to:
-------------------------------------
This is test #21****line 5
Another test #ab****line 6
Second last test #xyz****line 7
Final test #&&****line 8
-------------------------------------

[SNIP]




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

Date: 24 May 2001 17:40:12 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Search and replace text in a file based on a specific line
Message-Id: <m37kz6bcc3.fsf@dhcp9-172.support.tivoli.com>

On Thu, 24 May 2001, drobert@caissepop.mb.ca wrote:

> I will explain with an example.  Here is the ORIGINAL file (called
> testfile):
> -------------------------------------
> This is test #21****line 5
> Another test #ab****line 6
> Second last test #xyz****line 7
> Last test #&&****line 8
> -------------------------------------
> 
> I run the sh script: replinfile testfile "line 8" "???? test" "Final
> test" would result the testfile file be modified to:
> -------------------------------------
> This is test #21****line 5 Another test #ab****line 6 Second last
> test #xyz****line 7 Final test #&&****line 8
> -------------------------------------

Here's a pretty lazy way:

#!/usr/bin/perl -pi.bak
BEGIN {
  ($line, $pattern, $replace) = splice @ARGV, 1, 3;
  $pattern =~ tr/?/./;
}
/$line/ and s/$pattern/$replace/g;
__END__

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 24 May 2001 23:31:28 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Search and replace text in a file based on a specific line
Message-Id: <x7u22a2uk8.fsf@home.sysarch.com>

>>>>> "DR" == Daniel Robert <drobert@caissepop.mb.ca> writes:

  DR> I am sorry if I didn't express myself very well, but here goes
  DR> again...  I want to create a sh script which will search a text
  DR> file (parameter 1) for a specific string (parameter 2).  This is
  DR> used to uniquely identify exactly which line I need modify.  The
  DR> next step is to replace FROM text that is supplied (parameter 3)
  DR> (it can contain one or more "?" (or none) as a wildcard) TO text
  DR> that is also supplied (parameter 4).  So the format would be:
  DR> replinfile textfile searchtext replacefrom replaceto

if you want shell, then why post in c.l.perl.misc?

<c.l.perl.misc removed from followups>

  DR> I hope I have provided enough information and made myself clear. ;)

  DR> PS I have tried the awk solution and, as mentionned it repeats th line in
  DR> the file.  I have also tried the perl solution and I get the errors "Can't
  DR> open line 6: No such file or directory", "Can't open test #..: No such file
  DR> or directory", and "Can't open test #www: No such file or directory".
  DR> Shouldn't you need to specify the name of the file somewhere?  I don't even
  DR> remotely know perl (only know of it) but I forsee the need to delve in it in
  DR> the future.

my mistake. it needs to remove the @ARGV values for the -p loop to
work. but since you don't even care to understand what code you are
getting or how to fix it, i won't help any more.


uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Thu, 24 May 2001 15:27:45 -0700
From: David Ball <dball@bnb-lp.com>
Subject: Re: setting priority from perl on linux
Message-Id: <2k2rgt0accdtj6mcfgub637hi585r918o6@4ax.com>

On Thu, 24 May 2001 11:58:52 +0000 (UTC), abigail@foad.org (Abigail)
wrote:

>David Ball (dball@bnb-lp.com) wrote on MMDCCCXXII September MCMXCIII in
><URL:news:h53mgtk7tpkcr8baq78mpl8r8qpuj3hcap@4ax.com>:
>@@  
>@@  Do you know of any scripts that will build an index of html pages
>@@  and then search it from a CGI ?
>
>
>Yes.
>
>
>Please use a web search to find such programs. Discussing of such programs
>(which have nothing to do with Perl) don't belong in this group, just
>like discussing your favourite brand of toilet paper doesn't.

Gee, you mean discussing perl scripts doesn't belong in a perl
newsgroup. That's just plain stupid Abigail.

-- David



>
>
>Abigail



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

Date: Fri, 25 May 2001 00:38:41 +0100
From: =?iso-8859-1?Q?Thorbj=F8rn?= Ravn Andersen <thunderbear@bigfoot.com>
Subject: Re: sounder
Message-Id: <3B0D9B81.96A0CB58@bigfoot.com>

Todd Smith wrote:

> > > Well, since Perl is the only cgi language I know, I'd like to see the
> Perl
> > > implementation of the complete solution.
> >
> > Hack the "user sign up" script to send you an email.
> >
> 
> Emails are boring! I want noise!

Hack your emailprogram to treat "user sign up" mail specially.  

How were you expecting to get your browser to say the noise you want?

-- 
  Thorbjørn Ravn Andersen                "...plus...Tubular Bells!"
  http://bigfoot.com/~thunderbear


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

Date: Fri, 25 May 2001 00:30:42 +0200
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: Win32::OLE -> How to query a Microsoft Catalog
Message-Id: <9ek2gb$3c76i$1@ID-13368.news.dfncis.de>

"Jean-Paul Cozzatti" <jcozzatti@cozzatti.com> schrieb im Newsbeitrag
news:31f3f729.0105240947.23c9e5b3@posting.google.com...
>
> I'm using activestate perl v5.6.1 build 626 on windows 2k to query a
> microsoft catalog (i.e. a catalog created by the microsoft indexing
> service)
> I would like to get some perl hooks into it so I can play with the
> index.
> Right now I'm getting the error I've included.
>
> My questions are:
>
> 1)What's causing the error...it looks related to the here-document
> like coding.

Please take a break until you see again that you used ">>" instead
"<<" to start a here-doc :-)

> 2)Is there a better way to do this using DBI::ADO...or another perl
> module.
>
I don't know.

>
> use Win32::OLE::Const ;

That should be
use Win32::OLE::Const 'Microsoft ActiveX Data Objects';
otherwise you don't get the values for things like adOpenDynamic

>
>   if (Win32::OLE->LastError) {

What is this check good for???

>       $RS->Open(>>"SQL",$Conn, adOpenDynamic);
                  ^^
You meant
        $RS->Open(<<"SQL",$Conn, adOpenDynamic);

>             select Filename from SCOPE(milcker)
>   SQL
>
Please note that you can't have any whitespace surrounding th closing
tag of the here-doc.

I don't know how to interface to the MS Index server, so i can't
comment on the rest of your posting.



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

Date: 24 May 2001 16:38:02 -0700
From: jmjlampert@aol.com (Jill)
Subject: Re: wwwboard.pl - Taint and Use Strict
Message-Id: <9287c79.0105241538.7242aaa5@posting.google.com>

My hands do not fall off.  I am amazed by the response I've got!  I
thought people would be helpful.  I would be helpful if anyone asked
me for help.

I need to "use strict" and use the "-T" switch because that is a
requirement of the ISP who provide the web space I would like to use.

When I use the "-T" switch I get a variety of error messages with line
numbers.  As I explained, I am a newby.  To be honest, I don't know
how perl calculates line numbers.  If I use Microsoft Word to
calculate the line numbers for the error messages, then I find the
references to to problem lines makes no sense.

When I use "use Strict", the script seems to hang.......or run,
without anything visible happening.

I am really just trying to find out whether anyone else has already
made this particular script (wwwboard.pl) pass Taint and Use Strict.
From reading this bulletin board it is clear that it is a very widely
used script, and so it seems to me conceivable that someone has needed
to make it pass "Taint" and "use script".

Telling me to 'do my homework' seems a bit pointless, as I've already
explained that I have tried very hard to do that by reading the perl
documentation and the relevant information in a number of different
books.  Maybe I'm just thick, but the fact is that I can't put in
these two teeny bits of code and then make the script run properly. 
I'd like to use the script (suitably modified) on my website, and I
know there are lots of people who do this sort of thing all the time,
and I suspect that for those of you who really understand these
things, it is like "falling off a log".

If you have something helpful and positive to say, I look forward to
hearing it.
Thanks 
Jill


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

Date: Thu, 24 May 2001 23:47:08 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: wwwboard.pl - Taint and Use Strict
Message-Id: <x7ofsi2ttv.fsf@home.sysarch.com>

>>>>> "J" == Jill  <jmjlampert@aol.com> writes:

  J> My hands do not fall off.  I am amazed by the response I've got!  I
  J> thought people would be helpful.  I would be helpful if anyone asked
  J> me for help.

and if you were trying to help everyon all day long and they never did
any reading or homework, would you continue?

  J> When I use "use Strict", the script seems to hang.......or run,
  J> without anything visible happening.

that module doesn't exist. module names are case sensitive

  J> I am really just trying to find out whether anyone else has already
  J> made this particular script (wwwboard.pl) pass Taint and Use
  J> Strict.  From reading this bulletin board it is clear that it is a
  J> very widely used script, and so it seems to me conceivable that
  J> someone has needed to make it pass "Taint" and "use script".

hmm, it is popular so it must be good. loks like you like redmondware
too.

someone posted he got that POS to be -w and -T clean. but he hasn't
posted it yet. and i bet it will still be a piece of shit.

  J> Telling me to 'do my homework' seems a bit pointless, as I've
  J> already explained that I have tried very hard to do that by reading
  J> the perl documentation and the relevant information in a number of
  J> different books.  Maybe I'm just thick, but the fact is that I
  J> can't put in these two teeny bits of code and then make the script
  J> run properly.  I'd like to use the script (suitably modified) on my
  J> website, and I know there are lots of people who do this sort of
  J> thing all the time, and I suspect that for those of you who really
  J> understand these things, it is like "falling off a log".

maybe you are just thick. the solution is to hire a programmer. or get a
better board program. don't use that crap. 

  J> If you have something helpful and positive to say, I look forward to
  J> hearing it.

and if you can pull the carrots out of your ears you might hear
something and possibly learn. matt's code sux. period. nothing can be
done but a complete rewrite. simple. nothing more to say. do you get it?
try another question. pick another category. this is a dead point. don't
use his code.

that is as nice as i can get when discussing that crap that is matt's
code.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Thu, 24 May 2001 17:24:24 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: wwwboard.pl - Taint and Use Strict
Message-Id: <3B0DA638.A9456EB0@stomp.stomp.tokyo>

Jill wrote:

(snipped majority of the trolling)
 
> My hands do not fall off.  I am amazed by the response I've got!  I
> thought people would be helpful.  I would be helpful if anyone asked
> me for help.

Personally, I think your head fell off.

Look at this way. You are using a fake AOL email address,
posting through google via a proxy server over in England,
claim your server requires use of strict and taint along
with your use of a trigger topic of Matt's scripts then
annoyingly add a classic troll of, "You people are so mean!"

You expect to be taken seriously?

Have I told you I have tiny blue monkeys flying out of my big butt?


Godzilla!


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

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


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