[22563] in Perl-Users-Digest
Perl-Users Digest, Issue: 4784 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 29 18:06:19 2003
Date: Sat, 29 Mar 2003 15:05:08 -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 Sat, 29 Mar 2003 Volume: 10 Number: 4784
Today's topics:
Re: And... <tore@aursand.no>
Re: CGI.pm or roll-your-own? <grazz@nyc.rr.com>
Re: CGI.pm or roll-your-own? <tore@aursand.no>
Re: CGI.pm or roll-your-own? <noreply@gunnar.cc>
Re: CGI.pm or roll-your-own? <wsegrave@mindspring.com>
Re: CGI.pm or roll-your-own? <noreply@gunnar.cc>
Re: currency number to text conversion <Jodyman@hotmail.com>
HTML::Parser questions (Mooky Mooksgill)
Re: implicit vs explicit variable usage in loop w/ rang (Tad McClellan)
Re: match except between... <istink@real.bad.com>
Re: match except between... <istink@real.bad.com>
Re: match except between... <goldbb2@earthlink.net>
Re: Multiple POSTS and GETS from one perl script <tore@aursand.no>
Re: Perl and objects <tore@aursand.no>
Re: Perl and objects <tassilo.parseval@rwth-aachen.de>
Re: Please tell me I'm beginner <tore@aursand.no>
Re: simple substitution also changes line endings (Tuang)
Re: simple substitution also changes line endings <goldbb2@earthlink.net>
suid not working <root@localhost.spam.me.not>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 29 Mar 2003 21:37:28 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: And...
Message-Id: <pan.2003.03.29.16.01.59.700694@aursand.no>
On Sat, 29 Mar 2003 06:40:07 -0600, Ami wrote:
> Excuse me, Mr. Parseval !
> It was careless.
> I'd forgot the fact it was crosspost,
> because it's been long time since my last post.
> Entschuldigen Sie, Herr Parseval !
> Es war unaufmerksam von mich.
> Volkkommen haben ich verlernt,
> denn seit meiner letzter Post viel Zeit genommen hast.
I'm very sure that Tassilo understands English. If not, why the h*ll
would he write his own messages in English?
*doh*
--
Tore Aursand
------------------------------
Date: Sat, 29 Mar 2003 21:07:23 GMT
From: Steve Grazzini <grazz@nyc.rr.com>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <fWnha.1813$Xf4.194@twister.nyc.rr.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Alan J. Flavell wrote:
>> On Sat, Mar 29, Gunnar Hjalmarsson inscribed on the eternal scroll:
>>>Actually, the fact that the module ignores querystrings
>>>is a security detail.
>>
>> Could you expand a bit on that, please?
> Bill Segrave called my attention [...] to the risk with email
> forms in general that abusers add newline characters to an email
> header field using hex encoding, and with that submit additional
> headers. We concluded that, since the module doesn't take GET
> requests, that is a non-issue in this case.
You must be mistaken.
The hole would be here [not your code]
print SENDMAIL "Subject: $form{subject}\n";
When the spammer has fed you -- via POST or GET... the type of
request is irrelevant -- something like
subject => uri_escape("Work From Home!\nTo: $addresses");
Despite Bill's warning, I think you would have fallen into this
trap if you hadn't used the Mail::Sender module, which replaces
newline sequences with CRLF + TAB when printing headers.
HTH
--
Steve
------------------------------
Date: Sat, 29 Mar 2003 22:13:23 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <pan.2003.03.29.21.03.58.519211@aursand.no>
On Sat, 29 Mar 2003 18:18:31 +0100, Gunnar Hjalmarsson wrote:
>> more secure,
> One reason why I asked for feedback was to test that thesis by giving
> people a chance to point out *examples* of security shortcomings.
First of all, your code does not take in account DoS attacks. CGI.pm does
that.
Secondly, we don't know of all the security shortcomings that will arise
tomorrow (or the day after). You may be dead or, even worse, coding in
Java when that happens, thus having a hard time "remembering" to update
your code. :)
Anyway. Let's get to the base point here: You still haven't come up with
_one_ reason to why you're using your own wheel instead of CGI.pm. You've
made a lot of effort in trying to tell us _why_ you have invented your own
wheel, but none of those reasons rules out the advantages of using the CGI
module.
On the other hand, we have pointed out at least 2-3 good reasons to why
you should use the CGI module.
> 2) I haven't (yet) studied CGI.pm enough to feel comfortable with it.
It's time to start.
--
Tore Aursand
------------------------------
Date: Sat, 29 Mar 2003 22:45:54 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <b65479$1jbha$1@ID-184292.news.dfncis.de>
Steve Grazzini wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>>Bill Segrave called my attention [...] to the risk with email
>>forms in general that abusers add newline characters to an email
>>header field using hex encoding, and with that submit additional
>>headers. We concluded that, since the module doesn't take GET
>>requests, that is a non-issue in this case.
>
> You must be mistaken.
Don't think so.
> The hole would be here [not your code]
>
> print SENDMAIL "Subject: $form{subject}\n";
>
> When the spammer has fed you -- via POST or GET... the type of
> request is irrelevant -- something like
>
> subject => uri_escape("Work From Home!\nTo: $addresses");
>
> Despite Bill's warning, I think you would have fallen into this
> trap if you hadn't used the Mail::Sender module, which replaces
> newline sequences with CRLF + TAB when printing headers.
\n in for instance the subject field in a form (at least a form that
submits using the POST method) ends up in nothing but literally '\n'
as part of the message subject. The same with %0A etc. But if the
querystring is parsed, %0A results in a newline, so the request method
does make a difference.
Btw, I noticed the Mail::Sender behaviour in this respect when I
temporarily let the module parse the querystring.
To summarize, there are three reasons why %0A etc. can't hurt:
- The fact that only POST requests are supported
- The Mail::Sender feature you mentioned
- The fact that the module does "s/\s+/ /g;" with the values of
the header fields
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 29 Mar 2003 15:50:06 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <b654kv$lb6$1@slb6.atl.mindspring.net>
"Steve Grazzini" <grazz@nyc.rr.com> wrote in message
news:fWnha.1813$Xf4.194@twister.nyc.rr.com...
<snip>
> > Bill Segrave called my attention [...] to the risk with email
> > forms in general that abusers add newline characters to an email
> > header field using hex encoding, and with that submit additional
> > headers. We concluded that, since the module doesn't take GET
> > requests, that is a non-issue in this case.
>
Actually, my admonition to Gunnar was specific, not general, i.e., the %0A
exploit of cgiemail, when user supplied data is included in the headers.
Later discussions evolved into other issues.
> You must be mistaken.
>
> The hole would be here [not your code]
>
> print SENDMAIL "Subject: $form{subject}\n";
>
> When the spammer has fed you -- via POST or GET... the type of
> request is irrelevant -- something like
>
> subject => uri_escape("Work From Home!\nTo: $addresses");
>
> Despite Bill's warning, I think you would have fallen into this
> trap if you hadn't used the Mail::Sender module, which replaces
> newline sequences with CRLF + TAB when printing headers.
Thanks, Steve, for the clarification.
Cheers.
Bill Segraves
------------------------------
Date: Sat, 29 Mar 2003 23:32:09 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI.pm or roll-your-own?
Message-Id: <b656u1$1peec$1@ID-184292.news.dfncis.de>
Tore Aursand wrote:
> On Sat, 29 Mar 2003 18:18:31 +0100, Gunnar Hjalmarsson wrote:
>
>>> more secure,
>
>> One reason why I asked for feedback was to test that thesis by
>> giving people a chance to point out *examples* of security
>> shortcomings.
>
> First of all, your code does not take in account DoS attacks.
> CGI.pm does that.
True. Tintin called my attention to that, too. I appreciate your
calling my attention to it, and I intend to do *something*.
[snip]
> On the other hand, we have pointed out at least 2-3 good reasons to
> why you should use the CGI module.
I have counted one.
>> 2) I haven't (yet) studied CGI.pm enough to feel comfortable with
>> it.
>
> It's time to start.
Maybe true.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 29 Mar 2003 22:56:34 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: currency number to text conversion
Message-Id: <Cwpha.1746$lZ2.174806@newsread1.prod.itd.earthlink.net>
"Michael Budash" <mbudash@sonic.net> wrote in message
news:mbudash-E637CC.18191123032003@typhoon.sonic.net...
> In article <3trfa.16086$pK4.1449944@newsread1.prod.itd.earthlink.net>,
> "Jodyman" <Jodyman@hotmail.com> wrote:
>
> > "Mike" <earthtrip@gmx.net> wrote in message
> > news:b5l7d9$2aedu1$1@ID-161707.news.dfncis.de...
> > > Cameron wrote:
> > > > Hello All --
> > > >
> > > > Has anyone run across a module that handles the conversion of
currency
> > > > amounts - number to text string and visa versa. For example
$500.00 ->
> > > > FIVE HUNDRED DOLLARS or FIVE HUNDRED DOLLARS -> $500.00. I've
located
> > > > Delphi and VB routines, but nothing in PERL. Any pointers are
greatly
> > > > appreciated.
> > > >
> > > > Cheers,
> > > > Cameron
> > > I will have a look for what you are searching. Please post the
routines
> > > you´ve found in VB... I´m looking for that for months...
> >
[Snip VB Code]
>
> i have unsuccessfully looked around for a perl version of the above VB
> code. i think many of us would like a perl module of this kind. so, i've
> performed an initial conversion of the VB code to perl, with some
> attempts at "perl-ize"-ing, streamlining, and localization. i've gone
> over it and tested it, but i'd respectfully like to ask you folks to
> critically review this V.01 code, looking for bugs, poor practices, etc.
>
> sub NumToString {
>
> my $nNumber = shift;
>
> my $NumToString;
>
> my %zeros = (
> 3 => 'thousand',
> 6 => 'million',
> 9 => 'billion',
> 12 => 'trillion',
> );
>
> my %numbers = (
> 0 => 'zero',
> 1 => 'one',
> 2 => 'two',
> 3 => 'three',
> 4 => 'four',
> 5 => 'five',
> 6 => 'six',
> 7 => 'seven',
> 8 => 'eight',
> 9 => 'nine',
> 10 => 'ten',
> 11 => 'eleven',
> 12 => 'twelve',
> 13 => 'thirteen',
> 14 => 'fourteen',
> 15 => 'fifteen',
> 16 => 'sixteen',
> 17 => 'seventeen',
> 18 => 'eighteen',
> 19 => 'nineteen',
> 20 => 'twenty',
> 30 => 'thirty',
> 40 => 'fourty',
> 50 => 'fifty',
> 60 => 'sixty',
> 70 => 'seventy',
> 80 => 'eighty',
> 90 => 'ninety',
> 100 => 'hundred',
> );
>
> my $bNegative;
> my $bHundred;
>
> if ($nNumber < 0) {
> $bNegative++;
> }
>
> $nNumber = abs(int($nNumber));
>
> if ($nNumber < 1000) {
> if (int($nNumber/100) > 0) {
> $NumToString .= NumToString(int($nNumber/100)) .
> ' ' . $numbers{100};
> $bHundred++;
> }
> $nNumber -= ((int($nNumber/100)) * 100);
> my $bNoFirstDigit;
> my $tenths = int($nNumber/10);
> my $modtenths = $nNumber % 10;
> if ($tenths == 0) {
> unless ($modtenths == 0 && $bHundred) {
> $NumToString .= " $numbers{$modtenths}";
> }
> $bNoFirstDigit++;
> }
> elsif ($tenths == 1) {
> $NumToString .= " $numbers{$modtenths + 10}";
> $bNoFirstDigit++;
> }
> else {
> $NumToString .= " $numbers{$tenths * 10}";
> }
>
> unless ($bNoFirstDigit) {
> if ($nNumber % 10 != 0) {
> $NumToString .= '-' . substr(NumToString($nNumber % 10), 1)
> }
> }
> }
> else {
> my $nTemp = 10 ** 12;
> while ($nTemp >= 1) {
> if ($nNumber >= $nTemp) {
> $NumToString .= NumToString(int($nNumber / $nTemp));
> my $zeros = int(log($nTemp) / log(10) + 0.5);
> $NumToString .= " $zeros{$zeros}";
> $nNumber -= int($nNumber / $nTemp) * $nTemp;
> }
> $nTemp = $nTemp / 1000;
> }
> }
>
> if ($bNegative) {
> $NumToString = " negative$NumToString";
> }
>
> return $NumToString;
>
> }
>
>
> #-------------------------------------------------------------
> sub DollarToString {
>
> my $nAmount = shift;
>
> my $nDollar = int($nAmount);
> my $nCent = (abs($nAmount) * 100) % 100;
>
> my $DollarToString = NumToString($nDollar) . 'dollar';
>
> if (abs($nDollar) != 1) {
> $DollarToString .= 's';
> }
>
> $DollarToString .= ' and' . NumToString($nCent) . ' cent';
>
> if (abs($nCent) != 1) {
> $DollarToString .= 's';
> }
>
> $DollarToString =~ s/^\s+//;
>
> return $DollarToString;
>
> }
Good Job Michael,
Seems to work fine for me.
Jody
------------------------------
Date: 29 Mar 2003 14:43:51 -0800
From: starman7@hotmail.com (Mooky Mooksgill)
Subject: HTML::Parser questions
Message-Id: <8c02f0c6.0303291443.47e9b549@posting.google.com>
Is it possible to use HTML::Parser (or any of it's sub-parsers - e.g.
Pull, Toke, etc.) to obtain only certain elements of an .html file?
I have an html file with a lot of similarly html-tagged data. But I
only want certain parts like condition, and temperature:
e.g. CLOUDY 65F/18C
from:
<font face="Verdana,sans-serif" color="#666666"
size="-2"><b>Cond:</b></font></td>
<td bgcolor="#FFFFFF" width="68">
<font face="Verdana,sans-serif" color="#666666"
size="-2">CLOUDY</font></td></tr>
<tr><td width="100" bgcolor="#CCCCCC">
<font face="Verdana,sans-serif" color="#666666"
size="-2"><b>Temp:</b></font></td>
<td bgcolor="#CCCCCC" width="68">
<font face="Verdana,sans-serif" color="#666666"
size="-2">65F/18C</font></td></tr>
<tr><td width="100" bgcolor="#FFFFFF">
<font face="Verdana,sans-serif" color="#666666"
size="-2"><b>Feels:</b></font></td>
<td bgcolor="#FFFFFF" width="68">
<font face="Verdana,sans-serif" color="#666666"
size="-2">61F/16C</font></td></tr>
<tr><td width="100" bgcolor="#CCCCCC">
<font face="Verdana,sans-serif" color="#666666"
size="-2"><b>Wind:</b></font></td>
Thanks for any examples,
Mooky
------------------------------
Date: Sat, 29 Mar 2003 15:46:42 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: implicit vs explicit variable usage in loop w/ range regexp
Message-Id: <slrnb8c522.4r0.tadmc@magna.augustmail.com>
Upstart <stimonyhall@netscape.net> wrote:
> yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote in message news:<3e84b6e6@news.victoria.tc.ca>...
>> if ( ($line =~ /^BEGIN:/) ... ( $_ =~ /^END:/) ) {
>>
>> which is not what you want.
>
> ok - i'll bite. what do i want? :-)
if ( ($line =~ /^BEGIN:/) ... ( $line =~ /^END:/) ) {
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 29 Mar 2003 17:53:08 -0500
From: istink <istink@real.bad.com>
Subject: Re: match except between...
Message-Id: <3E8623D4.59F5F5@real.bad.com>
I get a "1" (true).
$x="hello world hello world <hello world good> hello world helloworld";
$x=s/$re/$1 eq 'red' ? 'blue' : $1/ge;
print $x;
I still look at perl code and say what the h*ll is that!
Abigail wrote:
>
> Chris W (idont@thinkso.net) wrote on MMMCDXCVII September MCMXCIII in
> <URL:news:PKSdnS_OVtX6PhijXTWcpA@comcast.com>:
> == Okay, I tested this regex in reply to another question in the group:
> ==
...........
> Abigail
> --
> perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
------------------------------
Date: Sat, 29 Mar 2003 17:54:12 -0500
From: istink <istink@real.bad.com>
Subject: Re: match except between...
Message-Id: <3E862414.A49C3951@real.bad.com>
*slap* *slap* *slap* *slap*
never mind.
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
------------------------------
Date: Sat, 29 Mar 2003 18:11:07 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: match except between...
Message-Id: <3E86280B.2875BF87@earthlink.net>
istink wrote:
>
> I get a "1" (true).
>
> $x="hello world hello world <hello world good> hello world helloworld";
> $x=s/$re/$1 eq 'red' ? 'blue' : $1/ge;
> print $x;
An expression of the form "$x = s///" is not the same as "$x =~ s///".
One assigns does substitution on $_ then assigns to $x the number of
substitutions that were performed, and the other performs substitution
on $x, and discards the number of substitutions performed.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Sat, 29 Mar 2003 21:37:27 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Multiple POSTS and GETS from one perl script
Message-Id: <pan.2003.03.29.16.03.50.299410@aursand.no>
On Sat, 29 Mar 2003 14:37:51 +0000, Andrew Newlands wrote:
> I was wondering if there is a way of posting data to other scripts while
> continuing to run the original script, branching off so that 2 scripts
> are runnning on the webserver as opposed to one.
You mean fork()'ing?
--
Tore Aursand
------------------------------
Date: Sat, 29 Mar 2003 22:13:23 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Perl and objects
Message-Id: <pan.2003.03.29.21.11.09.792097@aursand.no>
On Sat, 29 Mar 2003 12:58:32 -0600, Joe Creaney wrote:
> I have been looking a simple object in the programming perl book.
After looking at your code, please have a look at:
'perldoc -f perltoot'
> #!/user/bin.perl
Really?
> use strict;
My "standard" way of creating a class is something (...) like this;
package Player;
use strict;
use warnings;
sub new {
my $proto = shift;
my $class = ref( $proto ) || $proto;
## Initialise the class with default values my $self = {
'name' => '',
'x' => 0,
'y' => 0,
}
bless( $self, $class );
return $self;
}
1;
Now this class can be used in my script;
#!/usr/bin/perl
#
use strict;
use warnings;
use Player;
my $Player = Player->new();
$Player->{'name'} = 'Michael Owen';
$Player->{'x'} = 235;
$Player->{'y'} = 678;
print 'Finished populating ' . $Player->{'name'} . "\n";
Totally untested.
--
Tore Aursand
------------------------------
Date: 29 Mar 2003 21:23:17 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Perl and objects
Message-Id: <b652s5$go$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Joe Creaney:
> I have been looking a simple object in the programming perl book. I
> think I wrote a simple class. It is a simple player class that will
> have his name and x and y location for walking on a simple map.
Well, no, you wrote a subroutine named player(), but there is no class.
> #!/user/bin.perl
> use strict;
> my $n;
>
>
> sub player {
> my $char = {};
> my $self;
> $char -> name()
> $char -> xcord();
> $char -> ycord();
$char is only a reference to an anonymous hash. It is no object so you
can't call any methods upon it.
> bless $self, $char;
You can't use it as the second argument for bless() either. Simplified:
the first argument to bless is the object (more correctly: the thing
that is eventually going to be the object) and the second argument is a
string denoting the name of the class the thing should belong to:
bless $thing, "Player";
# $thing is now a Player
> return $char;
> }
>
> print "Your name sir:";
>
> $n = <STDIN>;
> ** -> player ($char{name(->$n}); <-**
>
> The marked spot is where I am having trouble. I created a simple class
> and a few objects in C++ but here seems very different.
You are having these problems because you seem to be confused about a
few things. Before you can create objects, you need a class. In Perl, a
class is simply a package, therefore a player-class would begin like
that:
package Player;
After that you need a method that constructs your objects. This
function is unsurprisingly called the constructor. It's a common
convention to call this method new(). You can do some initializations
there as well, but the only important part for the moment is that you
bless() in this method:
sub new {
# the name of this class
my $class = shift;
# this will be the object later: we use a hash-reference
my $self = { name => undef,
x => 0,
y => 0 };
# this hash-reference is now told to be an instance
# of $class
bless $self, $class;
# the constructor returns an object:
return $self;
}
Now that you have an object with some attributes ('name', 'x' and 'y'),
you should add some accessor methods to set and retrieve these values:
sub set_name {
# $self is again the object itself
my ($self, $name) = @_;
$self->{ name } = $name;
}
sub get_name {
my $self = shift;
return $self->{ name };
}
Add similar methods for the position on the map (the attributes 'x' and
'y').
Now you can start creating new Players with 'Player->new'.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sat, 29 Mar 2003 21:37:28 +0100
From: "Tore Aursand" <tore@aursand.no>
Subject: Re: Please tell me I'm beginner
Message-Id: <pan.2003.03.29.16.00.21.562603@aursand.no>
On Sat, 29 Mar 2003 06:36:10 -0600, Ami wrote:
>> Looking at your script, I strongly suggest that you start using CGI.pm
>> instead of reinventing the wheel.
> Thank you, sir !
And, while we're at it; don't top-post (ie. post your reply before the
original message).
--
Tore Aursand
------------------------------
Date: 29 Mar 2003 11:53:29 -0800
From: tuanglen@hotmail.com (Tuang)
Subject: Re: simple substitution also changes line endings
Message-Id: <df045d93.0303291153.6b155e5b@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3E855557.96906066@earthlink.net>...
> > How do I turn binmode on for all files when using the command line
> > options to create an automatic loop?
>
>
> > This is the whole script:
> >
> > ==========================
> >
> > #!/cygdrive/c/Perl/bin/perl -w -i.bak -p
> > #
> >
> > # insert processing code here:
> > s/A/X/g;
> >
> > ==========================
> >
> > how do I use binmode here? I thought maybe $ARGVOUT was the hidden
> > filename, so I tried inserting 'binmode $ARGVOUT;' before the
> > substitution, but it didn't work.
>
> It's ARGVOUT, not $ARGVOUT.
Ah, yes, thank you. I've been doing a lot more shell stuff than Perl
lately. Inserting the line "binmode ARGVOUT;" makes it work correctly.
Unfortunately, the '-w' option, which seems like a reasonable thing to
keep in a template where the processing code will change often, issues
a warning:
Name "main::ARGVOUT" used only once: possible typo at ./proc line 11.
Is there any way to keep the protection of the -w option without
getting this particular warning every time I use it?
>
> However, you would be better off if it were opened in the right mode to
> begin with; thus, write your script as:
>
> #!/cygdrive/c/Perl/bin/perl -w -i.bak -p
> use open IN => ":raw", OUT => ":raw";
> # insert processing code here:
> y/A/X/;
> __END__
I tried this (inserting the "use ..." line, and without any "binmode
..." line) and it didn't work. I didn't get any errors or warnings,
but it still converted 0A line endings to 0D 0A.
Thanks to everyone for the helpful tips.
------------------------------
Date: Sat, 29 Mar 2003 17:08:55 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: simple substitution also changes line endings
Message-Id: <3E861977.8329802C@earthlink.net>
Tuang wrote:
> Benjamin Goldberg wrote:
>
> > > How do I turn binmode on for all files when using the command line
> > > options to create an automatic loop?
> >
> >
> > > This is the whole script:
> > >
> > > ==========================
> > >
> > > #!/cygdrive/c/Perl/bin/perl -w -i.bak -p
> > > #
> > >
> > > # insert processing code here:
> > > s/A/X/g;
> > >
> > > ==========================
> > >
> > > how do I use binmode here? I thought maybe $ARGVOUT was the hidden
> > > filename, so I tried inserting 'binmode $ARGVOUT;' before the
> > > substitution, but it didn't work.
> >
> > It's ARGVOUT, not $ARGVOUT.
>
> Ah, yes, thank you. I've been doing a lot more shell stuff than Perl
> lately. Inserting the line "binmode ARGVOUT;" makes it work correctly.
>
> Unfortunately, the '-w' option, which seems like a reasonable thing to
> keep in a template where the processing code will change often, issues
> a warning:
>
> Name "main::ARGVOUT" used only once: possible typo at ./proc line 11.
>
> Is there any way to keep the protection of the -w option without
> getting this particular warning every time I use it?
Add:
no warnings 'once';
> > However, you would be better off if it were opened in the right mode
> > to begin with; thus, write your script as:
> >
> > #!/cygdrive/c/Perl/bin/perl -w -i.bak -p
> > use open IN => ":raw", OUT => ":raw";
> > # insert processing code here:
> > y/A/X/;
> > __END__
>
> I tried this (inserting the "use ..." line, and without any "binmode
> ..." line) and it didn't work. I didn't get any errors or warnings,
> but it still converted 0A line endings to 0D 0A.
Strange. I don't know why it didn't work.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Sat, 29 Mar 2003 21:41:38 GMT
From: "Phil Langerholc" <root@localhost.spam.me.not>
Subject: suid not working
Message-Id: <mqoha.503$tr2.316@nwrdny03.gnilink.net>
Hello,
I am having a problem with Perl trying to suid on AIX 4.3.3, ML is 11. I
am using the perl that comes with AIX , 5.005_03 because I have several
different customer sets I support and they want the "vendor supplied"
version on their systems.
Here is my code:
#!/bin/perl -wTU
#test of the SUID capability of perl
#
$ENV{'PATH'}="";
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
print "EUID = $>\n";
print "UID = $<\n";
$< = $>; # set the REAL_USER_ID to the EFFECTIVE_USER_ID
$( = $) = 0; # set the REAL_GROUP_ID and EFFECTIVE_GROUP_ID to system
system("/usr/bin/whoami");
print "UID=$<\n";
and here is the output:
kenny:/home/pdlanger> suidtest.pl
EUID = 204
UID = 204
pdlanger
UID=204
I've Googled and not found too much on this for AIX aside from some overflow
vulnerabilities in pervious versions of AIX.
Thanks in advance to anyone who can help...
---Phil
--
Phil Langerholc - Sr. I/T Specialist
IBM Global Services
The opinions expressed are my own and do not reflect those of IBM
"Things in life should be made simple rather than complex" - Einstein
"Experience has shown that no amount of effort will alter reality" - Unknown
------------------------------
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 4784
***************************************