[19696] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1891 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 8 14:05:37 2001

Date: Mon, 8 Oct 2001 11:05:08 -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: <1002564308-v10-i1891@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 8 Oct 2001     Volume: 10 Number: 1891

Today's topics:
    Re: Am I asking too much ??? (Tana)
        Another time source then the server time <basv@ozemail.com.au>
    Re: Another time source then the server time (Logan Shaw)
    Re: Another time source then the server time <thomas@baetzler.de>
    Re: Another time source then the server time nobull@mail.com
    Re: Another time source then the server time (T. Postel)
    Re: Bug in s/\B.//g and s/\b.//g (was: Re: Goedel JAPH) <nospam-abuse@ilyaz.org>
    Re: Call perl script in html page nobull@mail.com
        Contracts <tim_odomNOSPAM@NOSPAMhotmail.com>
        dynamic printer format (PDF?) with perl <jruano@capside.com>
    Re: dynamic printer format (PDF?) with perl (Logan Shaw)
    Re: dynamic printer format (PDF?) with perl <thomas@baetzler.de>
    Re: get "REMOTE_ADDR" with perl.. (Alan Barclay)
        hash problem (winter7)
    Re: hash problem <thomas@baetzler.de>
    Re: How to run perl under bash not sh nobull@mail.com
    Re: newbie question on passing global variable nobull@mail.com
    Re: newbie sendmail question <nospam_artd@speakeasy.net>
        Obfuscation <tim_odomNOSPAM@NOSPAMhotmail.com>
    Re: question about MAP function, please help. <thomas@baetzler.de>
    Re: SelfLoader and 'open(FH, "-|")' <nospam-abuse@ilyaz.org>
    Re: Stop Transversal of a Directory... the dot dot prob (Alun Jones)
    Re: Stop Transversal of a Directory... the dot dot prob (Bill Unruh)
    Re: strangeness (bug?) in regexp handling (Anno Siegel)
    Re: Useless use of numeric eq in void context (Mark Jason Dominus)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 8 Oct 2001 10:34:33 -0700
From: tana@acedsl.com (Tana)
Subject: Re: Am I asking too much ???
Message-Id: <4294f74d.0110080934.2eaef413@posting.google.com>

"J?gen Exner" <jurgenex@hotmail.com> wrote in message news:<3bc1a596@news.microsoft.com>...
> "Tana" <tana@acedsl.com> wrote in message
> news:4294f74d.0110070827.d0102c0@posting.google.com...
> > Yes, you all have a point there.
> > But I am not trying to get "free code" or something like that.
> 
> Actually you do.
> 
> > I am not a perl programmer, nor php programmer.
> > I am just trying to use PayPal Instant notification PERL script.
> > The PERL script provided by PayPal does not work for me, that's all.
> 
> Then why don't you ask PayPal to fix the problem? It seems it's their fault.
> 
> jue

Sure, I tried that first.
PayPal response: "While this code has been tested by PayPal, PayPal
cannot be held responsible for its use."

Tana


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

Date: Mon, 8 Oct 2001 23:13:55 +0800
From: "Bas Voordendag" <basv@ozemail.com.au>
Subject: Another time source then the server time
Message-Id: <Vojw7.1174$6q1.72829@ozemail.com.au>

Is there another time source then the server time?
I need a time other then server time, can this with Perl?
If so, how?






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

Date: 8 Oct 2001 11:08:45 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Another time source then the server time
Message-Id: <9psj2d$2g2$1@charity.cs.utexas.edu>

In article <Vojw7.1174$6q1.72829@ozemail.com.au>,
Bas Voordendag <basv@ozemail.com.au> wrote:
>Is there another time source then the server time?
>I need a time other then server time, can this with Perl?

I think you will have to be a little clearer than "the server".  What
server?  A mail server?  A file server?  A time server?  A web server?

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Mon, 08 Oct 2001 18:35:32 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: Another time source then the server time
Message-Id: <57l3st8ap4a7hcgp13pklk16fh7at90nbc@4ax.com>

On 8 Oct 2001, logan@cs.utexas.edu (Logan Shaw) wrote:

>In article <Vojw7.1174$6q1.72829@ozemail.com.au>,
>Bas Voordendag <basv@ozemail.com.au> wrote:
>>Is there another time source then the server time?
>>I need a time other then server time, can this with Perl?

>I think you will have to be a little clearer than "the server".  What
>server?  A mail server?  A file server?  A time server?  A web server?

I'm assuming the OP is talking about time() on the server. And of
course the answer to that would be to kick the sysadmin to fix the
clock - probably by using ntp or somesuch. I don't think it would be a
good idea for client code to go out and grab time info from who knows
where.

My $0.02,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: 08 Oct 2001 17:40:07 +0100
From: nobull@mail.com
Subject: Re: Another time source then the server time
Message-Id: <u9pu7yt7a0.fsf@wcl-l.bham.ac.uk>

"Bas Voordendag" <basv@ozemail.com.au> writes:

> Is there another time source then the server time?

If you have access to the Internet then there are many servers that
will be willing to tell you the time using NTP protocol.  Choose one
nearby.

> I need a time other then server time, can this with Perl?

Yes, but you are probably solving the wrong problem.  If the server's
clock is wrong then you should install (or, if it's not your server,
brow-beat the admin into installing) a time syncronisation daemon.

> If so, how?

Get a from CPAN. (Spotting an appropriate module is left as an
exercise for the reader).
 

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


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

Date: Mon, 08 Oct 2001 17:11:57 GMT
From: T.Postel@ieee.org (T. Postel)
Subject: Re: Another time source then the server time
Message-Id: <ts3nkbhq2ktq0f@corp.supernews.com>

In article <Vojw7.1174$6q1.72829@ozemail.com.au>, "Bas Voordendag" 
<basv@ozemail.com.au> wrote:
>Is there another time source then the server time?
>I need a time other then server time, can this with Perl?
>If so, how?
>
>
>
>
On page 355 of the blue Camel there is an example. Note that the default time 
out of 10 seconds may be too short for the available time servers.
I've made a few changes here:

use Socket;
sub timed_out { die "GOT TIRED OF WAITING"; }

sub getwbOff {
$timeOut =  shift;

#######################################################################
#
#Get current time from USNO, correct for my time zone.
#
#######################################################################

{
## $ST is defined elsewhere $ST = scalar localtime(time - ($wbOff));
## $wbOff is the time offset of my server.
my $SECS_of_70_YEARS = 2208988800;
my $TZ_off = 3 * 60 * 60;
my $hisiaddr;
my $proto = getprotobyname('tcp');
my $port = getservbyname('time', 'tcp');
my $host = 'tock.usno.navy.mil';

unless ($hisiaddr = inet_aton($host)) {
   warn "[$ST] Time service host: $host unknown. $!";
    }
else {
  my $hispaddr = sockaddr_in($port, $hisiaddr);
  my $rtime = '    ';

  $SIG{ALRM} = \&timed_out;              ##time out for time...
  eval {
      alarm ($timeOut);
      socket(SOCKET, PF_INET, SOCK_STREAM, $proto);
      connect(SOCKET, $hispaddr);

      read(SOCKET, $rtime, 4);
      close(SOCKET);
      alarm(0);                          ## Cancel the pending alarm if time     
                                     ##comes back.
      };

      if ($@ =~ /GOT TIRED OF WAITING/) {
        if (open (FILE, $timeFile)) {  ## $timeFile is defined elsewhere, a file 
                                       ## on my web server.
          $wbOff = <FILE> ;
          close FILE;
          }
        else { warn "[$ST] could not read time file - $!"; }
        }

      if ($rtime ne '    ') {
          my $histime = unpack("N", $rtime) - $SECS_of_70_YEARS ;
          $wbOff = ($TZ_off - $histime) + time;
          }

      if (open (FILE, ">$timeFile")) {
         print FILE $wbOff;
         close FILE;
         }
      else { warn "[$ST] could not write time file - $!"; }
    }
  }
}
##end getwbOff


-- 
While my e-mail address is not munged,     | T.Postel@ieee.org
I probably won't read anything sent there. |


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

