[9350] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2945 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 23 09:07:09 1998

Date: Tue, 23 Jun 98 06:01:07 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 23 Jun 1998     Volume: 8 Number: 2945

Today's topics:
    Re: after 5 hrs, the beginner beats the s/// (Michael J Gebis)
    Re: after 5 hrs, the beginner beats the s/// <tchrist@mox.perl.com>
    Re: after 5 hrs, the beginner beats the s/// <tchrist@mox.perl.com>
    Re: argc and argv (Gabor)
    Re: argc and argv <Tony.Curtis+usenet@vcpc.univie.ac.at>
    Re: Comparing conditional ? with if..else construct <tchrist@mox.perl.com>
    Re: Comparing conditional ? with if..else construct (Larry Rosler)
    Re: Comparing conditional ? with if..else construct <tchrist@mox.perl.com>
    Re: Flames.... birgitt@my-dejanews.com
    Re: Flames.... kibbeyd@finnegan.com
    Re: How can I get the IP-Number & the Remote_Host Name (Larry Rosler)
    Re: how do I get directory structure disk space used? <tchrist@mox.perl.com>
    Re: how do I get directory structure disk space used? <tchrist@mox.perl.com>
    Re: problem: passing an array of references <jdf@pobox.com>
    Re: Remove blank  too much lines from a text file <tchrist@mox.perl.com>
    Re: Remove blank  too much lines from a text file <tchrist@mox.perl.com>
    Re: Remove blank  too much lines from a text file <rra@stanford.edu>
    Re: Remove blank  too much lines from a text file <perlguy@inlink.com>
    Re: Remove blank  too much lines from a text file <tchrist@mox.perl.com>
    Re: Sending files via mail in perl <tchrist@mox.perl.com>
    Re: Sending files via mail in perl kibbeyd@finnegan.com
    Re: Simple, efficient way of checking whether $VAR is a <tchrist@mox.perl.com>
    Re: system() and security again <rra@stanford.edu>
    Re: system() and security again <tchrist@mox.perl.com>
    Re: system() and security again (Marc Haber)
    Re: system() and security again <rra@stanford.edu>
    Re: Taint again <rra@stanford.edu>
    Re: Taint again (Marc Haber)
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 23 Jun 1998 04:57:45 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: after 5 hrs, the beginner beats the s///
Message-Id: <6mnck9$3oa@mozo.cc.purdue.edu>

sowmaster@juicepigs.com (Bob Trieger) writes:
}$line =~ s/^\s*(.*)\s*$/$1/;

}That is what you are looking for and if you checked the FAQs, you wouldn't 
}have wasted 5 hours.

I personally find it funny that it took SEVEN (at this count) people
to show this guy up. Yeah, yeah, I know, the non-deterministic nature
of usenet makes all notions of simultaneity obsolete, but come on, did
EVERYBODY need to pick on the original poster?  He said that he had
had a pretty bummed-out day already.  

This isn't directed at you, Bob- at least you were first on my
server, and were (relatively) gentle in your response.  


-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: 23 Jun 1998 12:00:57 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: after 5 hrs, the beginner beats the s///
Message-Id: <6mo5dp$pvd$3@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    sowmaster@juicepigs.com (Bob Trieger) writes:
:Yes, I do. Was a typo. Thanks for pointing it out.
:
: $line =~ s/^\s*(.*?)\s*$/$1/;

This is certainly a slow solution.  The FAQ
points out the better way.

--tom
-- 
    echo "I can't find the O_* constant definitions!  You got problems."
            --The Configure script from the perl distribution


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

Date: 23 Jun 1998 12:18:17 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: after 5 hrs, the beginner beats the s///
Message-Id: <6mo6e9$pvd$10@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    gebis@albrecht.ecn.purdue.edu (Michael J Gebis) writes:
:I personally find it funny that it took SEVEN (at this count) people
:to show this guy up. 

None of whom (modulo me) actually provided the proper answer.

--tom
-- 
If I had any humility I would be perfect.
                --Ted Turner


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

Date: 23 Jun 1998 12:39:49 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: argc and argv
Message-Id: <slrn6ov8ht.1co.gabor@localhost.vmunix.com>

In comp.lang.perl.misc, Robert Rehammar <Robert.Rehammar@emw.ericsson.se> wrote :
# Hi !!
# 
# I'm writning a perlscript to use with CGI and the POST method. Now  I
# need to read the argc and argv (don't know if this is the perl name of
# it, but I'm sure that everybody knows what I mean, the parameters sent
# to the program...). My question is how do I do this ???
# 
# \\Robert Rehammar

