[16146] in Perl-Users-Digest
Perl-Users Digest, Issue: 3558 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 15:57:44 2000
Date: Mon, 10 Jul 2000 12:57:31 -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: <963259051-v9-i3558@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 10 Jul 2000 Volume: 9 Number: 3558
Today's topics:
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) (Bart Lateur)
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) (Abigail)
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) (Abigail)
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) (Bart Lateur)
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) (Abigail)
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) <bcaligari@shipreg.com>
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) (Abigail)
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) <Magic@mattnet.freeserve.co.uk>
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) <lr@hpl.hp.com>
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) <Magic@mattnet.freeserve.co.uk>
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) (NP)
Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!) <Magic@mattnet.freeserve.co.uk>
Re: date conversions... <abe@ztreet.demon.nl>
DBD::Sybase rsuter@i-2000.com
Dealing with #!/crazy/location/perl <kj0@mailcity.com>
Re: Dealing with #!/crazy/location/perl (Gwyn Judd)
Re: Dealing with #!/crazy/location/perl <bwalton@rochester.rr.com>
Re: Dealing with #!/crazy/location/perl (David Efflandt)
Re: Dealing with #!/crazy/location/perl <dburch@teleport.com>
Re: Dealing with #!/crazy/location/perl (Neil Kandalgaonkar)
Re: Dealing with #!/crazy/location/perl (Neil Kandalgaonkar)
Re: Debugging Memory Usage <adetalabi@clara.co.uk>
Re: Debugging Memory Usage <jason.holland@dial.pipex.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 04 Jul 2000 12:05:23 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <3964d123.16376492@news.skynet.be>
Magic wrote:
>> It can delete the user's harddisk. Just look at the Loveletter virus
>>for a simple example.
>
>The LoveLetter virus was VBScript not JavaScript.
You're absolutely right. I'm sorry I didn't mention that. What I wanted
to demonstrate, is that if you move from server side to client side
scripting, you'll also shift the security dangers towards the client's
side. The Loveletter virus was an example of *that*.
>VBScript is
>Microsoft's very open insecure code which allowed far more than that
>to be done to your machine. Javascript does not have these loopholes
>in security.
I have no doubt that Javascript is better with regards to security
problems, but I'm not absolutely convinced that it's 100% safe.
Microsoft has taken absolutely no security precautions at all. That's
how all this could happen, with presumably an extremely simple script.
The door is wide open to the whole world.
These kinds of problems will make a large part of users turn of client
side scripting. The net result is that a pure Javascript solution won't
do.
Now, this kind of problems you may expect on the server side too, but in
a far lesser degree. In addition, Perl's taint mode helps in preventing
unexpected holes, but it's far from perfect. If you say "this piece of
data is alright", Perl won't contradict you.
--
Bart.
------------------------------
Date: 04 Jul 2000 14:53:33 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <slrn8m4dn3.59a.abigail@alexandra.delanet.com>
Bart Lateur (bart.lateur@skynet.be) wrote on MMCDXCIX September MCMXCIII
in <URL:news:3964d123.16376492@news.skynet.be>:
:)
:) I have no doubt that Javascript is better with regards to security
:) problems, but I'm not absolutely convinced that it's 100% safe.
:) Microsoft has taken absolutely no security precautions at all. That's
:) how all this could happen, with presumably an extremely simple script.
:) The door is wide open to the whole world.
It should be said that there's nothing Microsoft specific in the
Loveletter virus attack. All that is required is having client programs
do something on a specific MIME type. Unix programs do that too. They
typically look in $HOME/.mailcap and /etc/mailcap to see what to do. Else,
they fall back on some default behaviour. There's nothing in Unix that
prevents you from bad thing happening to you.
Once Unix becomes as popular as Windows, people *will* want their mailers
and browsers automatically show/play/execute whatever is send to them.
The only reason Unix is safe from attacts like this is that Unix is far
less popular (so there's less fun for the author), and its users are
less eager to have all the fluff. But that's changing...
Abigail
--
perl -MNet::Dict -we '(Net::Dict -> new (server => "dict.org")
-> define ("foldoc", "perl")) [0] -> print'
------------------------------
Date: 04 Jul 2000 18:01:09 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <slrn8m4omr.59a.abigail@alexandra.delanet.com>
Bart Lateur (bart.lateur@skynet.be) wrote on MMCDXCVI September MCMXCIII
in <URL:news:395dbe15.408147@news.skynet.be>:
== Randal L. Schwartz wrote:
==
== >So I just invoke
== >
== > http://www.your.server.org/yourscript?PAGE=rm+-rf+/+|
== >
== >and you say bye bye to all your files.
== >
== >Please, people. Do NOT write code that uses params directly as filenames!
==
== I'm not sure what
==
== open PAGE, "rm -rf /";
==
== is supposed to do. I don't think it will invoke rm. But you can still
== modify it do to so, I guess.
However, "rm -rf /" isn't what's being passed. "rm -rf / |" *IS*.
== Question: how safe is -e? It it safe to pass ANY string to it, or is
== there still a snake in the grass?
What do you mean? "system ('rm -rf /')" is a big snake in the grass....
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Tue, 04 Jul 2000 23:27:32 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <396271d8.289344@news.skynet.be>
Abigail wrote:
>== Question: how safe is -e? It it safe to pass ANY string to it, or is
>== there still a snake in the grass?
>
>What do you mean? "system ('rm -rf /')" is a big snake in the grass....
I mean:
$file = 'rm -rf /';
if(-e $file) {
# safe to open?
}
And I guess sysopen() won't try funny things on me either.
In a way, "Magic" is right. It's Perl's "helpfulness" in doing all sorts
of tricks, with one function call, that makes it potentially dangerous.
A different function name for a different kind of action, would have
been a lot safer.
--
Bart.
------------------------------
Date: 04 Jul 2000 19:52:17 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <slrn8m4v76.59a.abigail@alexandra.delanet.com>
Bart Lateur (bart.lateur@skynet.be) wrote on MMCDXCIX September MCMXCIII
in <URL:news:396271d8.289344@news.skynet.be>:
?? Abigail wrote:
??
?? >== Question: how safe is -e? It it safe to pass ANY string to it, or is
?? >== there still a snake in the grass?
?? >
?? >What do you mean? "system ('rm -rf /')" is a big snake in the grass....
??
?? I mean:
??
?? $file = 'rm -rf /';
?? if(-e $file) {
?? # safe to open?
?? }
??
?? And I guess sysopen() won't try funny things on me either.
??
?? In a way, "Magic" is right. It's Perl's "helpfulness" in doing all sorts
?? of tricks, with one function call, that makes it potentially dangerous.
?? A different function name for a different kind of action, would have
?? been a lot safer.
There has always been sysopen. And there's now 3-arg open.
I don't understand the problem. There isn't the slightest hint that
open() would only open files. It isn't called fopen. It ain't called
popen() either. It's open, since it does both fopen() and popen().
Abigail
--
perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
${qq$\x5F$} = q 97265646f9 and s g..g;
qq e\x63\x68\x72\x20\x30\x78$&eggee;
{eval if $a =~ s e..eqq qprint chr 0x$& and \x71\x20\x71\x71qeexcess}'
------------------------------
Date: Wed, 5 Jul 2000 07:59:15 +0200
From: "Brendon Caligari" <bcaligari@shipreg.com>
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <8jui8b$b6u$1@news.news-service.com>
yeah...it's like Perl is to unix what VBstuff is to windows
"Bart Lateur" <bart.lateur@skynet.be> wrote in message
news:396271d8.289344@news.skynet.be...
> Abigail wrote:
>
> >== Question: how safe is -e? It it safe to pass ANY string to it, or is
> >== there still a snake in the grass?
> >
> >What do you mean? "system ('rm -rf /')" is a big snake in the grass....
>
> I mean:
>
> $file = 'rm -rf /';
> if(-e $file) {
> # safe to open?
> }
>
> And I guess sysopen() won't try funny things on me either.
>
> In a way, "Magic" is right. It's Perl's "helpfulness" in doing all sorts
> of tricks, with one function call, that makes it potentially dangerous.
> A different function name for a different kind of action, would have
> been a lot safer.
>
> --
> Bart.
------------------------------
Date: 05 Jul 2000 11:27:58 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <slrn8m6m1j.ibb.abigail@alexandra.delanet.com>
Magic (Magic@mattnet.freeserve.co.uk) wrote on MMCDXCV September MCMXCIII
in <URL:news:h9solsgku5q2cggn768cka1p3cbtdee5d4@4ax.com>:
?? On 29 Jun 2000 07:11:59 -0700, merlyn@stonehenge.com (Randal L.
?? Schwartz) wrote:
??
?? > Paul> open PAGE, $page ;
??
?? Could I just added the line
??
?? $page = 'http://www.mydomain.co.uk/' + $page;
Did you try? You'd be surprised what's in $page. + adds numbers, it
doesn't concatenate strings.
?? > So I just invoke
?? >
?? > http://www.your.server.org/yourscript?PAGE=rm+-rf+/+|
?? >
?? > and you say bye bye to all your files.
??
?? Wouldn't that now try to open "http://www.mydomain.co.uk/rm+-rf+/+|"
?? and fail?
Oh, yes, it would. It would actually fail to open *ANY* file you construct
that way, unless you create a directory 'http:' with a subdirectory
called 'www.mydomain.co.uk'.
Abigail
--
perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
${qq$\x5F$} = q 97265646f9 and s g..g;
qq e\x63\x68\x72\x20\x30\x78$&eggee;
{eval if $a =~ s e..eqq qprint chr 0x$& and \x71\x20\x71\x71qeexcess}'
------------------------------
Date: Wed, 05 Jul 2000 21:35:00 +0100
From: Magic <Magic@mattnet.freeserve.co.uk>
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <hq67ms4vdcm09t4fef13l3qr4ms4rlq8rv@4ax.com>
On 05 Jul 2000 11:27:58 EDT, abigail@delanet.com (Abigail) wrote:
> Magic (Magic@mattnet.freeserve.co.uk) wrote on MMCDXCV September
MCMXCIII
> in <URL:news:h9solsgku5q2cggn768cka1p3cbtdee5d4@4ax.com>:
> ?? On 29 Jun 2000 07:11:59 -0700, merlyn@stonehenge.com (Randal L.
> ?? Schwartz) wrote:
> ??
> ?? > Paul> open PAGE, $page ;
> ??
> ?? Could I just added the line
> ??
> ?? $page = 'http://www.mydomain.co.uk/' + $page;
>
> Did you try? You'd be surprised what's in $page. + adds numbers, it
> doesn't concatenate strings.
Yes, and I found this works instead...
$page = '/usr/home/myusername/public_html/$page';
Or at least it seemed to. I did however advance from that and strip
out all the ".." and "|" symbols.
>
> ?? > So I just invoke
> ?? >
> ?? > http://www.your.server.org/yourscript?PAGE=rm+-rf+/+|
> ?? >
> ?? > and you say bye bye to all your files.
> ??
> ?? Wouldn't that now try to open
"http://www.mydomain.co.uk/rm+-rf+/+|"
> ?? and fail?
>
>
> Oh, yes, it would. It would actually fail to open *ANY* file you
construct
> that way, unless you create a directory 'http:' with a subdirectory
> called 'www.mydomain.co.uk'.
Yes... I should have used the path to my HTML files rather than the
URL, which was a bit stupid and explains why it didn't work. :o)
Magic ==|:o)
--
Location : Portsmouth, England, UK
Homepage : http://www.mattnet.freeserve.co.uk
EMail : mailto:Magic@mattnet.freeserve.co.uk
------------------------------
Date: Wed, 5 Jul 2000 13:53:20 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <MPG.13cd401c191591f298abae@nntp.hpl.hp.com>
[Removed alt.perl.]
In article <hq67ms4vdcm09t4fef13l3qr4ms4rlq8rv@4ax.com> on Wed, 05 Jul
2000 21:35:00 +0100, Magic <Magic@mattnet.freeserve.co.uk> says...
...
> ... I found this works instead...
>
> $page = '/usr/home/myusername/public_html/$page';
>
> Or at least it seemed to.
Seemed to? Only if those single-quotes were really double-quotes.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 06 Jul 2000 01:07:18 +0100
From: Magic <Magic@mattnet.freeserve.co.uk>
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <dbj7mso5uc9tduqmeghac7jbklmhjcjam9@4ax.com>
On Wed, 5 Jul 2000 13:53:20 -0700, Larry Rosler <lr@hpl.hp.com> wrote:
> [Removed alt.perl.]
>
> In article <hq67ms4vdcm09t4fef13l3qr4ms4rlq8rv@4ax.com> on Wed, 05
Jul
> 2000 21:35:00 +0100, Magic <Magic@mattnet.freeserve.co.uk> says...
>
> ...
>
> > ... I found this works instead...
> >
> > $page = '/usr/home/myusername/public_html/$page';
> >
> > Or at least it seemed to.
>
> Seemed to? Only if those single-quotes were really double-quotes.
They were, lol
Magic ==|:o)
--
Location : Portsmouth, England, UK
Homepage : http://www.mattnet.freeserve.co.uk
EMail : mailto:Magic@mattnet.freeserve.co.uk
------------------------------
Date: Thu, 06 Jul 2000 14:56:37 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <F6195.309974$VR.4637217@news5.giganews.com>
On Wed, 05 Jul 2000 21:35:00 +0100, Magic <Magic@mattnet.freeserve.co.uk> wrote:
:
: Yes, and I found this works instead...
:
: $page = '/usr/home/myusername/public_html/$page';
It does?
#!/usr/local/bin/perl -w
my $page = 'foo.html';
$page = '/blah/blah/$page';
print("$page\n");
$ perl test.prl /blah/blah/$page
/blah/blah/$page
Or when you were typing in that code, did you have a typo?
-- Nate
------------------------------
Date: Sun, 09 Jul 2000 22:54:47 +0100
From: Magic <Magic@mattnet.freeserve.co.uk>
Subject: Re: DANGEROUS CODE ABOVE (was Re: Perl Help Please!)
Message-Id: <f4thms8hvdk51c9esm505a19bpgenoj76t@4ax.com>
On Thu, 06 Jul 2000 14:56:37 GMT, nvp@spamnothanks.speakeasy.org (NP)
wrote:
> On Wed, 05 Jul 2000 21:35:00 +0100, Magic
<Magic@mattnet.freeserve.co.uk> wrote:
> :
> : Yes, and I found this works instead...
> :
> : $page = '/usr/home/myusername/public_html/$page';
>
> It does?
>
> #!/usr/local/bin/perl -w
>
> my $page = 'foo.html';
> $page = '/blah/blah/$page';
>
> print("$page\n");
>
> $ perl test.prl /blah/blah/$page
> /blah/blah/$page
>
> Or when you were typing in that code, did you have a typo?
>
> -- Nate
I have this annoying habit of using the wrong type of quotes...
Magic ==|:o)
--
Location : Portsmouth, England, UK
Homepage : http://www.mattnet.freeserve.co.uk
EMail : mailto:Magic@mattnet.freeserve.co.uk
------------------------------
Date: Tue, 04 Jul 2000 22:11:07 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: date conversions...
Message-Id: <c762ms893v8q77u8oe68us5k27se73lc5j@4ax.com>
On Fri, 30 Jun 2000 16:47:34 -0600, "Kris" <kaweed@micron.com> wrote:
> hello-
hi,
> I'm looking for some type of algorithm or code snippet (even an idea of
> a direction to go in) on creating a numerical list from a dated list. I'm
> using a plotting program to plot some dates, but it won't accept dates in
> the format I have. So what I need to do is convert each date into a number.
> So, if I convert the first date in the file to a 1 (say it's 3/30/2000) then
> I need to convert 3/31/2000 to 2, and 4/1/2000 to 3, and so on. Any ideas
> on how to do this? The other problem I have is that there are often
> re-ocurring dates and they aren't all in order, so I need all instances of
> 4/1/2000 throughout the file to be a 3. A bit confusing and tailored I
> know, but I thought I'd see if anyone had any ideas?
Your specs are not complete. What should '4/2/2000' return?
You could use the 'yyyymmdd' date format. It is sortable and even
readable:
my $date = '3/30/2000';
my $new_date = sprintf "%d%02d%02d",
(split m!/!, $date)[2, 0, 1];
print "$date -> $new_date\n";
--
Good luck,
Abe
------------------------------
Date: Fri, 07 Jul 2000 20:53:10 GMT
From: rsuter@i-2000.com
Subject: DBD::Sybase
Message-Id: <8k5fvh$68h$1@nnrp1.deja.com>
I'm trying to use DBD::Sybase in Win32, but can't get past connect.
I use:
use DBI;
my $dbh = DBI->connect( 'dbi:Sybase:server = mcare_unix_11',
'myname', 'mypassword' )
or die "Can't connect: $DBI::errstr\n";
and only get the result:
Error: Runtime exception
I haven't found any info on this error message. The sybase home
directory is on a networked drive, on another NT server. Sybase itself
is on a HP unix box. Other Sybase client library applications run
successfully.
Other perl scripts work sucessfully. The 'DBI->available drivers'
reports that the Sybase driver is available.Can anyone enlighten me? Is
perl or DBD installed wrong?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 9 Jul 2000 20:34:00 -0400
From: kj0 <kj0@mailcity.com>
Subject: Dealing with #!/crazy/location/perl
Message-Id: <8kb5lo$m14$1@panix3.panix.com>
Whenever I transfer my perl scripts to a new system, I have to go
through this stupid ritual of changing the hash-bang first-lines to
the correct perl location for that site. This is a pain, even when
it's done with the aid of a script (which itself must be done "by
hand").
The obvious solution would be to define an environment variable PERL
containing Perl's location (something in the spirit of setenv PERL
`which perl`), so that all scripts can start with #!$PERL [flags...].
The only problem with this is that it doesn't work.
Is there a way?
KJ
------------------------------
Date: Mon, 10 Jul 2000 03:15:20 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Dealing with #!/crazy/location/perl
Message-Id: <slrn8mig3f.19m.tjla@thislove.dyndns.org>
I was shocked! How could kj0 <kj0@mailcity.com>
say such a terrible thing:
>
>
>
>Whenever I transfer my perl scripts to a new system, I have to go
>through this stupid ritual of changing the hash-bang first-lines to
>the correct perl location for that site. This is a pain, even when
>it's done with the aid of a script (which itself must be done "by
>hand").
>
>The obvious solution would be to define an environment variable PERL
>containing Perl's location (something in the spirit of setenv PERL
>`which perl`), so that all scripts can start with #!$PERL [flags...].
>The only problem with this is that it doesn't work.
>
>Is there a way?
#!env perl
seems to work okay for me
--
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
The lunatic, the lover, and the poet,
Are of imagination all compact...
-- Wm. Shakespeare, "A Midsummer Night's Dream"
------------------------------
Date: Mon, 10 Jul 2000 03:37:45 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Dealing with #!/crazy/location/perl
Message-Id: <3969453E.981BE89B@rochester.rr.com>
kj0 wrote:
>
> Whenever I transfer my perl scripts to a new system, I have to go
> through this stupid ritual of changing the hash-bang first-lines to
> the correct perl location for that site. This is a pain, even when
> it's done with the aid of a script (which itself must be done "by
> hand").
>
> The obvious solution would be to define an environment variable PERL
> containing Perl's location (something in the spirit of setenv PERL
> `which perl`), so that all scripts can start with #!$PERL [flags...].
> The only problem with this is that it doesn't work.
>
> Is there a way?
>
> KJ
The usual method would be to install a symbolic link at some "standard"
place like maybe /usr/local/bin/perl that points to the real location of
the Perl interpreter. Alternatively, you could set up an alias if your
shell supports that. Yet a third possibility would be to put a short
shell script at /usr/local/bin/perl that fires up the Perl interpreter,
wherever it may actually be stored. Remember that something like #!perl
-w with something pointing to Perl somewhere on your path probably won't
work, since it is the kernel that processes the #! line, not a shell,
and the kernel doesn't have access to your path. If you don't have
write access to /usr/local/bin and you can't talk your sysadmin to
setting up a symbolic link, use the alias method if you shell supports
that.
--
Bob Walton
------------------------------
Date: 10 Jul 2000 11:27:54 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Dealing with #!/crazy/location/perl
Message-Id: <slrn8mjcpc.us1.efflandt@efflandt.xnet.com>
On 9 Jul 2000 20:34:00 -0400, kj0 <kj0@mailcity.com> wrote:
>
>Whenever I transfer my perl scripts to a new system, I have to go
>through this stupid ritual of changing the hash-bang first-lines to
>the correct perl location for that site. This is a pain, even when
>it's done with the aid of a script (which itself must be done "by
>hand").
>
>The obvious solution would be to define an environment variable PERL
>containing Perl's location (something in the spirit of setenv PERL
>`which perl`), so that all scripts can start with #!$PERL [flags...].
>The only problem with this is that it doesn't work.
>
>Is there a way?
Did you happen to know that Perl is good for modifying text? Write a perl
script that recursively goes through the directory tree starting at a
specified path (see opendir and readdir) and updates the shebang line, if
it contains perl:
if (-T $file) {
if (open(FILE,"$file")) {
@lines = <FILE>;
close FILE;
print "Checking $file\n$lines[0]";
if ($lines[0] =~ s/^(#!\s*)([^p]*perl[\S]*)/$1$newpath/i) {
print "$lines[0]";
if (open(FILE,"> $file")) {
print FILE @lines;
close FILE;
print "Updated $file\n";
} else {
print "Can't update perl file $file: $!\n";
}
} else {
print "Skipping non-perl file $file\n"
}
} else {
print "Can't read text file $file: $!\n";
}
} else {
print "Skipping non-text file $file\n";
}
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/ http://cgi-help.virtualave.net/
------------------------------
Date: Mon, 10 Jul 2000 07:19:28 -0700
From: Dan Burch <dburch@teleport.com>
Subject: Re: Dealing with #!/crazy/location/perl
Message-Id: <3969DB70.8879194@teleport.com>
> The obvious solution would be to define an environment variable PERL
> containing Perl's location (something in the spirit of setenv PERL
> `which perl`), so that all scripts can start with #!$PERL [flags...].
> The only problem with this is that it doesn't work.
>
> Is there a way?
>
> KJ
It works on win32. Just put SET PATH=C:\Perl\bin\ in your autoex.bat
DB
------------------------------
Date: Mon, 10 Jul 2000 16:15:32 GMT
From: neil@brevity.org (Neil Kandalgaonkar)
Subject: Re: Dealing with #!/crazy/location/perl
Message-Id: <8kcsf4$l8m$1@localhost.localdomain>
In article <slrn8mjcpc.us1.efflandt@efflandt.xnet.com>,
David Efflandt <efflandt@xnet.com> wrote:
>On 9 Jul 2000 20:34:00 -0400, kj0 <kj0@mailcity.com> wrote:
>>
>>This is a pain, even when
>>it's done with the aid of a script (which itself must be done "by
>>hand").
>Did you happen to know that Perl is good for modifying text? Write a perl
>script
Golly, someone's mommy forgot to teach them manners AND how to read.
>that recursively goes through the directory tree starting at a
>specified path (see opendir and readdir)
See File::Find.
The script you posted is replete with common errors. Given that you're
acting like a know-it-all this isn't a good idea. Unless you're just
trying to raise everyone's ire.
>and updates the shebang line, if
>it contains perl:
>
> if (-T $file) {
> if (open(FILE,"$file")) {
tests for success, but does not warn right away. The error message is in
an else block located many lines below. It would be a lot easier to use
the standard
open FILE, "< $file" or print STDERR "couldn't open $file: $!"
BTW, "$file" is unnecessary stringification... of course it would be
useful if you protected yourself with "< $file" (or '<', $file in 5.6).
> @lines = <FILE>;
Wasteful slurp. Not running under strict.
> close FILE;
> print "Checking $file\n$lines[0]";
Should be printing messages to STDERR.
> if ($lines[0] =~ s/^(#!\s*)([^p]*perl[\S]*)/$1$newpath/i) {
Fails on the common /opt/... location for perl. That [^p] is nasty.
I would trust perl's backtracking.
> print "$lines[0]";
Unnecessary stringification.
> if (open(FILE,"> $file")) {
> print FILE @lines;
> close FILE;
> print "Updated $file\n";
> } else {
> print "Can't update perl file $file: $!\n";
> }
> } else {
> print "Skipping non-perl file $file\n"
> }
> } else {
> print "Can't read text file $file: $!\n";
> }
> } else {
> print "Skipping non-text file $file\n";
> }
Yeesh. Do you find this easy to read?
Perl has such nice syntactical sugar to avoid having to do this.
Or you could just do:
$ find . -type f -exec
perl -pi.bak -e 's{^#!.*perl}{#!/path/to/perl} if $. == 1' {} \;
Except you end up with a lot of unnecessary .bak files.
This one is more efficient and selects only for perl files (works on
my RH linux 6.2 box):
$ find . -type f | file -f - | grep 'perl commands text' \
| awk '{ print $1 }' | sed 's/:$//' \
| xargs perl -pi.bak -e \
's{^#!.*perl}{#!/path/to/perl} if $. == 1;
close ARGV if eof'
--
Neil Kandalgaonkar <neil@brevity.org>
------------------------------
Date: Mon, 10 Jul 2000 16:28:41 GMT
From: neil@brevity.org (Neil Kandalgaonkar)
Subject: Re: Dealing with #!/crazy/location/perl
Message-Id: <8kct7j$lan$1@localhost.localdomain>
In article <8kcsf4$l8m$1@localhost.localdomain>,
Neil Kandalgaonkar <neil@brevity.org> wrote:
> $ find . -type f | file -f - | grep 'perl commands text' \
> | awk '{ print $1 }' | sed 's/:$//' \
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Better: eliminates the awk & allows for filenames with spaces:
| sed 's/:[^:]*$//'
> | xargs perl -pi.bak -e \
> 's{^#!.*perl}{#!/path/to/perl} if $. == 1;
> close ARGV if eof'
--
Neil Kandalgaonkar <neil@brevity.org>
------------------------------
Date: Tue, 04 Jul 2000 12:36:03 +0100
From: Ade Talabi <adetalabi@clara.co.uk>
Subject: Re: Debugging Memory Usage
Message-Id: <3961CC23.EB79053@clara.co.uk>
Jason Holland wrote:
>
> Hello all,
>
> I've run into a problem quite recently with tracking memory usage in
> Perl.
>
> Essentially, I've built a system where a hierarchy of linked Perl
> objects are created. It's actually a DOM implementation, and the number
> of objects allocated in a tree can be extremely large.
>
> Because of the way that the tree structure is built, each of the node
> objects stores a reference to it's parent and child nodes. Because of
> this I believe that some circular references may have been introduced.
> I've carefully written a destructor for each object that breaks any
> references but it's quite hard seeing if this is being done properly or
> not.
>
> Part of the system is used in a batch environment, and can quite easily
> use several hundred megabytes of RAM!
>
> I've already checked out CPAN, the DProf module, which is very nice, and
> looked through the documentation for the Debugger; but there doesn't
> seem to be much in the way of tools for tracking memory usage.
>
> What I would like would be a module, similar to DProf, that would tell
> me what each package was allocating; and more importantly what was not
> being released upon object destruction and at exit.
>
> Incidentally, I'm just about to try the GNU ddd debugger, which may or
> may not do what I want. It's probably overkill though ;-)
>
> Any ideas?
>
> Thanks in advance!
>
> Jason
>
> --
> "A Jedi craves not these things."
>
> Yoda
You can incoporate in to your perl script 'dmesg| grep mem' to roughly
work out how mumch mem each module is eating up.
--
We see, whatever we want to see, whether visible or not
- AT. June 2000.
------------------------------
Date: Tue, 04 Jul 2000 20:30:05 +0000
From: Jason Holland <jason.holland@dial.pipex.com>
Subject: Re: Debugging Memory Usage
Message-Id: <3962494D.BB57625E@dial.pipex.com>
> Jason Holland wrote:
> >
> > Hello all,
> >
> > I've run into a problem quite recently with tracking memory usage in
> > Perl.
Ade Talabi wrote:
> You can incoporate in to your perl script 'dmesg| grep mem' to roughly
> work out how mumch mem each module is eating up.
Oops! Sorry Ade, but I don't think I phrased that quite right.
I'm not so much concerned with _how much_ memory each module is using,
but more memory that is not being released properly.
Essentially, each class creates objects that contain a lot of circular
references, I'm finding it quite a chore tracking down where memory is
being deallocated amongst those objects.
What I would like is a debugger module that tells me what each class
alloctates and deallocates, so I can see where memory is not being
released properly.
Thanks!
Jason
--
"A Jedi craves not these things."
Yoda
------------------------------
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 3558
**************************************