[19662] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1857 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 2 14:10:56 2001

Date: Tue, 2 Oct 2001 11:10:12 -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: <1002046212-v10-i1857@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 2 Oct 2001     Volume: 10 Number: 1857

Today's topics:
    Re: Pattern Matching <iltzu@sci.invalid>
    Re: Pattern Matching <dtweed@acm.org>
        Perl via metasend (Donnajeanne Liu)
    Re: Perl via metasend nobull@mail.com
    Re: Reduce "cell" where should I start (newbie) <08.363340@telia.com>
    Re: Segmentation fault with Stronghold 3.0 <okhoma@voy.lviv.ua>
    Re: Sorting multidimensional arrays and MIN/MAX (Greg Bacon)
    Re: use Module vs. use module <mjcarman@home.com>
    Re: use Module vs. use module <bart.lateur@skynet.be>
        useradd and setuid (Javier Arrieta)
    Re: useradd and setuid (Garry Williams)
    Re: who said this? <bobkeys@weedcon1.cropsci.ncsu.edu>
        win32::netadmin::LocalGroupAddUsers <nick.blake@qr.com.au>
    Re: XS Question <bkennedy99@Home.com>
        Yet another fork question <djberge@qwest.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 2 Oct 2001 15:48:58 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Pattern Matching
Message-Id: <1002034280.25750@itz.pp.sci.fi>

In article <23e71812.0110011546.551771bf@posting.google.com>, shaz wrote:
>The problem now is that I am using three hashes (each contain
>different length strings). I will call them %one(longer sentences),
>%two() and %three(shorter sentences).
>
>If I am currently scanning %three and I want to see if the strings are
>present in %one and %two, I will need to use LOTS of foreach
>statements.( This slows the program A LOT).
>
>I am using the following 
>
>foreach $small(keys %three){
> if (grep { index($_, $small) != -1 } keys %two){
>  $seen{$_}=1;
> }
> if (grep { index($_, $small) != -1 } keys %one){
>  $seen{$_}=1;
> }
>}

One possible approach is to prepare a substring index of the longer
strings.  That is, you split each of the longer strings into words, or
characters, or character pairs, and create a hash where the keys are
these substrings and the values are arrays (or hashes) containing the
strings where the corresponding substring occurs.

How does that help?  Let's say you've used letters as the index keys,
and that you want to find all the long strings containing the word
"zombie".  Without an index, you'd have to look at all the strings to
see if they contain the word.

With a letter index, however, you already have a list of all the strings
containing the letter "z".  This will probably be only a small fraction
of all the strings.  You can reduce that list further by checking each
element against the list of all strings that contain "b", and so on.

Of course, at some point you will start getting diminishing returns --
if your strings are English sentences, almost all of them will contain
"e" -- so you need to decide when to stop relying on the index and do
the final grep on the remaining candidate strings.  Still, if the short
string is long enough, and you choice of index fits your data, you'll
probably have eliminated most of the possible long strings.

If the above seem a bit vague, it's because the exact details will
depend strongly on the kind of data you have -- an index that works well
on random octet strings may do really badly on English text, and vice
versa.  There are also optimizations that can be made if you only want
whole-word matches, or if most short strings will be single words, and
so on.

And of course, the best approach may be something completely different.
Efficient substring matching is by no means a simple field, and a lot of
rather thick books have been written about it.


Once you do find a suitable algorithm, the Benchmark and related modules
may be useful in testing its real-world performance.  One thing to keep
in mind is the "Keep It Simple, Stupid!" principle.  That applies more
than usual to high-level languages like Perl, where a simple built-in
operation can often be faster than a more elaborate algorithm which
needs to execute more Perl opcodes.

-- 
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real!  This is a discussion group, not a helpdesk.  You post something,
we discuss its implications.  If the discussion happens to answer a question
you've asked, that's incidental."           -- nobull in comp.lang.perl.misc



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

Date: Tue, 02 Oct 2001 17:31:13 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: Pattern Matching
Message-Id: <3BB9F893.EFEF25E5@acm.org>

Ilmari Karonen wrote:
> One possible approach is to prepare a substring index of the longer
> strings.