Date: Mon, 8 Oct 2001 15:33:17 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Bug in s/\B.//g and s/\b.//g (was: Re: Goedel JAPH)
Message-Id: <9psgvt$1u57$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Bart Lateur 
<bart.lateur@skynet.be>], who wrote in article <c743st0552t3alra3inc4hc55dbbvdaq30@4ax.com>:
> >> 	$_ = 'A+B+C+D+E+F';
> >> 	s/\b(.)/X/g;

> >This may be a *very different* problem.  This guy is optimized (the
> >string is modified "in place"), *and* the boundaries change during the
> >substitution.
> 
> No they don't. Replacing a "A" or a "B" with an "X" does not change the
> word boundaries.

But replacing '+' does.

> Plus: my earlier experiences with regexes (i.e. in perls prior to 5.6)
> indicate that s///g always works on the *original*, unmodifed string.

Then your experiments are wrong.  The *intent* (if you can speak about
intent of something evolved by many different people who only hardly
understand the overall picture) is to make the behaviour
undistinguishable from what you wrote.  However, I never turned on the
HAVE_LOOKBEHIND flag for rexen which start with \b or \B.  The reason
is that such a change would slow down s/// *many times* - and "most of
the time" the substitution does not change the boundary.

The real fix (correct behaviour *and* no slowdown) may be to 

a) have two flags: HAVE_LOOKBEHIND_ONE_CHAR, HAVE_LOOKBEHIND_MANY_CHAR;

b) Special-case HAVE_LOOKBEHIND_ONE_CHAR in the "optimized"
   replace-in-place branch (save/restore the previous char);

c) Disable the "optimized" branch only if HAVE_LOOKBEHIND_MANY_CHAR.

"a" and "c" are very easy to implement.  "b" would require some
meticulous (but very localized) modification to pp_subst.

Hope this helps,
Ilya

P.S.  perl -wle '$_="aaa"; s/\b././g; print'
      ...


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

Date: 08 Oct 2001 17:42:25 +0100
From: nobull@mail.com
Subject: Re: Call perl script in html page
Message-Id: <u9n132t766.fsf@wcl-l.bham.ac.uk>

<harm.bouwman@mediasys.nl> writes:

> I'am pretty new to writing perl scripts and have have the following problem.

I'm guessing you are also probably pretty new to web programming -
which is probably more relevant.

> I have written an perl script which I what to call from an HTML page. I have
> create an HTML page like example below, but it does not work. The perl
> script itself works fine.

What you trying to do?

 1) run a Perl CGI script server-side.
 2) run a PerlScript script client-side.
 3) run a Perl CGI script server-side which constructs on-the-fly
    a PerlScript script to be run client-side.
 
> Can anybody tell me what is wrong here!

Not without knowing what you are trying to do, what you actually did,
and what happened.  If you are trying to run PerlScript script client
side are you sure the client supports PerlScript?

> <script language="PerlScript"
> src="http://mysite.com/cgi-bin/main.pl"></script>

This looks like you are trying to do (3).

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


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

Date: Mon, 08 Oct 2001 15:21:09 GMT
From: "Tim from AZ" <tim_odomNOSPAM@NOSPAMhotmail.com>
Subject: Contracts
Message-Id: <Fvjw7.43548$3d2.2417422@bgtnsc06-news.ops.worldnet.att.net>

Hello,

I recently wrote some perl CGI scripts that I will be installing on an ISP's
site as demos.  I need to write a contract that protects my copyright on the
scripts before I install them, however, and was wondering if any of the
people on this newsgroup could point me to some real world contracts that I
could read to make sure that I am covering all the bases in my own contract.
Any help with this would be greatly appreciated!

Tim






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

Date: Mon, 8 Oct 2001 18:08:27 +0200
From: "Josep Ruano Bou" <jruano@capside.com>
Subject: dynamic printer format (PDF?) with perl
Message-Id: <9psi37$pvr$1@talia.mad.ttd.net>

Hi all!
I need to generate some "printer perfect" format in a web application. I'm
thinking to generate PDF or RTF (best PDF).
I've been searching out there, but I haven't found any thing that makes what
I want.
Any body knows of any module, program, library,... that generates PDF or any
other *good* printer format from a template document??

Thanks very much for your help.

Josep Ruano Bou.
jruano@capside.com





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

