[22613] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4834 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 11 18:11:31 2003

Date: Fri, 11 Apr 2003 15:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 11 Apr 2003     Volume: 10 Number: 4834

Today's topics:
    Re: pack, unpack and 'w' <goldbb2@earthlink.net>
    Re: Perl command line and backticks <goldbb2@earthlink.net>
    Re: perl compiler for win32 platform? <nospam@raytheon.com>
    Re: Perl DBD::DB2 and security? <goldbb2@earthlink.net>
        perl problem and not so much <grobitaille@mail.com>
    Re: perl problem and not so much <emschwar@pobox.com>
    Re: perl problem and not so much <nobull@mail.com>
    Re: Questions about Perl's Unicode Model <goldbb2@earthlink.net>
    Re: Questions about Perl's Unicode Model <flavell@mail.cern.ch>
    Re: rtf conversion <bob@aol.com>
    Re: Simple (hopefully) perl Q <joec@aracnet.com>
    Re: Simple (hopefully) perl Q (Tad McClellan)
    Re: tab ctcgag@hotmail.com
    Re: Ugly code; what does it do? <michael.p.broida@boeing.com>
    Re: when break circ-refs in objects ? <goldbb2@earthlink.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 11 Apr 2003 15:08:28 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: pack, unpack and 'w'
Message-Id: <3E9712AC.D62461B7@earthlink.net>

Matthew Braid wrote:
[snip]
> # Assuming the address ($ip) is currently a string that contains a
> # hex integer, 0 padded and 32 bytes in length

   my $pip = pack("H32", $ip);

This should produce a fixed-length, 16 byte, string.

> I lose the compression,

I don't think you can have both compression (loss of leading zeros) and
sortability.

Also remember, if all 256**16 addresses are possible, than any scheme
which compresses *some* addresses to less than 16 bytes, will expand
others to more than 16 bytes.  This may be counter-intuitive, but is an
inviolable propery of all compression schemes; it's called "The
Pigeonhole Principle."

One major consequence of this is that you would need to allocate *more*
than 16 bytes of storage, if you wanted to store compressed ipv6
addresses.

> but at least (for ip6 at least) its as small as it can go while still
> being testable.... If I treat IPv4 differently (ie just a single 'L'
> pack) and structure my queries intelligently then maybe things will
> still work.

Assuming you're talking about sql queries... you do know that with most
databases, you can use <, >, =, != on table fields containing strings,
and don't need to use anything like "strcmp," right?

> > If you store packed strings of fixed length (either 4 or 16 bytes),
> > then there are no problems with having other languages deal with
> > them.  If you try and use pack("w",...), then yes, you are going to
> > have problems.
> 
> Sigh. Oh well. 16/4 bytes it is.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Fri, 11 Apr 2003 18:09:27 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl command line and backticks
Message-Id: <3E973D17.38B74FCE@earthlink.net>

Richard Gration wrote:
[snip]
> That's right. get_cchange.pl is intended to produce a list of
> substitution commands, built by reading a file cchange.txt. The context
> of this is a little global search and replace script for class names
> across a website. The idea is that the contents of cchange.txt may be
> altered, the script run again and more (ie different) search & replace
> happens. So I _do_ want the shell to interpret the backticks, and I
> _do_ want perl to use the output as a command list to -e. But it's not.

What's wrong with doing string eval() within perl?

   #!/usr/bin/perl -w
   use strict;
   my $subst = read ccgange.txt and make "s/foo/bar/; s/baz/qux/;"
   my $prog = q!
      $^I = "";
      while(<>) {
   ! . $subst . q!
      }
   !;
   eval $prog;
   __END__

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Fri, 11 Apr 2003 13:15:35 -0500
From: Chris Olive <nospam@raytheon.com>
Subject: Re: perl compiler for win32 platform?
Message-Id: <aEDla.282$35.709@dfw-service2.ext.raytheon.com>