perldoc -f study

Unfortunately, this only works for one target string at a time, so you
need to plan your activities accordingly. It's pretty effective, though;
I use it when auto-inserting links into HTML documents.

-- Dave Tweed


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

Date: 2 Oct 2001 08:03:13 -0700
From: dliu2@umbc.edu (Donnajeanne Liu)
Subject: Perl via metasend
Message-Id: <82751023.0110020703.173bf3df@posting.google.com>

I have a code (written in Perl) to use metasend in which 2 files are
sent as attachments in 2 separate emails.

    my $mail_basecmd ='metasend -b -m "chemical/x-pdb" -m
"application/string" -e "7bit" -S 4000000 -F SANS-MODELER  ';
    my $mail_basecmd2='metasend -b -m "application/string" -e "7bit"
-S 4000000 -F SANS-MODELER  ';

#print out file for sendmail command
    open (NEWOUT, ">/tmp/email_csh");
    print NEWOUT "/usr/sbin/sendmail -i -t < /tmp/$fnameemail";
    print NEWOUT "\n";
    my $mail_cmd = $mail_basecmd . '-s '. $fname[1] .  ' -f /tmp/'.
$fname[1] .' -D '. $fname[0] . ' -t ' . $fname[2];
    print NEWOUT $mail_cmd;
    print NEWOUT "\n";
    my $mail_cmd2 = $mail_basecmd2 . '-s '. $fname[0] . ' -f /tmp/'.
$fname[0] .' -D '. $fname[0] . ' -t ' . $fname[2];
    print NEWOUT $mail_cmd2;    
    close(NEWOUT);


How do I send 1 email, using metasend, with 2 files attached?


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

Date: 02 Oct 2001 18:29:34 +0100
From: nobull@mail.com
Subject: Re: Perl via metasend
Message-Id: <u9u1xix85d.fsf@wcl-l.bham.ac.uk>

dliu2@umbc.edu (Donnajeanne Liu) writes:

[ snip Perl script that appears to construct a csh script that in turn
calls some program called metasend ]

> How do I send 1 email, using metasend, with 2 files attached?

And you Perl question was....?

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


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

Date: Tue, 02 Oct 2001 16:50:53 GMT
From: "Åke Wahlberg" <08.363340@telia.com>
Subject: Re: Reduce "cell" where should I start (newbie)
Message-Id: <Nfmu7.3240$XO2.397213@newsb.telia.net>

Thomas,

Thanks for your suggestion...

I did download the "Parse-RecDescent-1.80", and had a look ...
have you used this yourself ??, do have any example how to use it ??

Thanks
Åke.



"Thomas Bätzler" <Thomas@Baetzler.de> wrote in message
news:rsdjrtkasvk4af7f0db74bmm6l2b84bkir@4ax.com...
> On Tue, 02 Oct 2001, "Åke Wahlberg" <08.363340@telia.com> wrote:
> >I need to make this file more efficient, and I am very new to Perl, but I
> >belive that's the language to use for this...
> [...]
> >Where should I start ??, are there any "modules" functions that could
help
> >"ease" the pain ??
>
> You might want to look at Parse::RecDescent to parse your input into a
> structure that's more manageable - unless your input file is huge, in
> which case Parse::RecDescent is probably a sub-optimal choice.
>
> 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: Tue, 2 Oct 2001 17:56:06 +0300
From: "Oleh Khoma" <okhoma@voy.lviv.ua>
Subject: Re: Segmentation fault with Stronghold 3.0
Message-Id: <9pckqv$2u8o$1@news.uar.net>

> Having problems compiling Stronghold 3.0 with perl-5.6.1 embedded. Using
>
> CCFLAGS=`perl -MExtUtils::Embed -e ccopts`
> LDFLAGS=`perl -MExtUtils::Embed -e ldopts`
>
> Everything is compiled smoothly. Stronghold runs, but any request results
in
> 'Segmentation fault' in one of httpd's children.
>
> The problem is that it worked perfectly with perl-5.6.0. What could be
wrong
> when using new perl release? How to make it work?

I have found the problem:

