[22659] in Perl-Users-Digest
Perl-Users Digest, Issue: 4880 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 23 14:11:02 2003
Date: Wed, 23 Apr 2003 11:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 23 Apr 2003 Volume: 10 Number: 4880
Today's topics:
Perl's exec and system use the shell even if the docs s <denshimeiru-sapmctacher@durchnull.ath.cx>
Re: Perl's exec and system use the shell even if the do <nobull@mail.com>
Re: Perl's exec and system use the shell even if the do <denshimeiru-sapmctacher@durchnull.ath.cx>
Pod::Usage::pod2usage uses tainted arguments <private@claudio.ch>
reg expr prl newbie (James Peterson)
Re: reg expr prl newbie <richard@zync.co.uk>
Re: reg expr prl newbie <nobull@mail.com>
regular expression question (siva chelliah)
Re: regular expression question <tassilo.parseval@rwth-aachen.de>
Re: regular expression question <grazz@pobox.com>
Re: regular expression question <nobull@mail.com>
Re: Tough question for the guru's; Grep Once, Awk Twice <richard@zync.co.uk>
Re: Tough question for the guru's; Grep Once, Awk Twice <uri@stemsystems.com>
Re: unix system komand (Villy Kruse)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Apr 2003 17:16:22 GMT
From: Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx>
Subject: Perl's exec and system use the shell even if the docs say something different (was: Re: Why no viruses on Linux?)
Message-Id: <slrnbadij9.gis.denshimeiru-sapmctacher@message-id.durchnull.ath.cx>
Scripsit ille aut illa »Ilari Liusvaara« <noaddress@porn.org>:
> Datagram from Rudolf Polzer incoming on netlink socket <slrnba3d2e.7a4.abuse@durchnull.de>. Dumping datagram.
[Executing shell script without #!/bin/sh line]
> > It depends on how one tries to execute the file. And I do not like that.
>
> Actually, it depends on wheither shell gets involved in loop or not.
> As has been said many times: Shell can do dangerous things.
>
> > Especially perl's exec call looks suspicious to me - according to the
> > documentation the shell is not used in this case but execvp is.
>
> Yes, it is weird. Hmm... I remember discussion about unary and binary form
> of some keyword in perl. It was that the unary version invoked shell, but
> the binary one didn't.
rpolzer@katsuragi tmp $ strace perl -e 'exec { "./foobar.sh" } "foobar.sh", "aaa"' 2>&1 |grep foobar
execve("/usr/bin/perl", ["perl", "-e", "exec { \"./foobar.sh\" } \"foobar.sh\", \"aaa\""], [/* 62 vars */]) = 0
execve("./foobar.sh", ["foobar.sh", "aaa"], [/* 62 vars */]) = -1 ENOSYS (Function not implemented)
execve("./foobar.sh", ["foobar.sh", "aaa"], [/* 62 vars */]) = -1 ENOSYS (Function not implemented)
execve("./foobar.sh", ["foobar.sh", "aaa"], [/* 62 vars */]) = -1 ENOSYS (Function not implemented)
execve("./foobar.sh", ["foobar.sh", "aaa"], [/* 62 vars */]) = -1 ENOSYS (Function not implemented)
execve("./foobar.sh", ["foobar.sh", "aaa"], [/* 62 vars */]) = -1 ENOEXEC (Exec format error)
execve("/bin/sh", ["/bin/sh", "./foobar.sh", "aaa"], [/* 62 vars */]) = 0
open("./foobar.sh", O_RDONLY|O_LARGEFILE) = 3
According to the documentation, the syntax:
exec { "./foobar.sh" } "foobar.sh", "aaa";
should never call the shell. However, it does. It isn't as bad as I
thought because it seems to happen if and only if a file cannot be
executed because of a missing #! line, but it isn't documented. It
probably should.
I even got:
rpolzer@katsuragi tmp $ perl -e 'exec { "-c/foo.sh" } "-c"'
/bin/sh: -/: invalid option
Usage: /bin/sh [GNU long option] [option] ...
/bin/sh [GNU long option] [option] script-file ...
[...]
I don't know if it can be dangerous in any case, but it looks like Perl
can be tricked into calling the shell. Probably it only is useful for
JAPHs, but I don't know.
XP&Fup2comp.lang.perl.misc set
--
A remarkable, elegant little C function was written to implement I-TAG
processing, but it has too many lines of code to include in this margin [11].
RFC 2795
------------------------------
Date: 23 Apr 2003 18:27:00 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl's exec and system use the shell even if the docs say something different (was: Re: Why no viruses on Linux?)
Message-Id: <u9el3t9laz.fsf@wcl-l.bham.ac.uk>
Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx> writes:
> According to the documentation, the syntax:
>
> exec { "./foobar.sh" } "foobar.sh", "aaa;"
>
> should never call the shell.
Can you tell me where this is stated - I can't find it in "perldoc
-f exec" in 5.8.0 or 5.6.1.
All I can see is a satement that
exec { "./foobar.sh" } "foobar.sh", "aaa";
and
exec "foobar.sh", "aaa";
both call execvp() directly.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 23 Apr 2003 17:49:15 GMT
From: Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx>
Subject: Re: Perl's exec and system use the shell even if the docs say something different (was: Re: Why no viruses on Linux?)
Message-Id: <slrnbadkgu.hac.denshimeiru-sapmctacher@message-id.durchnull.ath.cx>
Scripsit ille »Brian McCauley« <nobull@mail.com>:
> Rudolf Polzer <denshimeiru-sapmctacher@durchnull.ath.cx> writes:
> > According to the documentation, the syntax:
> >
> > exec { "./foobar.sh" } "foobar.sh", "aaa;"
> >
> > should never call the shell.
>
> Can you tell me where this is stated - I can't find it in "perldoc
> -f exec" in 5.8.0 or 5.6.1.
(I have 5.8.0)
> All I can see is a satement that
>
> exec { "./foobar.sh" } "foobar.sh", "aaa";
>
> and
>
> exec "foobar.sh", "aaa";
>
> both call execvp() directly.
Yes, and it is tried. It fails because of the missing #! line. Perl
detects the error ("DWIM") and calls /bin/sh explicitly.
That's nowhere stated in
perldoc -f exec
--
Story? Du meinst, es gibt auch eine Fassung dieser geschichten mit Story?
Das wäre mir neu... :D
["il cervello cattivo di Tenchi" in daani]
------------------------------
Date: 23 Apr 2003 16:29:03 +0200
From: Claudio Nieder <private@claudio.ch>
Subject: Pod::Usage::pod2usage uses tainted arguments
Message-Id: <3ea6a32f@news.swissonline.ch>
Hi,
a call to pod2usage with -verbose=>2 will result in this error:
Use of tainted arguments in system is deprecated at
/usr/lib/perl5/5.8.0/Pod/Usage.pm line 510.
when pod2usage tries to execute perldoc using system.
Workaround: use a negative verbosity level to print the entire manpage.
claudio
--
Claudio Nieder, Kanalweg 1, CH-8610 Uster, Tel +41 79 357 6743
yahoo messenger: claudionieder aim: claudionieder icq:42315212
mailto:private@claudio.ch http://www.claudio.ch
------------------------------
Date: 23 Apr 2003 09:54:50 -0700
From: sonique55105@yahoo.com (James Peterson)
Subject: reg expr prl newbie
Message-Id: <74a4a6df.0304230854.26d04bad@posting.google.com>
i want to extract the title from a number of html pages and i was told
i could do this in perl but i am having troubles with it. Basically i
want to grab whatever lies between <title> and </title> but i always
seem to get errors when i have </title> in my regular expression
because (i suppose) perl assumes that / denotes the end of the match.
Can anyone point me to a correct reg expr that will grab PAGE TITLE
from <title>PAGE TITLE</title>?
Thanks!
------------------------------
Date: Wed, 23 Apr 2003 18:08:27 +0100
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: reg expr prl newbie
Message-Id: <20030423.180826.411826969.18265@richg.zync>
In article <74a4a6df.0304230854.26d04bad@posting.google.com>, "James
Peterson" <sonique55105@yahoo.com> wrote:
> i always seem to
> get errors when i have </title> in my regular expression because (i
> suppose) perl assumes that / denotes the end of the match.
Correct. Either:
replace occurences of / in the search or replacement text with \/
(leaning toothpick syndrome)
Or:
change the delimiter for the regex. F'rinstance
$line =~ m#<title>(.*)</title>#;
$title = $1;
Cheers
Rick
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: 23 Apr 2003 18:17:37 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: reg expr prl newbie
Message-Id: <u9k7dl9lqm.fsf@wcl-l.bham.ac.uk>
sonique55105@yahoo.com (James Peterson) writes:
> i want to extract the title from a number of html pages and i was told
> i could do this in perl but i am having troubles with it. Basically i
> want to grab whatever lies between <title> and </title> but i always
> seem to get errors when i have </title> in my regular expression
> because (i suppose) perl assumes that / denotes the end of the
> match.
The way to escape metacharacters in Perl (and indeed many other
programming languages) is to prefix them with a backslash.
> Can anyone point me to a correct reg expr that will grab PAGE TITLE
> from <title>PAGE TITLE</title>?
No, using a regex, even /<title>\s*(.*?)\s*<\/title>/ is not correct.
Use an HTML parser. There's at least one on CPAN.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 23 Apr 2003 09:32:20 -0700
From: podian@yahoo.com (siva chelliah)
Subject: regular expression question
Message-Id: <5d146344.0304230832.adf9187@posting.google.com>
Hi,
The following regular expression:
/FRED(.*)\s.*BARNEY\1/
matches the following string and I thought it should not.
FREDyyy something here BARNEYyyyy
There are four y's at the end. Any ideas?
Thanks,
Siva
------------------------------
Date: 23 Apr 2003 16:53:47 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: regular expression question
Message-Id: <b86ger$qic$1@nets3.rz.RWTH-Aachen.DE>
Also sprach siva chelliah:
> The following regular expression:
>
> /FRED(.*)\s.*BARNEY\1/
>
> matches the following string and I thought it should not.
>
> FREDyyy something here BARNEYyyyy
>
> There are four y's at the end. Any ideas?
In the above, \1 refers back to the string "yyy" which matches any
number of "y"s larger than 3. If you want to make sure that the string
has to end on "yyy" you should anchor the pattern:
/FRED(.*)\s.*BARNEY\1$/
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: Wed, 23 Apr 2003 16:53:57 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: regular expression question
Message-Id: <Fyzpa.21757$7M5.1547781@twister.nyc.rr.com>
siva chelliah <podian@yahoo.com> wrote:
> The following regular expression:
>
> /FRED(.*)\s.*BARNEY\1/
>
> matches the following string and I thought it should not.
>
> FREDyyy something here BARNEYyyyy
>
> There are four y's at the end. Any ideas?
You didn't anchor the end of the string. The backreference
matches the first three of those four "y"s and that's enough
for the whole match to succeed.
(It would fail if you added '$' or '\Z'.)
--
Steve
------------------------------
Date: 23 Apr 2003 18:05:01 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: regular expression question
Message-Id: <u9of2x9mbm.fsf@wcl-l.bham.ac.uk>
podian@yahoo.com (siva chelliah) writes:
> Hi,
> The following regular expression:
>
> /FRED(.*)\s.*BARNEY\1/
>
> matches the following string and I thought it should not.
>
> FREDyyy something here BARNEYyyyy
This is untrue.
You are most likely allowing yourself to be confused by your own
sloppy terminolgy.
Sloppy short-hand terminolgy is fine as long as everyone knows it's
sloppy and short-hand and doesn't try take it literally.
The regex /i/ _finds_ a match in "wibble". It does not _match_
"wibble". What it matches is just the "i". Often, however, people
will say /i/ matches "wibble" but everyone should know not to take it
literally.
Likewise /FRED(.*)\s.*BARNEY\1/ finds a match in "FREDyyy something
here BARNEYyyyy". It does not, as you claim, match "FREDyyy something
here BARNEYyyyy" what it matched is just "FREDyyy something here
BARNEYyyy".
Perhaps you really meant /FRED(\S*)\s.*BARNEY\1(?!\S)/
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 23 Apr 2003 15:21:23 +0100
From: "Richard Gration" <richard@zync.co.uk>
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <20030423.152119.2118801173.18265@richg.zync>
Hi,
First off, you'll find the people on this group very helpful if you cut
and paste perl code into your post. You will find they get progressively
more unhelpful the less your posting has to do with a _specific_ perl
problem. In fairness, free systems analysis is hard to come by ;-)
Anyway.
Check out these:
perldoc perldata
perldoc perlref
perldoc -f localtime
perldoc -f open
perldoc -f die
perldoc -f while
perldoc -f split
perldoc -f grep
perldoc -f map <--- probably not needed, might come in handy
This should be enough to allow you to open the file, read it, isolate the
fields you're interested in, store them in a suitable data structure
(maybe an array of array refs?), and then pull out the lines you need
(grep and map). Then you should be able to post some code which does most
of what you need. Then the nice people here will probably jump at the
chance to point out the subtle mistakes which are breaking your code.
Cheers
Rick
PS A few lines of data would have made your shell script miles easier to
understand :-)
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
------------------------------
Date: Wed, 23 Apr 2003 15:46:21 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <x73ck9tdwy.fsf@mail.sysarch.com>
>>>>> "A" == Agrapha <brian@box201.com> writes:
A> Uri Guttman <uri@stemsystems.com> wrote in message news:<x7adehvnvn.fsf@mail.sysarch.com>...
>> this is a perl discussion group and not a rewrite my shell script in
>> perl for me group.
>>
>> even if you did get someone to rewrite it, you don't know any perl so
>> how could you maintain it? will you regularly repost it here so we can
>> add features and fix things when the formats change?
>>
>> the amount of perl you need is minimal so why don't you learn it?
>>
>> uri
A> whew, 71 words and not 1 bit of code....impressive.
A> I am learning perl otherwise I would post this in a PHP discussion
A> group. But I will be honest I am on a deadline here. I can use some
A> help if I can only get complaints about posting then I shall look
A> elsewhere.
whew, 244 word and not 1 bit of code. you beat me!! and please post this
in a php group and let them do your work for you.
A> My knowledge of perl is so far limited. if you care to have updated
A> posts I am not opposed to that. The script will need to be portable.
A> It is for emergencies only. Normally there is a much more complicated
A> program which pulls this data for us. The other night that program
A> broke. So I whipped up the shell script in a hurry.
so whip up the perl code in a hurry and show that.
A> My script is functional but not professional, not efficient. I'm not
A> pleased with how much cpu it took to run it. My dataset can have as
A> many as 200,000 rows in it. Out of that I am really only concerned
A> with 3 columns. $4, $5,and $8 of those three $5 is (in perlesque
A> language) just a $ARGV. I use that in my script as $1 to find all the
A> rows which match a value I pass to the scipt on the command line.
i am not pleased with how much time you are wasting here. think about
all the man-hours you have wasted by begging for a perl translation.
FYI: this group is not a free perl translation service. if you had
posted even a minimal and highly broken perl script you would have
gotten help.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 23 Apr 2003 13:48:28 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: unix system komand
Message-Id: <slrnbad6dc.1on.vek@station02.ohout.pharmapartners.nl>
On Fri, 18 Apr 2003 08:17:33 -0500,
Tad McClellan <tadmc@augustmail.com> wrote:
>uruz <uruz@inode.at> wrote:
>
>> My problem is as a part of this programm i use the system command
>> `write root`
>> this works as next i print a string.
>> but how should i send the strg-d command to close the write process
>> code:
>> print "writing to:";
>> `write uruz`;
>> print "hi uruz\n";
>> ???? strg-d
>
>
>If I understand your questions, then I think you should read
>the "Pipe Opens" section in:
>
> perldoc perlopentut
>
>
The strg-d aka. ctrl-d isn't used when sending data through a pipe.
The write command will terminate normaly when you close the pipe
which would create an EOF condition just like ctrl-d would do
when entering data from the keyboard.
Villy
------------------------------
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 4880
***************************************