ZZT wrote:
> Simon Andrews wrote:
> 
>> Get the latest version of PAR from CPAN.  It includes a tool called pp 
>> which will turn any Perl program into a windows .exe (you may also 
>> have to distribute a perl dll).
>>
>> It works really well now, even on complex GUI-based scripts.
>>
>> http://search.cpan.org/author/AUTRIJUS/PAR-0.67/
>>
>> Pretty easy to install too.  No C-compiler necessary, and a very 
>> helpful makefile script.
> 
> 
> Simon, where can I get the binary parl.exe ?
> I get an error back from pp:
> can't find par loader
> 
> thank you
> 

Get ActiveState's Perl for Windows: http://www.activestate.com

It's a free download and it's really killer on a Windoze box.

Chris
-----
Chris Olive
Systems Consultant
Raytheon Technical Services Corporation
Indianapolis, IN

email: olivec(AT)indy(DOT)raytheon(DOT)com



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

Date: Fri, 11 Apr 2003 18:04:11 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl DBD::DB2 and security?
Message-Id: <3E973BDB.7009A726@earthlink.net>

Johann Sander wrote:
[snip]
> I would suggest sticking with the user/password thing from perl and
> keeping authorized personnel away from the web server, and applying
> tight database security (which can be a lot of work). Remember, you
> can even revoke all table permissions from people and only grant them
> package permissions. This way you keep account hijackers from issuing
> dynamic sql against your tables. Unfortunately, you can't use DBI to
> work with packages, I believe, because DBI is all about dynamic sql.

The DBI module doesn't care about the contents of an sql query.  It just
passes it on to the database driver.

Not having read the docs, I don't know if DBD::DB2 is able to handle
packages... if it doesn't, that's it's failing, not DBI's.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Fri, 11 Apr 2003 16:00:16 -0300
From: "Gary" <grobitaille@mail.com>
Subject: perl problem and not so much
Message-Id: <2gEla.42450$cB3.287446@nnrp1.uunet.ca>

I know this is not completely a perl problem but here it goes

Is there any way from inside a cgi/perl program to evaluate if the program
is being executed because someone typed the address directly in a browser? I
have a script that I want to call from one of my pages but want to make sure
it can't be called directly by typing the address in a browser. I understand
that checking the HTTP_REFERER variable is not recommended but I would be
looking at something like that. For clarity....

The script somescript.cgi will always be called from
http://www.somedomain.com/somefile.html
I just want to make sure that you can't type in
http://www.somedomain.com/cgi-bin/somescript.cgi directly into a browser.


Is there a way with .htaccess?  <-- wow that's really not perl I am just
hoping there are lots of perl programming web server admin geniuses out
there.

Thanks all,

Gary




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

Date: 11 Apr 2003 13:16:27 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: perl problem and not so much
Message-Id: <etou1d4q1ys.fsf@wormtongue.emschwar>

"Gary" <grobitaille@mail.com> writes:
> I know this is not completely a perl problem but here it goes

It's not at all a perl problem, actually.  Here's a quick test: if you
were writing this application in INTERCAL, would you have the same
problem?  If so, it's not a Perl problem.

> Is there any way from inside a cgi/perl program to evaluate if the program
> is being executed because someone typed the address directly in a browser? 

Short answer: no.  Long answer: maybe.  
Detailed answer: comp.infosystems.www.authoring.cgi

> The script somescript.cgi will always be called from
> http://www.somedomain.com/somefile.html
> I just want to make sure that you can't type in
> http://www.somedomain.com/cgi-bin/somescript.cgi directly into a browser.

Can't be done.  You could maybe fake something up with cookies, but
those are spoof-able as well.  Ask in a CGI newsgroup; that's what
they do there.

> Is there a way with .htaccess?  <-- wow that's really not perl I am just
> hoping there are lots of perl programming web server admin geniuses out
> there.

There are also lots of web server admin geniuses on web server-related
newsgroups.  Did you think to look there?

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: 11 Apr 2003 20:21:23 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: perl problem and not so much
Message-Id: <u9n0iwc024.fsf@wcl-l.bham.ac.uk>

"Gary" <grobitaille@mail.com> writes:

> I know this is not completely a perl problem but here it goes