argc == scalar @ARGV # not quite since argv[0] isn't included
argv == @ARGV
argv[0] == $0
argv[1] .. argv[argc - 1] == $ARGV[0] .. $ARGV[$#ARGV]


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

Date: 23 Jun 1998 14:45:15 +0200
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: argc and argv
Message-Id: <7x90mo9tic.fsf@beavis.vcpc.univie.ac.at>

Re: argc and argv, Robert <Robert.Rehammar@emw.ericsson.se>
said:

Robert> Hi !!  I'm writning a perlscript to use with CGI and
Robert> the POST method. Now I need to read the argc and
Robert> argv (don't know if this is the perl name of it, but
Robert> I'm sure that everybody knows what I mean, the
Robert> parameters sent to the program...). My question is

They don't come via the command line, which is presumably
what you're referring to.

Robert> how do I do this ???

use CGI;

<URI:http://www-genome.wi.mit.edu/ftp/pub/software/WWW/>

hth
tony
-- 
Tony Curtis, Systems Manager, VCPC,      | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien, AT | http://www.vcpc.univie.ac.at/

"You see? You see? Your stupid minds! Stupid! Stupid!" ~ Eros, Plan9 fOS.


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

Date: 23 Jun 1998 11:57:13 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Comparing conditional ? with if..else construct
Message-Id: <6mo56p$pvd$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "F.Quednau" <quednauf@nortel.co.uk> writes:
:  $args->{subjectline} ? $subject = $args->{subjectline} : $subject = ".*";

Man, yet another C++ mistake.  Why does this keep happening? 
It's a simple matter of precedence.  You have to parenthesize
the assignments, just as you do with 

    if ( ($x = f()) || ($y = g()) ) { ..... }

--tom
-- 
    double value;                /* or your money back! */
    short changed;               /* so triple your money back! */
            --Larry Wall in cons.c from the 4.0 perl source code


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

Date: Tue, 23 Jun 1998 05:24:01 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Comparing conditional ? with if..else construct
Message-Id: <MPG.ff93e411c90fce99896eb@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <6mo56p$pvd$2@csnews.cs.colorado.edu>, Tom Christiansen 
<tchrist@mox.perl.com> says...
 ...
> :  $args->{subjectline} ? $subject = $args->{subjectline} : $subject = ".*";
> 
> Man, yet another C++ mistake.  Why does this keep happening? 
> It's a simple matter of precedence.

Why are you blaming this mistake on C++, or C for that matter?  The 
precedences are exactly the same as in Perl.  Even overloading the 
operators cannot change the precedences.

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 23 Jun 1998 12:27:24 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Comparing conditional ? with if..else construct
Message-Id: <6mo6vc$pvd$11@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, lr@hpl.hp.com (Larry Rosler) writes:
:Why are you blaming this mistake on C++, or C for that matter?  The 
:precedences are exactly the same as in Perl.  Even overloading the 
:operators cannot change the precedences.

Because it in fact *is* different in C++ than it is in C.
In C, it's illegal without parens, because C and Perl have
the same precedence.  But in C++, prececence *differs*, and the
parens are implicitly supplied for you anyway.

--tom

-- 


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

Date: Tue, 23 Jun 1998 12:16:55 GMT
From: birgitt@my-dejanews.com
Subject: Re: Flames....
Message-Id: <6mo6bn$2iu$1@nnrp1.dejanews.com>

In article <Pine.GSO.3.96.980622185608.3398Q-100000@user2.teleport.com>,
  Tom Phoenix <rootbeer@teleport.com> wrote:
>
> On Tue, 23 Jun 1998 birgitt@my-dejanews.com wrote in response to a message
> of mine:
>
> > Getting all upset and outraged and starting a long discussion
> > and analysis of the state of affairs doesn't help much either.
>
> I'm not certain how to take this. Have I done anything that entitles you
> to label me "upset and outraged"?  Did I start "a long discussion and
> analysis of the state of affairs"? Are you saying that your contributions
> to this discussion are helping but mine aren't?
>
> Please clarify.
>

Dear All:

Here are my official apologies and clarificatons for the record. I
answered Tom Phoenix in private mail yesterday evening.

Of course NOTHING AT ALL in my above statement was related in any
way to Tom Phoenix's postings to c.l.p.m. NOT IN MY DREAMS could I
imagine that my words could have been interpreted that way and I am
very much ashamed that I am still not capable to choose my words
carefully enough to avoid such confusion. Please accept my apologies.

Everyone knows and can't help to be tremedously amazed about *how*
Tom Phoenix is answering thousand of times to the thousandandoneth
FAQ questions. Cheerful, helpful, immensely polite, with pointers
and endless patience. Honestly I don't think you will find ONE
person who would not agree on this.

If I had asked a FAQ question which would have resulted in one of
Tom Phoenix famous answers, I guess the only sin I could commit is
sending him half a page of smileys back in private mail. To save
bandwidth I will do with one here. 8-).