$ perl5.6.0 -V
Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
 .....
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lcrypt
    libc=/lib/libc-2.1.92.so, so=so, useshrplib=false, libperl=libperl.a
 .....

$ perl5.6.1 -V
Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
 .....
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldb -ldl -lm -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
    libc=/lib/libc-2.2.so, so=so, useshrplib=false, libperl=libperl.a
 .....

$ perl5.6.1 -MExtUtils::Embed -e ldopts
-rdynamic  -L/usr/local/lib
/usr/local/lib/perl5/5.6.1/i686-linux/auto/DynaLoader/DynaLoader.a -L/usr/lo
cal/lib/perl5/5.6.1/i686-linux/CORE -lperl -lnsl -ldl -lm -lc -lcrypt -lutil

As you can see, perl-5.6.1 includes additional library option 'perllibs'
which actually contains the library list used to compile perl5. In the same
time ExtUtils::Embed use only 'libs' option to generate additional ld
options. They differ with one element - '-ldb'. And that was the key to
Segmentation fault.
Damn it! Is it the bug or a feature?? To my mind, ExtUtils::Embed should use
perllibs to generate list of libraries used to compile perl interpreter.
What am I missing?

-- Oleh Khoma




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

Date: Tue, 02 Oct 2001 14:50:30 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Sorting multidimensional arrays and MIN/MAX
Message-Id: <trjl1mjo83ta67@corp.supernews.com>

In article <9pb1s6$974$1@plutonium.btinternet.com>,
    S Warhurst <bigusAT@btinternetDOT.com> wrote:

: "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
: news:slrn9rfcv7.t75.mgjv@martien.heliotrope.home...
:
: > [Please in the future, put your reply _after_ the suitably trimmed text
: > you reply to. It is the commonly accepted quoting style on this
: > newsgroup, and Usenet in general]
: 
: When it is necessary to reply to particular passages of the original
: message, like now, then yes I agree, but since my reply didn't require such
: quotes and could be read "standalone" then I put it at the top where it's
: quickest & easiest to read. I maybe a relative novice to Perl but I have
: used Usenet for years and both methods are commonly accepted depending the
: context of the reply.

If your reply can stand alone, then [best Patrick Stewart imitation]
"make it so!"

Greg
-- 
That's the best thing since instant grits.
    -- Boss Hogg


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

Date: Tue, 02 Oct 2001 07:56:17 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: use Module vs. use module
Message-Id: <3BB9B971.59A71116@home.com>

Brian Helterline wrote:
> 
> So are there any ways to check this short of doing some eval
> statement?

Under 5.6+ you can use exists() to test for subroutines. So if you
expect package Foo to export the subroutine baz(), you could say
something like this:

use foo; # Typo -- should be 'Foo'

BEGIN {
    die "Import failed" unless exists &baz;
}

Note that there's no point in checking for Foo::baz. Perl found Foo.pm
(thanks to your case-insensitive OS) which means that Foo::baz does
exist; it just didn't get imported.

-mjc


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

Date: Tue, 02 Oct 2001 15:53:14 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: use Module vs. use module
Message-Id: <ldnjrtgd6s87bi1cl7f4p0v8pispsovibs@4ax.com>

Michael Carman wrote:

>use foo; # Typo -- should be 'Foo'
>
>BEGIN {
>    die "Import failed" unless exists &baz;
>}
>
>Note that there's no point in checking for Foo::baz. Perl found Foo.pm
>(thanks to your case-insensitive OS) which means that Foo::baz does
>exist; it just didn't get imported.

Not true. It's easy to loose sight of this, but the correlation of the
name of the module file and the package is a convention. Nothing more.
It's an  important convention, because the proper workings of use()
depend on it, but it's still just convention. So if your file is foo.pm
and your package is Foo, then Foo::baz may exist but foo::baz will not.

But, as I wrote before: it may be relevant to know if the package
exists, but not if the sub "import" actually exists.

Let's test this. I made an empty module Foo::Bar, just making sure the
package exists:

	package Foo::Bar;
	1;