I see no Perl content in the question at all.
 
> Is there any way from inside a cgi/perl program to evaluate if the program
> is being executed because someone typed the address directly in a
> browser?

No there is no way to tell by looking at an HTTP request message
anything beyond the information contained in that message.

> I understand that checking the HTTP_REFERER variable is not
> recommended but I would be looking at something like that.

If the information you are looking for is in the HTTP request then it
is in the referer header.  But not all browsers generate referer
headers and anyhow any HTTP request can be faked.

> I just want to make sure that you can't type in
> http://www.somedomain.com/cgi-bin/somescript.cgi directly into a browser.

This is what we call an X-Y problem.

What is it that you really want to achieve that you think could be
achieved by preventing the user typing the URL directly?

> Is there a way with .htaccess?

The obvious quick-fix is to LIMIT to POST only.

This, of course, won't prevent someone accessing your script with
their own hand-rolled client.

>                                          ... really not perl I am just
> hoping there are lots of perl programming web server admin geniuses out
> there.

Yes and there are newgroups devoted to web server admin and CGI.

Those people who want to answer such questions will hang out in those
groups.

If you work out what it is you actually want try one of those newsgroups.

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


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

Date: Fri, 11 Apr 2003 15:33:04 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Questions about Perl's Unicode Model
Message-Id: <3E971870.CA582A9D@earthlink.net>

"Alan J. Flavell" wrote:
> 
> On Thu, Apr 10, Benjamin Goldberg inscribed on the eternal scroll:
> 
> > That's strange -- I would expect it to fail due to the SJIS encoded
> > text being incorrectly interpreted as latin-1 encoded text, *not* due
> > to it being incorrectly interpreted as utf8 encoded text.
> 
> Consider, for example, RedHat 8 ?

I knew that, really I did :P, but since the OP didn't mention his OS or
his perl version, I assumed 

perl5.8 implicitly does something like:

   use if $ENV{LANG} =~ /utf-?8/i, qw(open :std :utf8);

(Not literally, it doesn't use if.pm ... this is done in initialization
of the perlio system)

And RedHat 8 has $ENV{LANG} set to "en_US-UTF-8" ... thus, anything read
from a non-binmode()d filehandle is treated as utf8.