Thanks for everything, Tom Phoenix !

Birgitt Funk

P.S. and of course I think that my 'contributions' to this list
are all helplessly off-topic, proving nothing more than the point
I tried to get across, that many, many posts are the result of
getting caught in a state of 'compulsively' posting and commenting
to what you read, because the "post" button is just too close
and too easily to press and the 'confusion' or feeling of being
'stuck, overwhelmed' of a newbie is undeniable more prevalent than
estimated by seasoned old timers.

Abigail said once here a couple of weeks ago, that the downfall
of usenet started with the invention of the "post" button on your
news reader (round about).

I think she is very right, as the medium you use has addictive
power and the "post" button (the way you can (ab)use it in these days)
is the delivery man for your daily dose of usenet 'dope'. You don't
even pay postage, and the 'dope' is for free. No wonder that some
end up in a mess.


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Tue, 23 Jun 1998 12:37:04 GMT
From: kibbeyd@finnegan.com
Subject: Re: Flames....
Message-Id: <6mo7hg$43v$1@nnrp1.dejanews.com>

In article <358E7710.867F268A@sirius.com>,
  bowlin@sirius.com wrote:
>
> Chris Nandor wrote:
> >
> > # That's the whole point. Your talking about people who are trying to
> > # learn what "grep" is -- but you are assuming (as many posters do) that
> > # a novice should already know something before they even ask. Why would
> > # they ask if they knew how to get the answer already?
> >
> > Where does it end?  When someone asks how to turn the computer on?  Where
> > the Any key is?  You have to know how to use a computer before you can
> > program it, period.  There are degrees of usage, and degrees of
> > programming, but if you cannot search a text file, at LEAST go to an
> > appropriate place to learn it, which is NOT a programming newsgroup.
>
> [not to Chris in particular]
>
> Comment:
> These Flame threads seem circular.  IMHO the pro-flamers are giving
> moral arguments for flaming newbies, while (at least some of) the
> anti-flamers are giving practical arguments of why polite responses may
> actually be more effective at achiving the desired result which I think
> many will agree is a higher signal to noise ratio in c.l.p.m.
>
> Suggestion:
> In addition to a daily posting of the FAQ, perhaps instructions on
> how to answer newbie questions could also be posted.  Granted it might
> be difficult to achieve consensus on what these instructions should be.
> Posting these instructions could have at least three positive benefits:
>
>    1) warn newbies of what kind of responses to expect
>    2) defuse some flames i.e. "S/he was only following instructions"
>    3) cut down on the honey that is attracting unwanted posts
>
> -- Jim Bowlin
>

YES!  I'd much rather wade through newbiew questions with constructive
answers than newbiew questions with flames attached and still more flames of
flames....

I'm sure all those Perl experts out there simply visualize their code onto the
screen in one fell swoope!  Some of us though have to slog through books, FAQs
and yes even newbie posts from time to time.  Give us a break, we want to be
like you one day (well, maybe)  :)


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Tue, 23 Jun 1998 05:15:09 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How can I get the IP-Number & the Remote_Host Name
Message-Id: <MPG.ff93c2bd841c67c9896ea@nntp.hpl.hp.com>

In article <358E6C52.8065597@nortel.co.uk>, F.Quednau 
<quednauf@nortel.co.uk> says...
 ...
> Here are the environment variables that this CGI script has been
> called with.

"Here are *some of* the environment variables that this CGI script *might 
have* been called with."

You take the risk of missing some of the more interesting ones, and 
printing some that haven't been transmitted (generating warnings about 
undefined variables because of the excellent '-w' in your script).

This is a sounder (and shorter) approach:

foreach (sort keys %ENV) { print "$_ = '$ENV{$_}'\n" }

Of course, it no longer is "just one big print statement, but" you can't 
win 'em all :-).

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 23 Jun 1998 12:03:27 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: how do I get directory structure disk space used?
Message-Id: <6mo5if$pvd$4@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    admin@bwsd.com writes:
:I'm trying to a directory structure -> disk space used script.  I
:haven't the foggiest where to start.  

    $size = `du -s $dir`;

