[25281] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7526 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 16 14:10:46 2004

Date: Thu, 16 Dec 2004 11:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 16 Dec 2004     Volume: 10 Number: 7526

Today's topics:
    Re: replace multiple lines in a file with Perl <tzhai2002@yahoo.com>
    Re: replace multiple lines in a file with Perl <tzhai2002@yahoo.com>
    Re: replace multiple lines in a file with Perl <mritty@gmail.com>
    Re: replace multiple lines in a file with Perl <tzhai2002@yahoo.com>
    Re: replace multiple lines in a file with Perl <noreply@gunnar.cc>
    Re: replace multiple lines in a file with Perl <nobull@mail.com>
    Re: replace multiple lines in a file with Perl <mritty@gmail.com>
    Re: Restricted Subsets of Perl <nobull@mail.com>
        stand alone executable using pp doesn't stand alone (Plotinus)
    Re: stand alone executable using pp doesn't stand alone <1usa@llenroc.ude.invalid>
    Re: Static Code Analysis Tools? (Randal L. Schwartz)
    Re: Static Code Analysis Tools? <emschwar@pobox.com>
    Re: use external files as "HERE-docs" (and avoid the un <nobull@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 16 Dec 2004 08:50:45 -0800
From: "learner" <tzhai2002@yahoo.com>
Subject: Re: replace multiple lines in a file with Perl
Message-Id: <1103215845.542104.234910@c13g2000cwb.googlegroups.com>

Well, did you read my first post, I did include a 'short and complete
program *that you can run*'.



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

Date: 16 Dec 2004 09:03:10 -0800
From: "learner" <tzhai2002@yahoo.com>
Subject: Re: replace multiple lines in a file with Perl
Message-Id: <1103216590.891512.109180@f14g2000cwb.googlegroups.com>

OK, here is what I actually need to do. we have this big program
project that has many source code files, and I want to replace the old
copyright notice that is included in many files with a new one.

The old one looks something like this:

//	 									MyBigBuckSoft
//
//					Laboratory for Applications of Land Surveying
//									XXXYYY PPPPPP
//								West xxxxyyyyy, XX 55555
//								 Copyright (1988-2004)
//								=A9 Xxxyyy RKKKKK Foundation
//									All rights reserved.

Then I will need to replace it with a new one across multiline. If you
could, please try to replace this old txt to see if you get the same
kind of weird result as I did. I am not sure if that 'copyright' symbol
is the reason?!



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

Date: Thu, 16 Dec 2004 17:06:13 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: replace multiple lines in a file with Perl
Message-Id: <9gjwd.10471$t44.5081@trndny03>

"learner" <tzhai2002@yahoo.com> wrote in message
news:1103215845.542104.234910@c13g2000cwb.googlegroups.com...
> Well, did you read my first post, I did include a 'short and complete
> program *that you can run*'.

Oh, okay, let me go run that file....

Can't open output file name.of.file.with.original.txt

Gee.  Doesn't work.

Posting a file that can be run, when dependent on external data,
requires the use of the __DATA__ marker.  We don't have any sample input
data with which to run your program.

Please (re-)read the Posting guidelines, paying attention to the section
labeled "Provide enough information"

Paul Lalli



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

Date: 16 Dec 2004 09:41:28 -0800
From: "learner" <tzhai2002@yahoo.com>
Subject: Re: replace multiple lines in a file with Perl
Message-Id: <1103218888.568856.289030@z14g2000cwz.googlegroups.com>

Ok, Please do these steps to run the program I posted:
1. copy and paste the perl program into an .pl file, say it is 'rep.pl'
2. in the same directory, create a new directory called 'changed'
3. create a new file with whatever name you want, say it is called
'oldtxt', which contains the oldtxt that you like to replace (the same
txt listed in the program)
4. then you issue command :

perl rep.pl oldtxt
to run it.
Hope this will help, and see if you can help me out in return. Thanks.



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

Date: Thu, 16 Dec 2004 19:05:14 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: replace multiple lines in a file with Perl
Message-Id: <32e23rF3l399fU1@individual.net>

learner wrote:
> OK, here is what I actually need to do. we have this big program
> project that has many source code files, and I want to replace the old
> copyright notice that is included in many files with a new one.
> 
> The old one looks something like this:
> 
> //	 									MyBigBuckSoft
> //
> //					Laboratory for Applications of Land Surveying
> //									XXXYYY PPPPPP
> //								West xxxxyyyyy, XX 55555
> //								 Copyright (1988-2004)
> //								© Xxxyyy RKKKKK Foundation
> //									All rights reserved.
> 
> Then I will need to replace it with a new one across multiline. If you
> could, please try to replace this old txt to see if you get the same
> kind of weird result as I did. I am not sure if that 'copyright' symbol
> is the reason?!

No, the copyright character is not special in regular expression 
patterns, but parentheses are, so they need to be escaped. You can do 
this when assigning the $original variable:

     Copyright \\(1988-2004\\)

but the easiest way to deal with it is to use \Q:

     s/\Q$original/$replacement/g

Please see "perldoc perlre".

HTH

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 16 Dec 2004 18:43:41 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: replace multiple lines in a file with Perl
Message-Id: <cpskn7$m4t$1@sun3.bham.ac.uk>



learner wrote:

> Ok, Please do these steps to run the program I posted:
> 1. copy and paste the perl program into an .pl file, say it is 'rep.pl'
> 2. in the same directory, create a new directory called 'changed'
> 3. create a new file with whatever name you want, say it is called
> 'oldtxt', which contains the oldtxt that you like to replace (the same
> txt listed in the program)
> 4. then you issue command :

There's only one of you, there are many people who may want to see if 
they help you.  As such it is more efficient for you (one person) do 
take the steps necessary to produce a mimimal but complete 
(self-contained) test case rather than for everyone else to have to take 
these steps.



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

Date: Thu, 16 Dec 2004 18:55:03 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: replace multiple lines in a file with Perl
Message-Id: <bSkwd.3540$ag6.127@trndny07>

"learner" <tzhai2002@yahoo.com> wrote in message
news:1103218888.568856.289030@z14g2000cwz.googlegroups.com...

> Ok, Please do these steps to run the program I posted:

Explain to me why you believe I (or any other potential reader of this
group) should have to follow *your* instructions?  YOU are the one
asking for help.  WE are the ones generously donating our time and
effort for the chance of helping YOU.  That means you do things the way
WE ask you to.   And *that* means following the Posting Guidelines.

Paul Lalli



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

Date: Thu, 16 Dec 2004 18:13:15 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Restricted Subsets of Perl
Message-Id: <cpsiu5$laa$1@sun3.bham.ac.uk>

Andy Glew wrote:

>>Be aware - Safe is flawed.  The best known way to escape a Safe
>>compartment involves returning blessed values.  This can easily be
>>avoided by disabling the bless opcode.  Similarly it's probably a good
>>idea to disable the tie opcode.  However there are probably other less
>>well known exploits.
> 
> 
> That's what I was worried about.
> 
> I'm guessing that the blessing and tie'ing use paths which are
> relative to the Safe compartment, but which get exported, and
> interpreted relative to the true Root.

Actually that's not the case (I made the same mistake myself when I 
first started looking for weaknesses in Safe).