Now let's see what's in the package stash:

	use Foo::Bar;
	use Data::Dumper;
	print Dumper \%Foo::Bar::, scalar %Foo::Bar::;
-->
	$VAR1 = {
	          'import' => *Foo::Bar::import
	        };
	$VAR2 = '1/8';

Now that's cute. Apparently perl creates a glob entry for import(), even
though it doesn't exist. The stash in scalar context gives info on how
many entries there are in the hash: 1 (in 8 buckets).

Let's change the case:

	print Dumper \%Foo::bar::, scalar %Foo::bar::;
-->
	$VAR1 = {};
	$VAR2 = 0;

An empty stash (but a valid hash reference, which surprised me a bit).
Let's see if it is in %Foo:: (unfortunately, perl insists on putting
%Foo::Bar:: as "Bar::" in %Foo::, not directly in %:: as "Foo::Bar::".
That makes this kind of mumbo jumbo harder than it could have been).

	use Foo::Bar;
	use Data::Dumper;
	print Dumper \%Foo::, scalar %Foo::;
-->
	$VAR1 = {
	          'Bar::' => *{'Foo::Bar::'}
	        };
	$VAR2 = '1/8';

Once I tested for %Foo::bar in the script, just above, then this became:

	$VAR1 = {
	          'bar' => *Foo::bar,
	          'Bar::' => *{'Foo::Bar::'}
	        };
	$VAR2 = '2/8';

So the mere mention of the stash made it come to life.

-- 
	Bart.


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

Date: 2 Oct 2001 06:18:47 -0700
From: javier_arrieta@bigfoot.com (Javier Arrieta)
Subject: useradd and setuid
Message-Id: <5088c43.0110020518.39edeb34@posting.google.com>

Hi

I've built a CGI script to add user to my system,
but when I run inside my script

system('/usr/sbin/useradd','-gnogroup','-s/dev/null',"-p$cryptpwd",$username
);

everything goes ok but the copy of /etc/skel (when running with setuid, when
run by root the command goes completely right)

Misteriously some of the files on /etc/skel are copied but others don't, and
are always the same.
The contents of /etc/skel are:

drwxr-xr-x    4 root     root         1024 sep 20 13:23 ./
drwxr-xr-x   57 root     root         4096 oct  2 12:10 ../
-rw-r--r--    1 root     root           24 dic 27  1999 .bash_logout
-rw-r--r--    1 root     root          122 ene  5  2001 .bash_profile
-rw-r--r--    1 root     root           85 ene  4  2001 .bashrc
-rw-r--r--    1 root     root          141 ago  3  2000 .mailcap
-rw-------    1 root     root          134 sep 29 12:00 .mailfilter
-rw-r--r--    1 root     root         3471 ene 21  2001 .screenrc
drwx------    6 root     root         1024 ene  4  2001 Maildir/
drwx------    2 root     root         1024 abr 11 20:08 tmp/

and the newly created user's home directory is:

-rw-r--r--    1 pepito.g nogroup        24 oct  2 12:17 .bash_logout
-rw-r--r--    1 pepito.g nogroup       122 oct  2 12:17 .bash_profile
-rw-r--r--    1 pepito.g nogroup        85 oct  2 12:17 .bashrc
-rw-r--r--    1 pepito.g nogroup       141 oct  2 12:17 .mailcap
drwx------    2 pepito.g nogroup      4096 oct  2 12:17 tmp/

Any guess?

Best regards
javier arrieta


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

Date: Tue, 02 Oct 2001 15:12:07 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: useradd and setuid
Message-Id: <slrn9rjma7.chk.garry@zfw.zvolve.net>

On 2 Oct 2001 06:18:47 -0700, Javier Arrieta
<javier_arrieta@bigfoot.com> wrote:

> I've built a CGI script to add user to my system,
> but when I run inside my script
> 
> system('/usr/sbin/useradd','-gnogroup','-s/dev/null',"-p$cryptpwd",$username
> );
> 
> everything goes ok but the copy of /etc/skel (when running with setuid, when
> run by root the command goes completely right)

Do this and all will be as you expect: 

  $< = $>;

-- 
Garry Williams


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

