[18820] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 988 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 25 14:10:46 2001

Date: Fri, 25 May 2001 11:10:15 -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: <990814215-v10-i988@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 25 May 2001     Volume: 10 Number: 988

Today's topics:
        HELP with IPC <dennis.kowalsk@daytonoh.ncr.com>
        How can I let a user enter simple math without using 'e gls@byu.edu
    Re: How can I let a user enter simple math without usin (Mark Jason Dominus)
        offline mode data entry?vvp <vprasad@americasm01.nt.com>
    Re: offline mode data entry?vvp nobull@mail.com
    Re: offline mode data entry?vvp (Craig Berry)
    Re: parsing perl again <mischief@velma.motion.net>
    Re: Perl 5.6.1 on SCO5.0.4 - Problem with dynamic loadi <iltzu@sci.invalid>
        Perl CGI <gmoll@anakena.dcc.uchile.cl>
    Re: Perl CGI nobull@mail.com
    Re: Perl CGI (Mark Jason Dominus)
    Re: Problem with scalar variables <mischief@velma.motion.net>
    Re: Q: about combining lines of a call record file... <abe@ztreet.demon.nl>
    Re: Question on the "use strict" pragma (Mark Jason Dominus)
    Re: Question on the "use strict" pragma (Mark Jason Dominus)
    Re: Question on the "use strict" pragma nobull@mail.com
    Re: Question on the "use strict" pragma <godzilla@stomp.stomp.tokyo>
    Re: realpath(), abs_path() <postmaster@god.edu>
    Re: realpath(), abs_path() <elijah@workspot.net>
    Re: Recognize a number <pne-news-20010525@newton.digitalspace.net>
    Re: Recognize a number <pne-news-20010525@newton.digitalspace.net>
    Re: Redirecting STDERR to sendmail <iltzu@sci.invalid>
    Re: regexp for triming domainnames <godzilla@stomp.stomp.tokyo>
    Re: Sorting data file on numerical field <abe@ztreet.demon.nl>
    Re: sounder <todd@designsouth.net>
    Re: url parsing <iltzu@sci.invalid>
    Re: using quantifier on a . <iltzu@sci.invalid>
    Re: wwwboard.pl - Taint and Use Strict <hartleh1@westat.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 25 May 2001 10:29:18 -0400
From: "Dennis Kowalski" <dennis.kowalsk@daytonoh.ncr.com>
Subject: HELP with IPC
Message-Id: <3b0e6c3e$1@rpc1284.daytonoh.ncr.com>


I am trying to develope two scripts. One that creates an IPC queue and
receives off of it and the other script send message to the IPC queue.

So far I have been able to create the queue OK but when I try to send to it
I get an error of Invalid argument.

I have tried msgsnd and the SysV $msg->snd methods and both fail.

Can anyone see the error?

Here is the msgsnd version

      eval 'sub IPC_RMID {0}' unless defined &IPC_RMID;
      eval 'sub IPC_NOWAIT {0004000}' unless defined &IPC_NOWAIT;

      $key = 999;
     $queue = msgget($key, 0);

# this does return the proper id of the ipc queue
# $queue contains the id

     $message = pack("La*", 0, "XXXXXX");

     $stat = msgsnd($queue, $message, &IPC_NOWAIT) or
       die "Can not send message: $!";

Can not send message: Invalid argument at ipc2.pl line 15, <IN> chunk 3.
debugged program terminated.  Use q to quit or R to restart,

Here is the SysV version

   $key = 999;
   $queue = new IPC::Msg($key,0);
   $message = pack("La*", 0, "XXXXXX");
   $stat = $queue->snd($message,0);
msg->snd( TYPE, BUF, FLAGS ) at ipc3.pl line 19
       Carp::croak('$msg->snd( TYPE, BUF, FLAGS )') called at
/usr/local/lib/pe
l5/5.00502/IPC/Msg.pm line 98
       IPC::Msg::snd('IPC::Msg=SCALAR(0x81b0ba4)', '^@^@^@^@XXXXXX', 0)
called
at ipc3.pl line 19
debugged program terminated.  Use q to quit or R to restart,

Thanks





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

Date: 25 May 2001 11:02:00 -0600
From: gls@byu.edu
Subject: How can I let a user enter simple math without using 'eval'?
Message-Id: <u1ypdbbw7.fsf@SNOW.i-did-not-set--mail-host-address--so-shoot-me>


Uri has been on the war path lately about not using eval unless
absolutely necessary.  I have been using some evals that I thought
were fairly safe, but I thought that I would see if there is a better
way.