Date: 8 Oct 2001 11:12:15 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: dynamic printer format (PDF?) with perl
Message-Id: <9psj8v$2i4$1@charity.cs.utexas.edu>

In article <9psi37$pvr$1@talia.mad.ttd.net>,
Josep Ruano Bou <jruano@capside.com> wrote:
>Hi all!
>I need to generate some "printer perfect" format in a web application. I'm
>thinking to generate PDF or RTF (best PDF).
>I've been searching out there, but I haven't found any thing that makes what
>I want.
>Any body knows of any module, program, library,... that generates PDF or any
>other *good* printer format from a template document??

TeX.

Or, generate postscript in your application and convert it to to pdf
using an external utility.

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Mon, 08 Oct 2001 18:36:45 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: dynamic printer format (PDF?) with perl
Message-Id: <0fl3st04lpepb7fuu7t7itsuhp8hp0blqm@4ax.com>

On Mon, 8 Oct 2001, "Josep Ruano Bou" <jruano@capside.com> wrote:
>I need to generate some "printer perfect" format in a web application. I'm
>thinking to generate PDF or RTF (best PDF).
>I've been searching out there, but I haven't found any thing that makes what
>I want.

Try http://search.cpan.org/ - lotsa PDF stuff on CPAN.

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: 8 Oct 2001 15:33:41 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: get "REMOTE_ADDR" with perl..
Message-Id: <1002555253.466184@elaine.furryape.com>

In article <9phnrj$1i7t$1@news.cis.nctu.edu.tw>,
8823559  <gis88559@ultra2.cis.nctu.edu.tw> wrote:
>Hi there,
>
>   Can anyone of you help me with this problem?  Thanks a lot..:)
>
>   It's O.K for me to get the environment variable "REMOTE_ADDR", while
>fail to get the "REMOTE_HOST".  I know some hosts turn off the feature
>for some speed concerns, the problem is, how should I turn it on again?

REMOTE_ADDR contains the IP address of the other end of the connection,
either a proxy server or the browser.

REMOTE_HOST contains the result of the DNS lookup, if the server has
lookups enabled.

If the DNS lookup fails, then there isn't anything sensible that
REMOTE_HOST can contain. 

Since about 10-20% of IP addresses don't have a lookup, it doesn't
matter what the server does, there is no answer in existance.



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

Date: 8 Oct 2001 09:22:31 -0700
From: winter7@e-mailanywhere.com (winter7)
Subject: hash problem
Message-Id: <fb7341b.0110080822.74fbe6a2@posting.google.com>

I want to manage same hash with some forked process without interference.
I tried following code.

while (defined($hash{$key})) {}
$hash{$key} = $value;
# some work
delete $hash{$key};

But race condition seems exist if two or more process are waiting on
while loop.

Is there any way to overcome this problem?
Thanks for any help.


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

Date: Mon, 08 Oct 2001 18:40:40 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: hash problem
Message-Id: <hhl3stksdmvp05biipcaqql5k43o83jmme@4ax.com>

On 8 Oct 2001 09:22:31,  winter7@e-mailanywhere.com (winter7) wrote:

>I want to manage same hash with some forked process without interference.
>I tried following code.

This won't work - forking means by definition that the child process
receives an identical copy of the parent's address space - so the
child's hash is not the parents hash. You might want to investigate
the IPC:: modules for shared memory and semaphores.

HTH,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: 08 Oct 2001 17:41:04 +0100
From: nobull@mail.com
Subject: Re: How to run perl under bash not sh
Message-Id: <u9ofnit78f.fsf@wcl-l.bham.ac.uk>

Larry Alkoff <invalid@nowhere.com> writes:

> My question is actually very much on topic in this newsgroup
> and has nothing to do with bash.

You are, of course, right.  So why did you ask a different question?
 
> It has to do with how is perl called and what shell(s) it uses
> internally.

Yep, the question you meant to ask was: "How do I control what shell
Perl uses in system/backticks/open?"

AFAIK you can't (not on Unix anyhow - ISTR there's a registry entry in
Windows).

But you can change:
  system($command)
to:
  system('/bin/bash','-c',$command)
(and so on).

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


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