Date: 2 Oct 2001 14:37:04 GMT
From: BSD Bob the old greybeard BSD freak <bobkeys@weedcon1.cropsci.ncsu.edu>
Subject: Re: who said this?
Message-Id: <9pcjeg$7up$1@uni00nw.unity.ncsu.edu>

In comp.unix.questions Mike Miller <miller5286@usenetserver.com> wrote:
> I run Unix on my PC.  ;o)

I have been known to stoop so low as to run a UNIX in an emulator on
a dos 640K peecee....  Wretch!  That hurt, but it did work.....(:+}}...

                                                                          1
Was the peecee running UNIX or was UNIX running the peecee as a glass tty?

I tend to favor the latter and not the former...

>> With a PC, I always felt limited by the software available.
>> On Unix, I am limited only by my knowledge.
>>
>> --Peter J. Schoenster

Well said!  Knowledge is always the key....

Bob

1.  V5 UNIX in the Ersatz-11 PDP-11 emulator on dos 5.....(:+}}...


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

Date: Tue, 2 Oct 2001 23:49:23 +1000
From: "Nick Blake" <nick.blake@qr.com.au>
Subject: win32::netadmin::LocalGroupAddUsers
Message-Id: <9pcglf$car2@inetbws1.citec.com.au>

Connecting remotely to a server with this script.  What am I doing wrong ??

This is a sample record ROK_CEREP_CORRIE,RCENTRE\ROK_CEREP_CORRIE

script;

use Win32::NetAdmin;

while ( <> ){

 ( $groupname, $users ) = split(/,/);
Win32::NetAdmin::LocalGroupAddUsers(\\\\server, $groupname, $users) || print
"error", $groupname . "\n", $users;




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

Date: Tue, 02 Oct 2001 13:39:32 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: XS Question
Message-Id: <osju7.67751$5A3.25329484@news1.rdc2.pa.home.com>


"pkent" <adverts@teaselsyn.co.uk> wrote in message
news:adverts-94B86C.02182202102001@news.cableinet.co.uk...

> So, hopefully that makes sense as to _why_ I want to do this. The basic
> question is really: can I somehow have an extra .c source file in
> addition to my .xs file?

See the ExtUtils::MakeMaker, and use h2xs, I'm sure those is done quite
freqently - you could also compile your code into shared libraries, and
specify those locations in Makefile.PL as well.  Or, try the Inline module,
which may be easist if you don't plan on distributing anything.

--Ben Kennedy





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

Date: Tue, 2 Oct 2001 10:32:07 -0500
From: "Mr. Sunblade" <djberge@qwest.com>
Subject: Yet another fork question
Message-Id: <K1lu7.854$825.176360@news.uswest.net>

Hi all,

Solaris 8, Perl 5.6.1

I'm trying to do something relatively simple (I think):  fork a series of
ssh calls (using Net::SSH::Perl, not the system call).

When using 'wait' it works fine, but I end up executing at the same speed as
a non-forked version.  When using 'reapChild', it's clearly faster, but I'm
not getting control back at the command line.

What obvious tidbit of code am I missing?

Thanks in advance.

Mr. Sunblade

#!/usr/local/bin/perl -w

use strict;
use Net::SSH::Perl;
use Net::Netrc;
use POSIX qw(:signal_h setsid WNOHANG);

$SIG{CHLD} = \&reapChild;
$|=1; # Tried with and without

my $host = 'myhost';
my $cmd = 'ls';

my $machine = Net::Netrc->lookup($host);
my $login = $machine->login();
my $password = $machine->password();

doForkStuff();

sub doForkStuff{
   for(1..3){
      my $pid = fork();
      if($pid == 0){
         my $ssh = Net::SSH::Perl->new($host, cipher=>'Blowfish',
auth_hosts_rsa=>0);
         $ssh->login($login,$password);
         my($stdout,$stderr,$exit) = $ssh->cmd($cmd);
         print $stdout;
         exit;
      }
      else{
         #wait; # works, but then I'm just executing sequentially
         reapChild();
      }
   }
}

sub reapChild{
   do {} while waitpid(-1,&WNOHANG) > 0;
}




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

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


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