I want the user to enter some numbers, but I want to allow them to
enter simple arithmatic like 100+50, (326-24), 3*42, or 
(120+15 - 12)/200

currently I use code like:
    my ($hw) = param('hw') =~ m|([-+*/0-9() .]+)| ;
    $hw = eval $hw;
    my ($quiz) = param('quiz') =~ m|([-+*/0-9() .]+)| ;
    $quiz = eval $quiz;
    .
    .
    .

Then use $hw, $quiz, etc in some math later on.  (it is a cgi script,
but the data could be entered other ways also)

I do some basic detainting (even though -T does not affect evals) to
protect against a user entering "system('cat /etc/passwd')" or 
"rm *".  I guess I'm in trouble if "))((++--3" actually parses and
does something, but I expect anything like that will return undef and
I am happy with this being evaluted to 0 later on.

I know that it is possible to write a lexer/parser in something like
RecDescent, but that seems overkill for such a simple problem (and
won't something in perl be faster than something in Perl?).

So is there a better/safer way to do this, or is this one of the few
cases where an eval is ok to use?


thanks,

-- 
Greg Snow, PhD                Office: 223A TMCB
Department of Statistics      Phone:  (801) 378-7049
Brigham Young University      Dept.:  (801) 378-4505
Provo, UT  84602              email:  gls@byu.edu


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

Date: Fri, 25 May 2001 17:37:38 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: How can I let a user enter simple math without using 'eval'?
Message-Id: <3b0e9852.1f92$32@news.op.net>

In article <u1ypdbbw7.fsf@SNOW.i-did-not-set--mail-host-address--so-shoot-me>,
 <gls@byu.edu> wrote:
>I want the user to enter some numbers, but I want to allow them to
>enter simple arithmatic like 100+50, (326-24), 3*42, or 
>(120+15 - 12)/200

The way you are doing it is probably the best way.

Dennis Taylor and I tried to think about this case pretty carefully a
few months ago, and couldn't come up with any exploits.
That doesn't mean there aren't any, of course.


>I do some basic detainting (even though -T does not affect evals) 

>I know that it is possible to write a lexer/parser in something like
>RecDescent, but that seems overkill for such a simple problem 

In this case I would have to agree.

> (and won't something in perl be faster than something in Perl?).

Much.

>So is there a better/safer way to do this, or is this one of the few
>cases where an eval is ok to use?

Running the code in a 'safe' compartment with the 'Safe' module might
add another layer of security.  You could set up the compartment to
forbid all operations except for the few that you want to permit.


-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Fri, 25 May 2001 12:17:49 -0400
From: "Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com>
Subject: offline mode data entry?vvp
Message-Id: <3B0E85AC.C9F1912D@americasm01.nt.com>

Hello,

I am trying to run a .cgi script written in perl from the command line -
it shows me this:

(offline mode: enter name=value pairs on standard input)

I type in age=12 <enter>

but it does not accept the data - what do I press or key in to make it
accept the data and proceed with the script?

Thanks,

V


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

Date: 25 May 2001 17:37:47 +0100
From: nobull@mail.com
Subject: Re: offline mode data entry?vvp
Message-Id: <u9g0dt4c6c.fsf@wcl-l.bham.ac.uk>

"Prasad, Victor [FITZ:K500:EXCH]" <vprasad@americasm01.nt.com> writes:

> I am trying to run a .cgi script written in perl from the command line -
> it shows me this:
> 
> (offline mode: enter name=value pairs on standard input)
> 
> I type in age=12 <enter>
> 
> but it does not accept the data - what do I press or key in to make it
> accept the data and proceed with the script?

You have to send it an end-of-file condition.

On Unix you can do this by hitting Control-D (this has nothing to do
with Perl).

I can't recall on other OSs.  

On Windows I'd expect it to be Control-Z as that's what it was on CP/M
(and Windows is a distant decendant of CP/M) however it may be that 
Control-D works also/instead.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 25 May 2001 18:00:58 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: offline mode data entry?vvp
Message-Id: <tgt7eqq4co6ie3@corp.supernews.com>

Prasad, Victor [FITZ:K500:EXCH] (vprasad@americasm01.nt.com) wrote:
: I am trying to run a .cgi script written in perl from the command line -
: it shows me this:
: 
: (offline mode: enter name=value pairs on standard input)

Then you're using CGI.pm -- good for you.

: I type in age=12 <enter>
: 
: but it does not accept the data - what do I press or key in to make it
: accept the data and proceed with the script?

What you need to do is close the standard input stream, so that CGI.pm
knows you're done entering keyword=value pairs.  How to do this is
operating system dependent.  In a DOS shell environment, hit control-Z
followed by enter; in a Unix shell, hit control-D.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Fri, 25 May 2001 15:17:53 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: parsing perl again
Message-Id: <tgstt1o2hjt9b5@corp.supernews.com>

Damian Conway <damian@cs.monash.edu.au> wrote:
> merlyn@stonehenge.com (Randal L. Schwartz) writes:

>>>>>>> "Damian" == Damian Conway <damian@cs.monash.edu.au> writes:

>>>> P.S. I take it this implies your belief that RecDescent is capable of 
>>>> performing the monsterous task?  

>>Damian> Not as it stands. But a new version of RecDescent is also on
>>Damian> the ToDo list!

>>Will the new version of RecDescent implement Perl6, Solve the Halting
>>Problem, or be self-aware?

> It will, of course, be a superposition all of three. Unfortunately, the
> Uncertainty Principle will mean that when you use the module you'll only
> get one of those capacities (at random) at any one time.

But once the thing is self-aware, can it spawn a copy of itself in
another process to implement Perl 6? Of course, cloning a sentient
being for so little gain may be an ethical dilemma for it. 

Chris

-- 
Try not. Do, or do not. The Force is binary. -- Yoda,
The Empire Strikes Back (paraphrased)



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

Date: 25 May 2001 16:44:51 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Perl 5.6.1 on SCO5.0.4 - Problem with dynamic loading
Message-Id: <990808696.29083@itz.pp.sci.fi>

In article <slrn9gla4k.2ue.doughera@maxwell.phys.lafayette.edu>, Andy Dougherty wrote:
>
>Hmm.  It appears you've found a hole in the test suite.
>Please check the following two things:

Why am I not surprised?  The current perl test suite is, of course,
infinitely better than no test suite at all, and it is getting better
all the time.  Nonetheless, it still does bear a rather unfortunate
resemblance to a sieve, in many ways.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: 25 May 2001 15:58:56 GMT
From: Gabriel Angel Moll Ibacache <gmoll@anakena.dcc.uchile.cl>
Subject: Perl CGI
Message-Id: <9elvg0$dro$1@sunsite.dcc.uchile.cl>

Anyone knows how to "run" a CGI?
Where the CGI must be in?


-- 
saludos,
	Gabriel Moll Ibacache.-
	e-mail: gmoll@dcc.uchile.cl
	ICQ: 93278824


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

Date: 25 May 2001 17:15:15 +0100
From: nobull@mail.com
Subject: Re: Perl CGI
Message-Id: <u9ofsh4d7w.fsf@wcl-l.bham.ac.uk>

Gabriel Angel Moll Ibacache <gmoll@anakena.dcc.uchile.cl> writes:

> Anyone knows how to "run" a CGI?
> Where the CGI must be in?

A web server.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 25 May 2001 17:19:41 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Perl CGI
Message-Id: <3b0e942d.1f25$2d8@news.op.net>

In article <u9ofsh4d7w.fsf@wcl-l.bham.ac.uk>,  <nobull@mail.com> wrote:
>Gabriel Angel Moll Ibacache <gmoll@anakena.dcc.uchile.cl> writes:
>
>> Anyone knows how to "run" a CGI?
>> Where the CGI must be in?
>
>A web server.

It occurs to me that it would be very easy to write a perl program
which ran some other CGI program *as if* there were a web server
available, even when there wasn't.  Of course, it won't be an exact
simulation, but it might be close enough to be useful.

Perhaps something like this:

        #!/usr/bin/perl
        #
        # postcgi - run a CGI program that is on the local disk
        #           as if it had received a POST request
        #
        # usage: postcgi cgiprogram.cgi name=value...
        # usage: postcgi cgiprogram.cgi < form_data
        #
        # form data in a file should be zero or more lines of the form
        #    name=value
        
        my $program = shift 
          or die "Usage: $0 cgiprogram.cgi [name=value]...\n";

        unless (-t STDIN) {
          my @stdin_pairs = <STDIN>;
          chomp @stdin_pairs;
          push @ARGV, @stdin_pairs;
        }
          
        my $form_data = '';
        for (@ARGV) {
          my ($name, $value) = split /=/, $_, 2;
          $form_data .= encode($name) . '=' . encode($value) . '&';
        }
        chop $form_data;
        $ENV{CONTENT_LENGTH} = length($form_data);
        $ENV{REQUEST_METHOD} = 'POST';        
        $ENV{REMOTE_PORT} = 0;
        $ENV{SERVER_PROTOCOL} = 'HTTP/1.0';
        $ENV{REMOTE_HOST} = $ENV{REMOTE_ADDR} = '127.0.0.1';
        $ENV{SERVER_HOST} = $ENV{REMOTE_ADDR} = '127.0.0.1';
        $ENV{SERVER_PORT} = 80;
        $ENV{SCRIPT_NAME} = $program;
        
        open CGI, "| $program" 
          or die "Couldn't run $program: $!; aborting";
        print CGI $form_data;
        close CGI 
          or die "Couldn't run $program: $!; aborting";
        exit 0;

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Fri, 25 May 2001 15:15:59 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Problem with scalar variables
Message-Id: <tgstpf975aal84@corp.supernews.com>

Scott DiNitto <usenet@infracore.dyndns.org> wrote:

>>and it will break too. will you fix his bugs later for him as well?
>>
>>  SD> $variable = 3;
>>
>>  SD> eval ("\@array$variable \= \("contents\"\);");
>>
>>if that is a sample of your code, i think your wit is better.
>>

> you can say it will break it. Show me how and I will believe you. your
> all talk RESULTS.. that's what matters, and eval will produce them..
> Preach all you want... why don't you actually show what you speak
> about instead of squaking about it? I will give you time to look in an
> orielly perl reference manual.

Ever heard of the Guttman Rosler Transform? Ever wonder which
Guttman that was? (The other name comes from Larry Rosler, BTW).

Do a search on "Uri Guttman" on the web, or, better yet, search
for "Guttman" on http://www.perl.com and see who produces results.

Chris

-- 
You must not lose faith in humanity. Humanity is an ocean;
if a few drops of the ocean are dirty, the ocean does not
become dirty.  -- Mohandas K. Gandhi



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

Date: Fri, 25 May 2001 19:18:35 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Q: about combining lines of a call record file...
Message-Id: <nk4tgtso6fadelfbqhcntln3cn0goa0mg6@4ax.com>

On Wed, 23 May 2001 01:55:41 -0600, Todd Nathan
<tnathan@midwayisland.net> wrote:

> Hi,
> 
> How would i write a Perl script to combine the lines of a Call Record
> into one line...?  Thanks, and you are welcome to get a hold of me
> directly, I really appreciate your help!!!
> 
> \t
> 
> Sample of call record data follows...

They differ in structure, if this important, you should give more
information.

It looks like the records are separated by a blank line, so "paragraph
mode" looks the most simple here:

#!/usr/bin/perl -w
use strict;

my @lines = do { 
	local $/ =""; # paragraph mode
	map {join ' ' => split /\n+/} <DATA>
};

print map "$_\n\n" => @lines;
	
__DATA__
CR 16178: CallType  1 04-MAY-2001 Disc-202
  Seize 13:59:16 Ans 13:59:27 Disc 13:59:38 TS   0
     A Party:    MOBILE (11) 8084213370     Serial ed8283c4
        0013(51: 2)     13:59:16[ 1]--13:59:38[ 1]
     B Party:    MOBILE (11) 8084213400     Serial fc097b20
        0012(51: 1)     13:59:19[ 2]--13:59:38[ 1]

CR 16194: CallType  1 04-MAY-2001 Disc-202
  Seize 13:59:26 Ans 13:59:34 Disc 13:59:43 TS   0
     A Party:    MOBILE (11) 8084213456     Serial e0da83ea
        0024(51:11)     13:59:26[ 1]--13:59:43[ 1]
     B Party:    MOBILE (11) 8084213386     Serial 874a563a
        0021(51: 8)     13:59:28[ 2]--13:59:43[ 1]

CR 16162: CallType  1 04-MAY-2001 Disc-203
  Seize 13:59:12 Ans 13:59:53 Disc 13:59:53 TS  36
     A Party:    MOBILE (11) 8084213373     Serial 7713298a
        0023(51:10)     13:59:12[ 1]--13:59:53[ 1]
     B Party:      PSTN (31) 9337
        1091(36: 2)     13:59:14[ 4]--13:59:53[ 1]

-- 
Good luck, Abe
Amsterdam Perl Mongers http://amsterdam.pm.org
perl -e '$_=sub{split//,pop;print pop while@_};&$_("rekcah lreP rehtona tsuJ")'


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

Date: Fri, 25 May 2001 16:43:49 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Question on the "use strict" pragma
Message-Id: <3b0e8bc4.1e5b$3d9@news.op.net>

In article <3b0dadee$1@news.iprimus.com.au>,
Andrew Hamm <ahamm.NO$PAM@sanderson.NO$PAM.net.au> wrote:
>Leo wrote in message <9ek8l3$58n$1@plutonium.btinternet.com>...
>>
>>1. Does adding use strict to my program slow it's execution down in any
>way?
>>
>It's an instruction to the compiler. It may affect the speed of the initial
>compilation (can't say whether it slows it down or actually speeds it up)
>but it shouldn't have ANY affect at runtime. Not that I can think of.

I don't understand why people keep saying this, since "strict refs" is
obviously a run-time check.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: Fri, 25 May 2001 16:59:09 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Question on the "use strict" pragma
Message-Id: <3b0e8f49.1eaa$3b2@news.op.net>

In article <9ekbmt$ln4$3@bob.news.rcn.net>,
Eric Bohlman <ebohlman@omsdev.com> wrote:
>In comp.lang.perl.misc Leo <leapius@hotmail.com> wrote:
>> I have a few questions regarding the "use strict" pragma:
>
>> 1. Does adding use strict to my program slow it's execution down in any way?
>
>Nope.  Its effects occur only at compile time, and the time taken for the 
>extra checks is negligible compared to the I/O time the compiler spends 
>reading in your program.

I don't understand why people keep saying this, because 'strict refs'
is obviously a run-time check.  Have you run a benchmark?  Do you know
that the time is negligible?  

I think it's just more evidence that people use strict superstitiously
without really understanding what it does or what it is for.

This reminds me of a story I once heard about an experiment in primate
psychology.  Five apes were placed in a cage with a bunch of bananas.
Naturally, the apes immediately went to eat the bananas, but when they
did, they were sprayed with high-pressure jets of water.

After a while, one of the apes tried for the bananas again, and again
the apes were sprayed with cold water.

A little while later one of the apes made a move for the bananas.
Before he reached them, the other four apes, who did not want to be
sprayed again, jumped on him and pounded him to make him stop.

Then the people running the experiment removed one of the original
apes and put a new ape into the cage.  The new ape went for the
bananas right away and was shocked and dismayed to discover that the
others beat him up when he tried.  He was puzzled, but after a couple
of attempts, he gave up trying.

The people running the experiment then removed another one of the
original five apes and introduced a new ape.  This ape also learned
that the bananas were taboo.

After a while, all five of the original apes had been removed.  
None of the five apes in the cage would eat the bananas, and they
would all pound the crap out of any ape that tried, even though none
of them knew why they were doing it and none of them had ever been sprayed.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 25 May 2001 18:21:40 +0100
From: nobull@mail.com
Subject: Re: Question on the "use strict" pragma
Message-Id: <u9ae414a57.fsf@wcl-l.bham.ac.uk>

mjd@plover.com (Mark Jason Dominus) writes:

> In article <9ekbmt$ln4$3@bob.news.rcn.net>,
> Eric Bohlman <ebohlman@omsdev.com> wrote:
> >In comp.lang.perl.misc Leo <leapius@hotmail.com> wrote:
> >> I have a few questions regarding the "use strict" pragma:
> >
> >> 1. Does adding use strict to my program slow it's execution down in any way?
> >
> >Nope.  Its effects occur only at compile time, and the time taken for the 
> >extra checks is negligible compared to the I/O time the compiler spends 
> >reading in your program.
> 
> I don't understand why people keep saying this, because 'strict refs'
> is obviously a run-time check.

But the check is in the code that implements symbolic refs, to check
to see if use strict refs is in effect.  As such the very existance of
"strict refs" introduces an overhead into code that uses symbolic
references.  If your code would run under "strict refs" the only speed
gain you'll get by removing it is at compile time.

Eg:

   if (PL_op->op_private & HINT_STRICT_REFS)
     DIE(aTHX_ PL_no_symref, sym, "an ARRAY");
   gv = (GV*)gv_fetchpv(sym, TRUE, SVt_PVAV);

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 25 May 2001 10:41:31 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Question on the "use strict" pragma
Message-Id: <3B0E994B.E385320D@stomp.stomp.tokyo>

Eric Bohlman wrote:
 
> Leo  wrote:

> > I have a few questions regarding the "use strict" pragma:
 
> > 1. Does adding use strict to my program slow it's execution down in any way?
 
> Nope.  Its effects occur only at compile time, and the time taken for the
> extra checks is negible compared to the I/O time the compiler spends
> reading in your program.

Several months or more back, I posted a series of articles on
pragma induced script slow down. In those articles I used very
simple code examples, almost "hello world" type coding. My results
showed an average slow down range of six percent to ten percent,
with increasing pragma activity for very simple coding.

 
> > If so would it be a good idea to use strict when developing a program and
> > then remove it when the code is final (so my code is syntatically correct),
> > or would that be pointless?
 
> It's been compared to putting on your seat belt in the garage and taking
> it off when you get onto the road.
 
You have this backwards. There is no logical reason to leave pragma 
within a final script version. Pragma are tools for development, not
required functional components of a script.

Godzilla!


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

Date: Fri, 25 May 2001 10:34:24 -0700
From: /dev/null <postmaster@god.edu>
Subject: Re: realpath(), abs_path()
Message-Id: <3B0E97A0.8C258F24@god.edu>

On 2001/05/25 11:46 +1000, mgjv@tradingpost.com.au (Martien Verbruggen)
wrote:
[comparing filesystems and inodes]
>      is, in fact, the only way you can do it on Unix (and much faster
> than any of the other ways that try to resolve the 'real path name'.

> inode + device is easy to get to, and what you seem to need anyway.

On 2001/05/25 14:33 +0000, abigail@foad.org (Abigail) wrote:
>     $ touch /tmp/foo
>     $ ln /tmp/foo /tmp/bar
>
> /tmp/foo and /tmp/bar are the same file. However, both /tmp/foo and /tmp/bar
> are "absolute canonicalized path"s. But "/tmp/foo" ne "/tmp/bar".

Points taken.  Thanks!

--
David Alban
extasia "@" mindspring "." com
Live in a world of your own, but always welcome visitors.


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

Date: 25 May 2001 17:55:35 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: realpath(), abs_path()
Message-Id: <eli$0105251337@qz.little-neck.ny.us>

In comp.lang.perl.misc, /dev/null  <postmaster@god.edu> wrote:

Hmmm.

> On 24 May 2001, at 17:55:46 +0100, nobull@mail.com wrote:
> > In Unix unique absolute path as a concept only actually applies to
> > directories.

Only if the word 'unique' is important to you.

> Actually, an absolute canonicalized path (in unix) is one in which:
>   
>   a.  It begins with a slash ('/')
>   b.  It contains no "." or ".." components
>   c.  It contains no components which are symbolic links
>   d.  All occurrences of slashes are single slashes
> 
> I'm not sure whether 'd' is mandatory, but it is desired.

You can define it as mandatory, if you want. It certainly is
perferable if you want to strcmp() them.

> > Anyhow, you say "Did the authors not see value?".  What do _you_ see
> > as the value?  Think carefully.  I have in the past found myself
> > instictively wanting (and even inplementing) your realpath() function
> > (not just in Perl) and then realised, on refelction, that my instinct
> > is wrong.

I think it is useful to know sometimes, but I don't need it often enough
to have coded the function.

> What I want to use it for is to determine whether or not two
> different paths refer to the same file or directory.

In this case you do not want realpath(). You want to check the filesystem
device and inode. Very simple and fast, and effective in ways realpath()
would not be: multiple hard links, open but deleted files, unreadable
parent directories to a file, maybe other strange cases.

> One option is to compare the filesystem and inode of each candidate.

Exactly.

> Another is to determine the absolute canonicalized paths of each and 
> see if they are the same.

Won't work reliably.

There are some cases where realpath() is going to help you. Scanning
a list/tree of files to see if they are where they appear to be:
particularly useful if you don't want to turn on 'follow symlinks'
in your Apache httpd.conf file, etc. I work with a revision control
program that uses absolute canonicalized path to know what a file is.
I often run into problems trying to check in or out files when I
specify them in "directories" that are symlinks. (I use env variables
for all my common root "work" directories, and I have symlinks so
that the various systems I'm on can appear to use the same directory
structure, even if one has disk space in /usr/local/ and another in
/home/.)

Elijah
------
thinking of weird cases of chroot() and/or mounting loopback devices


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

Date: Fri, 25 May 2001 17:10:39 +0200
From: Philip Newton <pne-news-20010525@newton.digitalspace.net>
Subject: Re: Recognize a number
Message-Id: <1atsgt0a7aq5240202utsds9p6mjnhmj7o@4ax.com>

On 25 May 2001 14:28:07 GMT, ctcgag@hotmail.com wrote:

> They're not identical.  Notice the ^ in that regex which isn't in the
> others.

Ah, right.

However, regexes 2 and 3 are still too permissive because of the lack of
beginning-of-string/end-of-string anchors.

> More interesting is trying to recognize reals.

Fortunately, `perldoc -q determine` already has some examples so people
don't have to rack their brains anew each time. Or you can use Damian's
Regexp::Common module (e.g. $RE{num}{real} or $RE{num}{int}).

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Fri, 25 May 2001 17:10:40 +0200
From: Philip Newton <pne-news-20010525@newton.digitalspace.net>
Subject: Re: Recognize a number
Message-Id: <a9tsgt413nqckqf3cdvidlduv1vinp6nu5@4ax.com>

On Fri, 25 May 2001 13:23:41 GMT, AvA <a.v.a@home.nl> wrote:

> <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
> <html>

Please post using plain text. Thank you.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 25 May 2001 16:35:04 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Redirecting STDERR to sendmail
Message-Id: <990808333.28692@itz.pp.sci.fi>

In article <lYwO6.4490$26.46416@NewsReader>, JohnShep wrote:
>Hi,
>I have ftp access to my cron directory but no access to the logs. I want to
>email any errors to myself and so far I've come up with the structure below
>which I am afraid is as much use as a chocolate teapot. Can someone point me
>in the right direction ?

You could look on CPAN -- this sounds just like something someone
might've already written a module for.

What I'd do, however, would be simply to redirect STDERR to some file
that I do have access to.  No need to mess with e-mail then.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: Fri, 25 May 2001 09:29:53 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: regexp for triming domainnames
Message-Id: <3B0E8881.D978DAFB@stomp.stomp.tokyo>

Patrick Erler wrote:

> Godzilla! wrote:
> > Patrick Erler wrote:

(snipped)

> thanks for your answer. please go and compare them to the answers posted by
> other people, compare them in style and prejudice from your side, and know
> why nobody in you neighbourhood realy wants to talk to you...

How illogical.

I have compared answers. Not including my own, I tested six
code examples. Out of those six code examples, only two work.
Clearly two-thirds of the people whom posted to this thread
lack sufficient skill to post correct code and, are so careless
they don't test their code before posting.

Why would I be concerned about those two-thirds not talking with me?

A historical examination of articles directed at me in this group
yields ninty-nine point nine percent of those articles are hateful
troll articles, as is your article.

It would be exceptionally illogical of me to have these concerns
you have expressed. People like you are unworthy of my concern.


Godzilla!


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

Date: Fri, 25 May 2001 18:08:06 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Sorting data file on numerical field
Message-Id: <l5vsgtocthif8ei6llccrudmeao31mlp7g@4ax.com>

On 24 May 2001 04:56:26 -0700, usenet@cox99.screaming.net (Graham Cox)
wrote:

> Tony Curtis <tony_curtis32@yahoo.com> wrote in message news:<87heycki6k.fsf@limey.hpcc.uh.edu>...
> 
> > Well, it's rather difficult without seeing any code (hint)
> 
> Sorry - My mistake. The code I've got so far is at the end of this
> post. I've also tried the code Vinny posted, but i I couldn't get that
> to work either :(
> The datafile "test.txt" contains exactly what I posted last time.
> 
> 
> #!/usr/bin/perl

Let perl help you by enabling warnings and strictures:

	#!/usr/bin/perl -w
	use strict;

> print "Content-type:text/html\n\n";
> print "<html>";
> print "<body>";

You might consider using CGI.pm, it saves a lot of trouble.

> 
> open (FILE, "< test.txt") or die("File not Found");
> {
> 	local $/="\|";
> 	@spare=<FILE>;
> }

That setting of $/ introduces a bug. Now the last field of line n will
be together with the first field of line (n+1).

[ a lot of code snipped ]

Given your data and assuming the file isn't too big to read into memory
that could have looked like:

#!/usr/bin/perl -w
use strict;
use CGI qw( :standard );

# read the file
my @lines = map { chomp; [ split /\|/ ] } <DATA>;

print header, start_html( 'Sorted results' );

# print the sorted data as table
print table( { -border => 1 }, map Tr([ td( $_ ) ])
	=> sort { $a->[5] <=> $b->[5] } @lines );

print end_html;

__DATA__
a|1|2|3|4|5
bob|5|4|3|2|1
c|3|5|8|1|8
d|99|99|99|99|99
e|42|24|42|24|62

-- 
Good luck, Abe
Amsterdam Perl Mongers http://amsterdam.pm.org
perl -e '$_=sub{split//,pop;print pop while@_};&$_("rekcah lreP rehtona tsuJ")'


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

Date: Fri, 25 May 2001 16:25:51 GMT
From: "Todd Smith" <todd@designsouth.net>
Subject: Re: sounder
Message-Id: <jIvP6.70520$I5.15574970@news1.rdc1.tn.home.com>

> >i COULD, but not without learning them first. I'm a perl guy.
> >
> >
> No, you're not.
>

What gives you the authority to say that?




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

Date: 25 May 2001 17:08:47 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: url parsing
Message-Id: <990809760.29812@itz.pp.sci.fi>

In article <jPzO6.22278$BN6.931952@newsread1.prod.itd.earthlink.net>, Patrick Joyce wrote:
>Hey, my name is patrick joyce and im a newbe to perl.
>I need a program that takes a url and strips out everything but the domain

Yes, URLs can be parsed with a regexp.  In fact, RFC 2396, which is the
authoritative document on anything you wanted to know about URLs, gives
the regexp in Appendix B.  I've pasted it here for you:

  $url =~ /^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/s
       or die "Invalid URL: $url\n";

  my ($scheme, $authority, $path, $query, $fragment) = ($2,$4,$5,$7,$9);

The names of the variables are from the RFC; the part that you want is
$authority, or $4.  Note that all parts except $path may be undefined.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: 25 May 2001 16:53:33 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: using quantifier on a .
Message-Id: <990809267.29520@itz.pp.sci.fi>

In article <slrn9glf36.jrh.abigail@tsathoggua.rlyeh.net>, Abigail wrote:
>
>    {  
>       local $" = "|";
>       my @x = map {chr ($_) x 3} 0x00 .. 0xFF;  # Assuming Latin-X.
>       /^(@x)/
>    }

Hmm.. it looks like you forgot to quote your subexpressions.

  my @x = map "\Q$_"x3, map chr, 0 .. 0xff;  # still assuming no unicode

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: Fri, 25 May 2001 13:42:00 -0400
From: Henry Hartley <hartleh1@westat.com>
Subject: Re: wwwboard.pl - Taint and Use Strict
Message-Id: <3B0E9968.193D27FB@westat.com>

Uri Guttman wrote:
> 
> >>>>> "J" == Jill  <jmjlampert@aol.com> writes:
>   J> If you have something helpful and positive to say, I look forward to
>   J> hearing it.
> 
> and if you can pull the carrots out of your ears you might hear
> something and possibly learn. matt's code sux. period. nothing can be
> done but a complete rewrite. simple. nothing more to say. do you get it?
> try another question. pick another category. this is a dead point. don't
> use his code.
> 
> that is as nice as i can get when discussing that crap that is matt's
> code.

Along these lines (but in reference to a different MW Script) see:

"Security Alert: FormMail Hack - UPDATED"
<http://www.8wire.com/articles/?aid=2016>

When I started out in the web field, I didn't know any better and I
downloaded a few of Matt's scripts.  I'm not particularly brilliant when
it comes to all the security  issues but I am smart enough to recognize
good advice when I hear it.  It didn't take me long to realize that lots
of the folks here on clpm are pretty bright and if they say "don't use
this, it sucks" I figure that even if I cannot see the problem, it's
probably there.

When Uri tells you not to use these scripts, he's not doing so to make
your life more difficult.  He's a pretty nice guy and wouldn't be here
on clpm if he didn't really want to help.  If a locksmith tells you that
you don't want to use a bathroom door lock on your outside door because
it can be opened from outside, would you take his advice and buy a
"real" lock or would you tell him to stop being so mean and help you
install it?  If the locksmith has to answer this sort of question every
three or four days for a few years, he's going to get a bit terse in the
way he answers.  That's what happens here.  Be glad that someone cared
enough to warn you.  Many of the experts have long since left.  Thank
goodness some are still here.  Hang around a while and you'll figure out
who they are pretty quickly.

Before continuing, I'd suggest you read at least the CGI section (or
better yet, the entire FAQ) of the "WWW Security FAQ" at
<http://www.w3.org/Security/Faq/wwwsf4.html>.  In particular (but read
the whole section), see Q32: "I found a great CGI script on the Web and
I want to install it. How can I tell if it's safe?"  You have actually
done the first part of what it recommends, "You can never be sure that a
script is safe. The best you can do is to examine it carefully and
understand what it's doing and how it's doing it. If you don't
understand the language the script's written in, show it to someone who
does."  Of course, if you show it to someone who does (like Herr
Guttman), you should actually listen when he says it's not safe or
there's not much point in asking.

I also recommend that you read "21 Rules for Writing Secure CGI
Programs" at
<http://www.webreview.com/1997/08_08/developers/08_08_97_3.shtml>.

A good document to bookmark is the "CGI Programming MetaFAQ", found at
<http://www.smithrenaud.com/public/CGI_MetaFAQ.html#security>.  Note
that the link to the above mentioned "21 Rules" document on the metafaq
is wrong.  

Hope this helps.  Just because something seems easy and lots of people
do it that way, doesn't mean its a good idea.  Security can be tricky. 
Listen to the experts.  You'll be glad you did.

-- 
Henry Hartley


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

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


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