Date: 08 Oct 2001 18:36:02 +0100
From: nobull@mail.com
Subject: Re: newbie question on passing global variable
Message-Id: <u9hetat4ot.fsf@wcl-l.bham.ac.uk>

Prakash Mishra <pmishra@mailcity.com> writes:

> Can I pass a global variable across different namespaces ?

Probably, if you can explain what you mean.

You may find perldac/"Typeglobs and Filehandles" helpful.

Or indeed "perldoc Exporter".

It all really depends on what you mean.

Of course you may also find it helps to explain _why_ you want to do
this as you may find there's a better way than using global variables.

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


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

Date: Mon, 8 Oct 2001 11:05:28 -0400
From: "speakeasy" <nospam_artd@speakeasy.net>
Subject: Re: newbie sendmail question
Message-Id: <ts3g692nl0f532@corp.supernews.com>

Look at Mime::Lite module..

"Jessica Bull" <jessica.bull@broadwing.com> wrote in message
news:ODiw7.655665$NK1.59898945@bin3.nnrp.aus1.giganews.com...
> I am on Win NT 4.0.  I have this script that will send mail for me.  I got
> it from another script that was writ by someone that is here no longer.  I
> know there is an easier way to do this, but I don't know what it is.  I
> looked at the FAQ's and found this module: Mail::Sendmail
> I don't know how or where to install this at. If someone could point me in
> the right direction, I would appreciate it.  Thanks.
>
>
> It dies at :
> if (!connect(S, pack('Sna4x8', AF_INET, $port, $smptaddr))) { return -3; }
>
> Here is the code that it is inside.  The box that it is running on is Win
NT
> 4.0
>
> sub Sendmail
> {
>     use Socket;
>     my ($from, $reply, $to, $smtp, $subject, $body) = @_;
>     my ($fromaddr)  = $from;
>     my ($replyaddr) = $reply;
>
>     $to        =~ s/[ \t]+/, /g;        # pack spaces and add comma
>     $fromaddr  =~ s/.*<([^\s]*?)>/$1/;  # get from email address
>     $replyaddr =~ s/.*<([^\s]*?)>/$1/;  # get reply email address
>     $replyaddr =~ s/^([^\s]+).*/$1/;    # use first address
>     if (!$to) { return -8; }
>     my($proto) = (getprotobyname('tcp'))[2];
>     my($port)  = (getservbyname('smtp', 'tcp'))[2];
>     my($smptaddr) = ($smtp
=~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
>       ? pack('C4',$1,$2,$3,$4)
>       : (gethostbyname($smtp))[4];
>
>     if (!defined($smptaddr)) { return -1; }
>     if (!socket(S, AF_INET, SOCK_STREAM, $proto)){ return -2; }
>     if (!connect(S, pack('Sna4x8', AF_INET, $port, $smptaddr)))
> { return -3; }
>     my($oldfh) = select(S); $| = 1; select($oldfh);
>     $_ = <S>; if (/^[45]/) { close S; return -4; }
>     print S "helo localhost\r\n";
>     $_ = <S>; if (/^[45]/) { close S; return -5; }
>     print S "mail from: <$fromaddr>\r\n";
>     $_ = <S>; if (/^[45]/) { close S; return -5; }
>     foreach (split(/, /, $to)) {
>  print S "rcpt to: <$_>\r\n";
>  $_ = <S>; if (/^[45]/) { close S; return -6; }
>     }
>     print S "data\r\n";
>     $_ = <S>; if (/^[45]/) { close S; return -5; }
>     print S "To: $to\r\n";
>     print S "From: $from\r\n";
>     print S "Reply-to: $replyaddr\r\n" if $replyaddr;
>     print S "X-Mailer:NDM Transfer Script \r\n";
>     print S "Subject: $subject\r\n\r\n";
>     print S "$body";
>     print S "\r\n.\r\n";
>     $_ = <S>; if (/^[45]/) { close S; return -7; }
>     print S "quit\r\n";
>     $_ = <S>;
>     close S;
>     return 1;
> }
>
>
>




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

Date: Mon, 08 Oct 2001 15:22:16 GMT
From: "Tim from AZ" <tim_odomNOSPAM@NOSPAMhotmail.com>
Subject: Obfuscation
Message-Id: <Iwjw7.43549$3d2.2417159@bgtnsc06-news.ops.worldnet.att.net>

Does anyone know of a decent program that I could use to make my perl code
harder to decifer?




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

Date: Mon, 08 Oct 2001 17:59:11 +0200
From: Thomas Bätzler <thomas@baetzler.de>
Subject: Re: question about MAP function, please help.
Message-Id: <rvi3stk0hk4thi0d34ulq77keltf350dp5@4ax.com>

On Sun, 07 Oct 2001, clintp@geeksalad.org (Clinton A. Pierce) wrote:
>map is used to iterate over one list, returning another list.  Essentially
>doing a transformation of the first into the second.  The second list can 
>be larger, smaller, related to or have nothing to do with the first list
>at all.

One thing to bear  in mind is that $_ is an alias for the elements of
the source list. If you modify $_, you also modify your input. Doing
this is usually considered a boo-boo.

If you want to have only some elements from the input list in your
output, you should probably use grep.

Just my $0.02,
-- 
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl


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

Date: Mon, 8 Oct 2001 15:38:18 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: SelfLoader and 'open(FH, "-|")'
Message-Id: <9psh9a$1u6b$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Andrew Gierth 
<andrew@erlenstar.demon.co.uk>], who wrote in article <87vghqpm77.fsf@erlenstar.demon.co.uk>:
> implemented internally I can't be certain, but my guess is that it
> actually leaves the original source FH open at that point.