But there is still a security hole because if the code within the safe 
compartment returns a value that is blessed into a package with a 
DESTROY then that destructor will be called with the true symbol table 
root accessible.

> Unfortunately, the design I came up with for an extensible config file
> involved allowing the user inside the Safe to do objects... 

To be really safe you should have a SUID helper and a chroot() :-)

> If I understand you correctly, the problem with Safe is not that the
> Safe code can reach out, but that the Safe code can return a data
> structure that is a Trojan Horse, which when used by the outside world
> feeds stuff back into the compartment.

That is the nature of the exploits I'm aware of.  They can be avoided by 
simply disabling the bless opcode (and I'd do the tie opcode too, even 
though I don't know how to exploit it).

I am also aware that a lot of people say there are other types exploits 
that are possible with Safe.

> I.e. the problem that I understand seems to be that you have to
> validate very carefully the values returned from Safe. I can even,
> possibly, imagine that there is no way to do such validation,
> if everything is tied. I don't know how much can be tied.
> 
> But if you ignore the return value, are you safe?

No.  It still gets destroyed outside the safe compartment.  The same may 
apply to blessed $@.

> Ignoring the return value wouldn't be terribly useful.  Can you query
> the contents of the Safe, without executing tied code or the like?

Yes.  You can wrap the user-supplied code with more code that is 
executed inside the safe compartment simply stringifies the result.

> Or is it a more general problem?  the code inside the Safe can get
> access to the outside world even without fooling the outside world to
> execute tied code or the like?  That would be just a bug in Safe.

As I said, there are respected people who say there are such bugs in Safe.

For a look at how I've tried to work-round some of the more obvious 
problems with Safe, take a look at String::Interpolate.



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

Date: 16 Dec 2004 08:10:08 -0800
From: mayes.s@ucles.org.uk (Plotinus)
Subject: stand alone executable using pp doesn't stand alone
Message-Id: <70c9b66a.0412160810.7c2be083@posting.google.com>

Hi,

just trying to convert a perl script into .exe using pp (part of PAR).
  Currently using a test script but no matter what script I use I get
the same error message...

Here is the script...

===============================================================================

#!/usr/bin/perl

# Created on 01-Sep-2004 12:29:29

use strict;
use Tk;
use Diagnostics;

use vars qw/ $bstream $cie_rb $esol_rb $ocr_rb $mr_rb /;

my $bstream; my $t_pc;
# End of Code

================================================================================
I ran the command "pp -o li3.exe li3.pl" to create the stand alone
executable but when I run it the error message is...


"couldn't find diagnostic data in
D:\cpanrun\build\5-8-0\lib/pods/perldiag.pod CODE(0xe336d0)
CODE(0xd3a158) . li3.exe at C:/Perl/lib/Diagnostics.pm line 249,
<POD_DIAG> line 24739.
Compilation failed in require at script/li2.pl line 7, <POD_DIAG> line
24739.
BEGIN failed--compilation aborted at script/li2.pl line 7, <POD_DIAG>
line 24739"

================================================================================

Now I removed the line "use diagnostics" and "use strict", no
improvement
I tried -M perldiag.pod and -l c:\perl\lib\pod\perldiag.pod no
improvement
I also tried -M diagnostics but then I get a whole new error message
(not including this as I suspect it is a red herring to the problem)

Thanks in advance

Plotinus


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

Date: 16 Dec 2004 16:37:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: stand alone executable using pp doesn't stand alone
Message-Id: <Xns95C17639E389Basu1cornelledu@132.236.56.8>

mayes.s@ucles.org.uk (Plotinus) wrote in
news:70c9b66a.0412160810.7c2be083@posting.google.com: 

> Hi,
> 
> just trying to convert a perl script into .exe using pp (part of PAR).
>   Currently using a test script but no matter what script I use I get
> the same error message...
> 
> Here is the script...

 ...

> #!/usr/bin/perl
> 
> # Created on 01-Sep-2004 12:29:29
> 
> use strict;
> use Tk;
> use Diagnostics;

The name of the package is diagnostics. Case matters.

Sinan


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

Date: 16 Dec 2004 08:00:03 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Static Code Analysis Tools?
Message-Id: <1103213007.12d222c874a81ccda2c36336a463f5ec@teranews>

>>>>> "Eric" == Eric Schwartz <emschwar@pobox.com> writes:

Eric> I was searching through CPAN today for a module that would generate a
Eric> static call tree, but couldn't seem to find one (lots of dynamic call
Eric> tree generators, though!).  I'm less concerned with code coverage at
Eric> this point; I'm looking for a module (or tool) that will help me
Eric> refactor code by easily showing me who calls, say, MyMod::Foo.