--tom
-- 
"Software Engineers are like economists." --Rob Pike


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

Date: 23 Jun 1998 12:05:00 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: how do I get directory structure disk space used?
Message-Id: <6mo5lc$pvd$5@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    admin@bwsd.com writes:
:So far I've got this, which will do one directory, but I don't know how
:to get it to recognize if the entry from a read on an opendir is a
:directory and then to loop through the directories.

That was a terrible solution, in that it wasn't a solution.
Try the more obvious and correct:

    use File::Find;
    @ARGV = ('.') unless @ARGV;
    my $sum = 0;
    find sub { $sum += -s }, @ARGV;
    print "@ARGV contains $sum bytes\n";

But you really just want du.  It's faster.

--tom
-- 
 "... the whole documentation is not unreasonably transportable in a
 student's briefcase." - John Lions describing UNIX 6th Edition
 "This has since been fixed in recent versions." - Kernighan & Pike


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

Date: 23 Jun 1998 08:30:39 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: problem: passing an array of references
Message-Id: <ra0gi6tc.fsf@mailhost.panix.com>

Todd Milligan <tmil@lle.rochester.edu> writes:

> $rv = $sth->bind_columns(\%attr, @refs_to_vars_to_bind);

> The number of references(columns to bind) will never be the the
> same.  It could be one reference or twenty.  So I thought I would
> create an array of references and pass that into the library
> function.  The problem is that I can't think af an elegent( read
> 'easy' ) way to break the array into the individual scalar
> references and use them in the call to 'bind_columns'.

I'm afraid I don't understand what the problem is.  If you've been
passed an array of scalar refs, why not simply pass them along to
bind_columns?

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf/


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

Date: 23 Jun 1998 12:08:50 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Remove blank  too much lines from a text file
Message-Id: <6mo5si$pvd$7@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Michael Zehrer <zehrer@dialup.nacamar.de> writes:
:Hi out there,
:
:Beeing not a Perl- Pro I need some advice how I can remove blank lines
:from a text file or even reduce a number of blank lines too one. 

The shell's "cat -s" reduces to one.

Perl's "print if /\S/" skips blankish lines.

--tom
-- 
Fancy algorithms are slow when n is small, and n is usually small. --Rob Pike


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

Date: 23 Jun 1998 12:11:39 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Remove blank  too much lines from a text file
Message-Id: <6mo61r$pvd$8@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, perlguy@technologist.com writes:
:You could easily do something like:
:
:open(INFILE,"$filename");
:open(OUTFILE,">$filename.out");
:
:while(<INFILE>){
: print $_ OUTFILE if($_ ne "");
:}
:
:close;

That doesn't work for so many reasons I can't begin.

--tom
-- 
    There is, however, a strange, musty smell in the air that reminds me of
    something...hmm...yes...I've got it...there's a VMS nearby, or I'm a Blit.
        --Larry Wall in Configure from the perl distribution


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

Date: 23 Jun 1998 05:10:47 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Remove blank  too much lines from a text file
Message-Id: <m390mo9v3s.fsf@windlord.Stanford.EDU>

Brent Michalski <perlguy@inlink.com> writes:

> You could easily do something like:
> open(INFILE,"$filename");
> open(OUTFILE,">$filename.out");

> while(<INFILE>){
>  print $_ OUTFILE if($_ ne "");
> }

You have the syntax of print backwards (it's print FILE LIST, not print
LIST FILE), but even with that fixed, this just copies $filename to
$filename.out.

To see why, look at what $_ actually contains when you've read in a blank
line from INFILE.  It isn't "" (the empty string).  If you printed the
empty string out to OUTFILE, you wouldn't get a blank line in OUTFILE;
you'd get nothing there at all.  Rather, a blank line is actually "\n".
So you wanted to write this as:

        while (<INFILE>) {
            print OUTFILE $_ if ($_ ne "\n");
        }

Where I writing this, I'd then take advantage of the fact that print will
print $_ if you don't tell it what to print, broaden this a bit to deal
with lines that contain only whitespace, and change the logic around a bit
and also make it more succinct, with an end result of:

        while (<INFILE>) { print OUTFILE unless /^\s+$/ }

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Tue, 23 Jun 1998 12:17:08 GMT
From: Brent Michalski <perlguy@inlink.com>
Subject: Re: Remove blank  too much lines from a text file
Message-Id: <358F9CC4.37E3E339@inlink.com>