Correct.

> All the
> child processes will end up sharing that FH, which means that only one
> of them will be able to read it successfully.

Hmm, should not fork() take care of this?  Oups, the docs I have state:

        o  The child process has its own  copy  of  the  parent's
           file  descriptors  and  directory streams. Each of the
           child's file descriptors shares a common file  pointer
           with  the corresponding file descriptor of the parent.

I have been always saying than fork() is a broken solution for a non-problem...

Ilya


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

Date: Mon, 08 Oct 2001 14:53:46 GMT
From: alun@texis.com (Alun Jones)
Subject: Re: Stop Transversal of a Directory... the dot dot problem
Message-Id: <_5jw7.388$fW3.137340003@newssvr11.news.prodigy.com>

In article <3BC116EB.E52C5D7A@acm.org>, Dave Tweed <dtweed@acm.org> wrote:
> Thirdly, you probably want to anchor the regex so that it only works
> at the beginning of the $filename.
> 
> Try this:
> 
>     if ($filename =~ /^~|\.\./) {print "$filename<br>\n";}

Both ~ and .. should be checked for if they occur after a directory 
separator ("/", or if you're writing for multiple platforms, also "\" for 
DOS/Windows) - after all, there're several exploits that try to access 
"dirname/../../..", or "dirname/~user".

Note - on Windows 9x and ME, should you find yourself targetting those 
platforms, watch out for multiple dots in a directory spec - the directory 
"..." refers to "../..", and "...." refers to "../../..", etc.

Alun.
~~~~

[Note that answers to questions in newsgroups are not generally
invitations to contact me personally for help in the future.]
-- 
Texas Imperial Software   | Try WFTPD, the Windows FTP Server. Find us at
1602 Harvest Moon Place   | http://www.wftpd.com or email alun@texis.com
Cedar Park TX 78613-1419  | VISA/MC accepted.  NT-based sites, be sure to
Fax/Voice +1(512)258-9858 | read details of WFTPD Pro for NT.


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

Date: 8 Oct 2001 17:57:32 GMT
From: unruh@physics.ubc.ca (Bill Unruh)
Subject: Re: Stop Transversal of a Directory... the dot dot problem
Message-Id: <9pspec$q3g$1@nntp.itservices.ubc.ca>

In <3BC10741.44644D5C@home.com> "What A Man !" <whataman@home.com> writes:

]How can I stop directory transversal with perl? I want to list all of my
]files and directories off of a sub-directory named "wkdir". and delete
]any files or directories that begin with ".." or "~" (since the shell
]can expand a "~"). The purpose is to stop people from writing in my main
]directory or other directories; and only allow them to write in "wkdir".
]This is running on a FreeBSD server.