Eric> Does anyone know of such a thing?

Does B::Xref fit?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 16 Dec 2004 10:00:31 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Static Code Analysis Tools?
Message-Id: <eto1xdqyy8g.fsf@wilson.emschwar>

merlyn@stonehenge.com (Randal L. Schwartz) writes:
>>>>>> "Eric" == Eric Schwartz <emschwar@pobox.com> writes:
> Eric> I was searching through CPAN today for a module that would generate a
> Eric> static call tree, but couldn't seem to find one (lots of dynamic call
> Eric> tree generators, though!).  I'm less concerned with code coverage at
> Eric> this point; I'm looking for a module (or tool) that will help me
> Eric> refactor code by easily showing me who calls, say, MyMod::Foo.
>
> Eric> Does anyone know of such a thing?
>
> Does B::Xref fit?

I think it can be made to-- thanks!  It looks like it's intended to be
run on a program, and recursively descend down its call-tree, yes?
Which isn't a problem, I think-- if I have a sub in a module that
doesn't appear after running that code over all my executables, then
clearly that sub can be moved anywhere (or preferably, deleted).

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Thu, 16 Dec 2004 14:08:20 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: use external files as "HERE-docs" (and avoid the undefined substitions)
Message-Id: <cps4j8$e40$1@sun3.bham.ac.uk>

dede wrote:

> Hello friends of the community,
> 
> find below the solution I am currently using to load external
> text-files that
> are seamlessly interpolated to behave like the useful HERE-docs:
> 
> echo <<"EOT";
> Hello $strWorld ...
> EOT
> 
> SNIPPET:
> 
> while (<$handle>) {
> $_ =~ s/(\$\S+)/defined eval($1) ? eval($1) : $1/gsxe;

This is unduely messy and complicated.

By using \S+ you expose yourself to all the dangers of eval().

By not using a single eval() of a here-doc you make the syntax of the 
files unnecessarily un-Perl like.

If you have already accepted all the costs of using eval() you may as 
well get all the beniefit.

my $text = do { local $/; <$handle> };
chop ( $text = eval "<<__END__\n$text\n__END__" );

This, of course, assumes that you can reasonably slurp the whole file.

Although as Tad points out it may be better simply to make the files 
real Perl files and do() or require() them.

I should add that you may even want to make the template be the actual 
Perl scripts and make them use your module.

> Note that the defined eval (...) is necessary in order to return values
> that Perls likes to interpret as FALSE (eg. '' or 0).

Why not simply switch off the warning?

> Any comments / immprovements are welcome.

You are inventing yet another templating system.

Perl already has two built-in templating systems (here-docs and formats) 
and others on CPAN.  You should think hard before you invent another.



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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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