(In case you're thinking "use if ..." is a syntax error... no, that's
actually the if.pm module.  It's innards are vaguely like:
   package if;
   for my $meth (qw(import export)) {
      *$meth = sub {
         shift(), shift() or return;
         eval qq[require $_[0]] or die;
         my $m = $_[0]->can($meth);
         goto &$m if $m;
      };
   }
   1;
   __END__
It's not quite like this ... this code is shorter.)


-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: Fri, 11 Apr 2003 22:00:31 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Questions about Perl's Unicode Model
Message-Id: <Pine.LNX.4.53.0304112158500.26136@lxplus008.cern.ch>

On Fri, Apr 11, Benjamin Goldberg inscribed on the eternal scroll:

> "Alan J. Flavell" wrote:
> >
> > Consider, for example, RedHat 8 ?
>
> I knew that, really I did :P,

Just to make sure there's no misunderstanding here: I didn't for a
moment mean to imply that I thought you didn't.

[interesting details snipped, thanks for those...]


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

Date: Fri, 11 Apr 2003 20:30:30 GMT
From: Optional <bob@aol.com>
Subject: Re: rtf conversion
Message-Id: <lk8e9v8spuenj7srgi1rnqkou40u5qd00e@4ax.com>

I've heard a rumor that on 8 Apr 2003 19:46:04 -0700,
siu_lone@hotmail.com (siu_lone) wrote the following:

>Hi All,
> 
>I need to do some conversion daily (from rtf to excel for statistic
>calculation), the problem is:
> 
>The data from rtf file(contains a table construct by tabs):
> 
>Field1   ->   Field2   ->   Field3   ->   Field4   ->   Field5
>DataA1          ->          DataA3   ->   DataA4   ->   DataA5
>DataA1          ->          DataA3          ->     ->   DataA5
>( -> : tab)
> 
>For the printing/working on the rtf file is fine, but when i convert
>to table/copy and paste to excel (...etc I have tried many methods),
>the data is shift to the wrong location which is not belongs to its
>field (since its was delimited by tab not position):
> 
>Field1 | Field2 | Field3 | Field4 | Field5
>------------------------------------------
>DataA1 | DataA3 | DataA4 | DataA5 |
>DataA1 | DataA3 | DataA5 |        |
> 
>Actually, I have also tried study the content of the rtf file and
>wondering if we can parse them by programming:
> 
>...
>...
>\par\pard\sl360\tx129\tx1483\tx3427\tx5428\tqr\tx6652
>{\f2\fs14\b\cf8\tab Field1}
>{\f2\fs14\b\cf8\tab Field2}
>{\f2\fs14\b\cf8\tab Field3}
>{\f2\fs14\b\cf8\tab Field4}
>{\f2\fs14\b\cf8\tab Field5}
>\par\pard\sl360\tx129\tx3427\tx5428\tqr\tx6652
>{\f2\fs14\b\cf8\tab DataA1}
>{\f2\fs14\b\cf8\tab DataA3}
>{\f2\fs14\b\cf8\tab DataA4}
>{\f2\fs14\b\cf8\tab DataA5}
>\par\pard\sl360\tx129\tx3427\tqr\tx6652
>{\f2\fs14\b\cf8\tab Field1}
>{\f2\fs14\b\cf8\tab Field3}
>{\f2\fs14\b\cf8\tab Field5}
>...
>...
> 
>As you can see, the first paragraph (1st \par) is the field name with
>the fixed tab position (\txNNN).
>Can we : Insert the missing tab position (compare to the field
>paragraph) and insert a blank tab?:
> 
>...
>...
>\par\pard\sl360\tx129\tx1483\tx3427\tx5428\tqr\tx6652
>{\f2\fs14\b\cf8\tab Field1}
>{\f2\fs14\b\cf8\tab Field2}
>{\f2\fs14\b\cf8\tab Field3}
>{\f2\fs14\b\cf8\tab Field4}
>{\f2\fs14\b\cf8\tab Field5}
>\par\pard\sl360\tx129\tx1483\tx3427\tx5428\tqr\tx6652
>{\f2\fs14\b\cf8\tab DataA1}
>{\f2\fs14\b\cf8\tab }                      <- blank tab
>{\f2\fs14\b\cf8\tab DataA3}
>{\f2\fs14\b\cf8\tab DataA4}
>{\f2\fs14\b\cf8\tab DataA5}
>\par\pard\sl360\tx129\tx1483\tx3427\tx5428\tqr\tx6652
>{\f2\fs14\b\cf8\tab Field1}
>{\f2\fs14\b\cf8\tab }                      <- blank tab
>{\f2\fs14\b\cf8\tab Field3}
>{\f2\fs14\b\cf8\tab }                      <- blank tab
>{\f2\fs14\b\cf8\tab Field5}
>...
>...
> 
>(or i just make thing more difficult to solve?)
> 
>Thanks alot!
>Fred

Hi Fred,

Is there a way could export in a different format than rtf?  You amy
want to also take a look at some of the rtf modules on http://cpan.org

Also you might want to take a look at the Spreadsheet::WriteExcel
module.  Very handy...


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

Date: Fri, 11 Apr 2003 11:12:04 -0700
From: Joseph Cipale <joec@aracnet.com>
Subject: Re: Simple (hopefully) perl Q
Message-Id: <3E970574.EE0B59D@aracnet.com>

Michael Budash wrote:
> 
> In article <3E96FB7F.1A61725@aracnet.com>,
>  Joseph Cipale <joec@aracnet.com> wrote:
> 
> [snip]
> > Once I perform a 'chomp' on $_, the data is converted to a value of '1'.
> [snip]
> 
> perldoc -f chomp
> 
> hint: what does 'chomp' return?
> 
> hth-
> 
> --
> Michael Budash

Thanks Michael!

Gots it...

Joe
--


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

Date: Fri, 11 Apr 2003 15:08:11 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Simple (hopefully) perl Q
Message-Id: <slrnb9e85b.1v7.tadmc@magna.augustmail.com>

Joseph Cipale <joec@aracnet.com> wrote:

> Subject: Simple (hopefully) perl Q


Please put the subject of your article in the Subject of your article.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 11 Apr 2003 19:58:45 GMT
From: ctcgag@hotmail.com
Subject: Re: tab
Message-Id: <20030411155845.804$N5@newsreader.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:

> That happens to work, but only because Perl Does What I Mean and
> interprets the string "\t" as a regular expression.  The correct
> way to specify the split parameter is
>
>     @rec = split /\t/, $line;
>
> The only exception is the string " ", which split() interprets as /\s+/.

Actually, I don't think there is any regex split pattern which
produces the same results as " " does.  /\s+/ doesn't surpress leading
empty fields, while " " does.

(and I just discovered that " " is only special if it's hard-coded
into the split, if you split on a variable containing " " it behaves
just like / / would).

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Fri, 11 Apr 2003 21:14:00 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Ugly code; what does it do?
Message-Id: <3E973018.7BDDF6FE@boeing.com>

"Michael P. Broida" wrote:
> 

[SNIP]

>                 # $_ contains the string to parse
>                 # BEGIN and END are the opening and closing markers for the
>                 # nested text.
>                 @( = ('(','');
>                 @) = (')','');
>                 ($re=$_)=~s/((BEGIN)|(END)|.)/$)[!$3]\Q$1\E$([!$2]/gs;
>                 @$ = (eval{/$re/},$@!~/unmatched/);
>                 print join("\n",@$[0..$#$]) if( $$[-1] );

[SNIP]

	OK, in other posts, people have explained all the bits of
	the above UGLY code except for ONE part.

	At the very end, I don't understand the use of:
			if( $$[-1] );

	OK,  $$[x]  is the xth element of array @$ created in the
	preceding line.  But I don't understand the index of -1.

	My only guess is that it's related to an empty array having
	$#arrayname = -1, but I wouldn't have expected Perl to allow
	a direct reference to element number -1.

	Please let me know if my guess is correct, or what the
	REAL meaning of that bit is.

		Thanks again!
			Mike


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

Date: Fri, 11 Apr 2003 16:27:01 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: when break circ-refs in objects ?
Message-Id: <3E972515.EF7D964@earthlink.net>

peter pilsl wrote:
[snip]

use strict;
use Scalar::Util qw(weaken);
package Test;

sub new {
   my $class = shift;
   my $self = {};
   $self->{self} = $self;
   weaken $self->{self}; # <-- important line!
   return bless $self, shift;
}

sub DESTROY {
   warn "Destroying $_[0]";
}

> ps: I cannot avoid the circular references, cause I use anonymous subs
> that include anonymous subs which are all refered from my object ...

In pre-5.8, if you have an anon sub defined from within another anon
sub, then there is an unavoidable circular reference between the two.

I don't recall whether this was actually fixed in 5.8.0, or whether the
patch only came in for 5.9/5.8.1.

In any case, if you want to avoid memory leaks, no anon sub should be
defined directly within another anon sub.  Instead, write a non-
anonymous helper subroutine, to create the "inner" anon sub.

That is, where you have code like:

sub foo {
   my ($var1, $var2) = ...
   return sub {
      my ($var3, $var4) = ...;
      return sub {
         stuff which uses $vars 1..4.
      };
   };
}

Change it to code like:

sub foo {
   my ($var1, $var2) = ...
   return sub {
      my ($var3, $var4) = ...;
      return foo_helper($var1, $var2, $var3, $var4);
   };
}
sub foo_helper {
   my ($var1, $var2, $var3, $var4) = @_;
   return sub {
      stuff which uses $vars 1..4.
   }
}

Thus, the "inner" anonymous sub is now created directly within a named
sub, instead of within another anonymous sub.

-- 
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}


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

Date: 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 4834
***************************************


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