I think you are confused. .. is NOT a filename. It is a shorthand for the parent of
the current directory. You canot delete it. If there are files which begin wit ..
they are almost certainly invalid files, or cracker files.

~ has nothing to do with filenames, it is expanded by the shell, not the
filesystem, as the home directory. If a file exists with that name, then it is
probably illegal.

rm ..?* will erase all files which begin with ..
rm ./~?* will erase all files which begin with ~.
(the ? means "match exactly one arbitrary character, meaning both of these must
have at least one character more than just the .. or the ~)

]After an extensive search of Google, here is what I have. I am doing
](print "$filename") first to see what I get in $filename. Later I will
]change (print "$filename") to unlink "$filename"; but print "$filename"
]is not working below as intended. It lists "." files such as .htaccess.,
]and subdirectories that don't even match my regex. Why?

because . in a regex matches any single character. ( as with the ? above for hte
shell). \. matches the character of the single period. also your regex says look
for ~ or .. anywhere in the filename, not at its beginning.

]use File::Find;
]sub eachFile {
]  $filename = $_;
]  $fullpath = $File::Find::name;
]# remember that File::Find changes your CWD, 
]#so you can call open with just $_
]if ($filename =~ "~|.." ) { print "$filename <BR>\n"; }
]}
]find (\&eachFile, "wkdir/");

]Kind Regards,
]--Dennis


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

Date: 8 Oct 2001 15:26:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: strangeness (bug?) in regexp handling
Message-Id: <9psgk0$a60$1@mamenchi.zrz.TU-Berlin.DE>

According to Vladimir Volovich  <vvv@vsu.ru>:
> "TB" == Thomas Bätzler writes:

[...]

>  >> i was removing everything from a string after a semicolon, except
>  >> preserving entities like &eacute;
> [...]
>  >>  the explanation above explains why i was using s/;.*//
> 
>  TB> Yes, but you didn't achieve anything because the ; was already
>  TB> gone by then - it was eaten in the first substitution. I still
>  TB> can't see what exactly it is that you're trying to do. Could you
>  TB> give a real world example?
> 
> consider the string like
> 
> Fran&ccedil;ois some < text; another text
> 
> i'd like to remove anything after (and including) the first "real"
> semicolon. By "real" i mean a semicolon which is not used to construct
> an HTML entity like the &ccedil; above (there could be any number of
> entities in a string).
> 
> i.e., in the above case the result should be
> 
> Fran&ccedil;ois some < text
> 
> so this could be accomplished by
> 
> s/&([A-Za-z0-9#]+?);/\0$1\01/g;
> s/;.*//;
> s/\0([A-Za-z0-9#]+?)\01/&$1;/g;
> 
> (or is there a simpler solution?)

Your solution is probably not overly complicated for the problem at
hand, but it depends on some data ("\01" in this case) not to appear
in the string, ever.  (Btw, Perl suggests $; for a character that is
unlikely to appear in a string.)

If we had variable-length lookbehind, that would be a straightforward
solution:

    s/(?<!&[A-Za-z0-9#]+);.*//;

should work, but is necessarily untested.

Sometimes we can reverse the string and use lookahead instead of
lookbehind.  Lookahead does variable length:

    $_ = reverse $_;
    s/^.*;(?![A-Za-z0-9#]+&)//;
    $_ = reverse $_;

You can also walk through the semicolons in a loop and check for
each one if it is part of an escape, like so:

    while ( /;/g ) {
        last unless /&[A-Za-z0-9#]+;\G/; # match before current position
    }
    $_ = substr( $_, 0, pos( $_)-1);

Another solution might involve splitting on /(&[A-Za-z0-9#]+;)/, which
would give you a list of alternating "normal text" and escapes.  You
could put them back together as needed.

None of these depends on the data to function.

Anno



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

Date: Mon, 08 Oct 2001 17:38:12 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Useless use of numeric eq in void context
Message-Id: <3bc1e483.9b8$a@news.op.net>

In article <9ps2j9$h4q$1@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>It is very likely that the actual error is within the if-block,
>which you don't show.

I think it's more likely to be in one of the elsif conditions.
Perl has that long-standing bug where if you get a warning in an
'elsif', perl reports it as being in the 'if' condition instead.

-- 
@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: 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 1891
***************************************


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