Ok Tom, I admin it isn't perfect, or even near it. 

BUT, it does work in the simplest cases.  

I was hoping to provide it as a starting point.  If the simple solution
doesn't work, move on to something more powerful...

Brent


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

Date: 23 Jun 1998 12:50:03 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Remove blank  too much lines from a text file
Message-Id: <6mo89r$24t$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    perlguy@technologist.com writes:
:Ok Tom, I admin it isn't perfect, or even near it. 
:
:BUT, it does work in the simplest cases.  

I think not.  You wrote:

    while (<INFILE>) {
	print $_ OUTFILE if($_ ne "");
    }

How do you expect $_ to lose its newline?

--tom
-- 
"A ship then new they built for him/of mithril and of elven glass" 
    --Larry Wall in perl.c from the v5.0 perl distribution,
	citing Bilbo from Tolkien's LOTR


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

Date: 23 Jun 1998 11:53:28 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Sending files via mail in perl
Message-Id: <6mo4vo$pvd$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Russ Allbery <rra@stanford.edu> writes:
:Other people have pointed this out, but it bears repeating:  Portable code
:that runs on both Unix and Windows and Mac and who knows what else is very
:impressive, laudible, and valuable, and wholly unnecessary for 80% of what
:people write in Perl.  Possibly more.

Well said.  Much better than, "Kill the backtick killers!" :-)

--tom
-- 
    "It is easier to port a shell than a shell script."
		--Larry Wall


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

Date: Tue, 23 Jun 1998 12:21:52 GMT
From: kibbeyd@finnegan.com
Subject: Re: Sending files via mail in perl
Message-Id: <6mo6l0$32k$1@nnrp1.dejanews.com>

In article <6mllf5$oq4@vse470.vse.cz>,
  xholf03@vse.cz (xholf03) wrote:
>
> Hello again,
> don't you know how to send files via mail (using sendmail)?
> I hoped that puting new line is enough:
> print Mail "attachmnt: 1. /my_path/my_file \n";
> but it is not.
> Could you help me?
> Thanks much.
> 		filip
>
>
Download the PMLite module for Perl.  It takes all the pain out of sending a
simple e-mail.  You can even setup attachments.


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: 23 Jun 1998 12:06:44 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Simple, efficient way of checking whether $VAR is an element of set @LIST ?
Message-Id: <6mo5ok$pvd$6@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Charles Roten <croten@big.aa.net> writes:
:Yeah, it's probably a _really_ dumb question ...  

You mean like one from the FAQ?  Yup.  perlfaq4, in fact.

Here's some more clue: the moment you find yourself using 
the words "exists", "in", or "unique" with respect to a list,
you've blown it already.  You should have used a hash. 

--tom
-- 
    "It is easier to port a shell than a shell script."
		--Larry Wall


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

Date: 23 Jun 1998 04:57:25 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: system() and security again
Message-Id: <m3btrk9vq2.fsf@windlord.Stanford.EDU>

Marc Haber <Marc.Haber-usenet@gmx.de> writes:

> Are there others for a standard bash? If that differs from shell to
> shell, parsing for metacharacters may be a major nuisance and using a
> different shell will break that code :-(

I'm honestly not sure what characters exactly are considered to be
special.  There are enough that it's usually better to just avoid the
situation.

[...]

> So, I believe that

> system("/usr/bin/nice","-n","+15","/bin/tar -czf $target/$backupfile
> -X $excludelist -g $incrlist /")

> would do what I want?

> What could I do in a more general context? Obviously, splitting the
> designated command line on white space into a list won't work since that
> would have led to

> system("/usr/bin/nice","-n","+15","/bin/tar","-czf","$target/$backupfile","-X","$excludelist","-g","$incrlist","/")

> which probably won't work.

No, that's actually what you want.

system ('/usr/bin/nice', '-n', '+15', '/bin/tar', '-czf',
        "$target/$backupfile", '-X', $excludelist, '-g', $incrlist, '/');

should be exactly what you want after you've redirected output.  nice can
cope with the command it's given having arguments; otherwise, it wouldn't
work correctly from the shell either.  In general, splitting on whitespace
is what you want (although the above will handle whitespace inside
filenames as well, while the shell would have more of a problem with
that).

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 23 Jun 1998 12:15:29 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: system() and security again
Message-Id: <6mo691$pvd$9@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Marc.Haber-usenet@gmx.de (Marc Haber) writes:
:What could I do in a more general context? Obviously, splitting the
:designated command line on white space into a list won't work since
:that would have led to
:
:system("/usr/bin/nice","-n","+15","/bin/tar","-czf","$target/$backupfile","-X","$excludelist","-g","$incrlist","/")
:
:which probably won't work. While the "shell magic" of system() and
:exec() seems a fine thing, it requires major tweaking in a security
:relevant setting. Has it been consciously designed that way?

Yes, it was.  Remember what Perl was written for: to make it
convenient to glue together text, files, and commands.  It's
piggy-backing on the shell's power.  This is certainly by design.

--tom
-- 
As of next week, passwords will be entered in Morse code.


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

Date: Tue, 23 Jun 1998 12:30:34 GMT
From: Marc.Haber-usenet@gmx.de (Marc Haber)
Subject: Re: system() and security again
Message-Id: <6mo765$di9$2@nz12.rz.uni-karlsruhe.de>

Russ Allbery <rra@stanford.edu> wrote:
>No, that's actually what you want.
>
>system ('/usr/bin/nice', '-n', '+15', '/bin/tar', '-czf',
>        "$target/$backupfile", '-X', $excludelist, '-g', $incrlist, '/');
>
>should be exactly what you want after you've redirected output.  nice can
>cope with the command it's given having arguments; otherwise, it wouldn't
>work correctly from the shell either.  In general, splitting on whitespace
>is what you want (although the above will handle whitespace inside
>filenames as well, while the shell would have more of a problem with
>that).

Hm, I have seen cases where arguments like "-f filename" split into
"-f" and "filename" didn't work. However, I cannot currently think of
an example :-( We are drifting into UNIX finesse, though.

Greetings
Marc

-- 
-------------------------------------- !! No courtesy copies, please !! -----
Marc Haber          |   " Questions are the         | Mailadresse im Header
Karlsruhe, Germany  |     Beginning of Wisdom "     | Fon: *49 721 966 32 15
Nordisch by Nature  | Lt. Worf, TNG "Rightful Heir" | Fax: *49 721 966 31 29


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

Date: 23 Jun 1998 05:42:02 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: system() and security again
Message-Id: <m3vhps8f39.fsf@windlord.Stanford.EDU>

Marc Haber <Marc.Haber-usenet@gmx.de> writes:

> Hm, I have seen cases where arguments like "-f filename" split into "-f"
> and "filename" didn't work. However, I cannot currently think of an
> example :-(

That would be an incredibly pathological program, since the shell splits
"-f filename" into "-f" and "filename" before passing it to the program
and that program would therefore not work with most shells without
quoting.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: 23 Jun 1998 04:53:22 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Taint again
Message-Id: <m3emwg9vwt.fsf@windlord.Stanford.EDU>

Marc Haber <Marc.Haber-usenet@gmx.de> writes:
> Russ Allbery <rra@stanford.edu> wrote:

>> The major clumsiness is that you're reinventing File::Find for no
>> particularly good reason.

> I must be really stupid. Why the hell have I not been using a Module
> that I know exists? I even used it half a year ago. Thanks!

Someone else has pointed out that File::Find doesn't work in taint mode.
:/  So you may have good reason to not use it.  *sigh*  I sent mail to
perl5-porters seeing if there may be a way to fix that.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Tue, 23 Jun 1998 12:12:06 GMT
From: Marc.Haber-usenet@gmx.de (Marc Haber)
Subject: Re: Taint again
Message-Id: <6mo63i$dbh$1@nz12.rz.uni-karlsruhe.de>

Russ Allbery <rra@stanford.edu> wrote:
>Marc Haber <Marc.Haber-usenet@gmx.de> writes:
>> I have the following code fragment that does a "rm -rf".
>> I am far from being a perl wizard, so if that code contains some
>> clumsiness, I'd like to know what I could do better.
>
>The major clumsiness is that you're reinventing File::Find for no
>particularly good reason.

In fact, I obviously reinvented File::Path::rmtree() for no good
reason :-(

However, I learned about perl security. So, neither my nor your time
was wasted. Thanks for your comments anyway :-)

Greetings
Marc

-- 
-------------------------------------- !! No courtesy copies, please !! -----
Marc Haber          |   " Questions are the         | Mailadresse im Header
Karlsruhe, Germany  |     Beginning of Wisdom "     | Fon: *49 721 966 32 15
Nordisch by Nature  | Lt. Worf, TNG "Rightful Heir" | Fax: *49 721 966 31 29


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 2945
**************************************

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