[19232] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1427 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 2 12:10:52 2001

Date: Thu, 2 Aug 2001 08:05:11 -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: <996764710-v10-i1427@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 2 Aug 2001     Volume: 10 Number: 1427

Today's topics:
        About PerlMagic (Win32). <sky@mail.lviv.ua>
        Can a regex or a tr/ do this sort of successive substit (Perl Girl)
    Re: Can a regex or a tr/ do this sort of successive sub <jasper@guideguide.com>
    Re: Can a regex or a tr/ do this sort of successive sub (Tad McClellan)
    Re: challenging question (Anno Siegel)
    Re: Directory Diff <lfoss@myxa.com>
        FAQ: How do I handle linked lists? <faq@denver.pm.org>
    Re: FAQ: What is the difference between $array[1] and @ nobull@mail.com
    Re: FAQ: What is the difference between $array[1] and @ (Tad McClellan)
    Re: global variables <manuel.koerner@rexroth.de>
    Re: global variables (Anno Siegel)
        how to change environnement variable in perl (Win32) <666.diablo@wanadoo.fr>
    Re: how to validate a regular expression.. <bart.lateur@skynet.be>
    Re: Is regex in grep() automatically precompiled? <bart.lateur@skynet.be>
    Re: Is regex in grep() automatically precompiled? <Tassilo.Parseval@post.rwth-aachen.de>
    Re: Is regex in grep() automatically precompiled? (Randal L. Schwartz)
    Re: join lines ? <godzilla@stomp.stomp.tokyo>
    Re: Matching Strings in an array (Yves Orton)
    Re: Module help needed! (Yves Orton)
    Re: Module help needed! (Randal L. Schwartz)
        non-blocking read on win32, how? <clarke__@__hyperformix.com>
    Re: Passing subroutine as an argument to another subrou <bart.lateur@skynet.be>
    Re: password protact a file (John Lin)
        Perl Journal Update <marshall@chezmarshall.com>
        PerlModule Apache::DBI <martinheinsdorf@codesign.net>
    Re: question on Here documents <bart.lateur@skynet.be>
        Regular expression issue <yf32@cornell.edu>
    Re: Regular expression issue <paul.johnston@dsvr.co.uk>
    Re: Reporting Questionable Programming Activity (Smiley)
    Re: Script works on PWS but not IIS? (Alex)
        substring matching and assigning to variable (joeri)
    Re: substring matching and assigning to variable <jasper@guideguide.com>
    Re: substring matching and assigning to variable <mjcarman@home.com>
    Re: The perlish way to write this? (Yves Orton)
        which module to mirror between servers? <dan@nospam_dtbakerprojects.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 02 Aug 2001 15:17:20 +0300
From: Kolorove Nebo <sky@mail.lviv.ua>
Subject: About PerlMagic (Win32).
Message-Id: <3B6944D0.EA6B71FF@mail.lviv.ua>

I'm intresting of question.
Can Perl manipulate with (for example) PS files
trough the PerlMagic modul. When i try to do command
$image->read('iii.ps');

i've got message:

Warning 315: no commands for this delgate ()
Warning 315: no delegates configuration file found (delegates.mgk)
How can i point to delagates.mgk the certain program
or module (Ghostscript)?


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

Date: 2 Aug 2001 06:49:24 -0700
From: perlgirl@hotmail.com (Perl Girl)
Subject: Can a regex or a tr/ do this sort of successive substitution?
Message-Id: <5fde2162.0108020549.531c8a1d@posting.google.com>

I need to make a char-by-char substitution of one string into another.
For example, I need to replace each '?' below with the next available
char from the second scalar. I wish to end up with:

cat
man1
dog 2
mou3se
hen  4


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

 $_='cat
 man?
 dog ?
 mou?se
 hen  ?';

 my $m='1234'; 

 s/\?/$m/geos;

 print;

I've tried various regex switches (such as -e) hoping I could coerce
this behavior but I can't seem to get it to happen. A la' Damian:
"Isn't there a better way??'

Thanks
PG


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

Date: Thu, 02 Aug 2001 14:57:02 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: Can a regex or a tr/ do this sort of successive substitution?
Message-Id: <3B695C2E.8BAF98EF@guideguide.com>

Perl Girl wrote:
> 
> I need to make a char-by-char substitution of one string into another.
> For example, I need to replace each '?' below with the next available
> char from the second scalar. I wish to end up with:
> 
> cat
> man1
> dog 2
> mou3se
> hen  4
> 
>  #!/usr/bin/perl -wd
>  use strict;
> 
>  $_='cat
>  man?
>  dog ?
>  mou?se
>  hen  ?';
> 
>  my $m='1234';
> 
>  s/\?/$m/geos;

As I'm sure you know, the s//e won't make any difference unless the
second part of the s// has some code to execute. Yours just puts '1234'
in each time.

instead you could use:

   $m = reverse $m;
   s/\?/chop $m/geos;

>  print;
> 
> I've tried various regex switches (such as -e) hoping I could coerce
> this behavior but I can't seem to get it to happen. A la' Damian:
> "Isn't there a better way??'

Oh, I'm sure there is.

> Thanks
> PG

Jasper
-- 
      split//,'019617511192'.
      '17011111610114101114'.
      '21011141011840799901'.
            '17101174';
            foreach(0..
            $#_){$_[$_
            ++]^=$_[$_
            --]^=$_[$_
]^=$_[++    $_]if!($_%
2)}$g.=$_  ,chr($g)=~
 /(\w)/&&($o.=$1and
   $g='')foreach@_;
      print"$o\n"


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

Date: Thu, 2 Aug 2001 10:03:46 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can a regex or a tr/ do this sort of successive substitution?
Message-Id: <slrn9mine2.r58.tadmc@tadmc26.august.net>

Perl Girl <perlgirl@hotmail.com> wrote:
>I need to make a char-by-char substitution of one string into another.
>For example, I need to replace each '?' below with the next available
>char from the second scalar. I wish to end up with:
>
>cat
>man1
>dog 2
>mou3se
>hen  4
>
>
> #!/usr/bin/perl -wd
> use strict;
>
> $_='cat
> man?
> dog ?
> mou?se
> hen  ?';
>
> my $m='1234'; 
>
> s/\?/$m/geos;


You should not throw options willy-nilly onto the pattern.

s///o is useless. There is no variable in your pattern.

s///s is useless. There is no dot in your pattern.

   my $i;
   s/\?/ substr($m, $i++, 1) /ge;


> print;


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


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

Date: 2 Aug 2001 10:35:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: challenging question
Message-Id: <9kbae2$rhk$1@mamenchi.zrz.TU-Berlin.DE>

According to Les Ander  <citykid@nospam.edu>:
> Hi,
> i am having hard time solving this problem and would
> appreciate any help...
> I want to generate N (uniform)random numbers in the range
> 0 to 1 and the sum of these numbers must equal 1.

You can't, except for one special case.

If numbers are uniformly distributed in [0, 1), the expected value
of each is 1/2,  so the expected value of the sum is N/2. This is
1 only for N = 2.  Since you want the result to be 1 in all cases,
the numbers *can't* be uniformly distributed.

[snip]

Didn't you ask the very same question a few days ago?  Or is it
an (unsolvable) assignment that is making the rounds?

Anno


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

Date: Thu, 02 Aug 2001 08:01:21 -0400
From: Lloyd Foss <lfoss@myxa.com>
Subject: Re: Directory Diff
Message-Id: <3B694111.715DC70@myxa.com>

Ross wrote:
> 
> I've done a backup on a UNIX directory
> to a temporary location and I'd like to find
> the files that have been changed from my
> current version of the directory. Has anyone
> written a utility to do this? What makes it a
> little tricky is that the directory has many sub-
> directories.
> --Ross

dircmp is a unix command to compare directories, unfortunately it is not
recursive.
find, sort and comm can also be used to do this
pseudocode:
	find original directory | sort >org_files.list
	find backup directory | sort >backup_files.list
	comm org_files.list backup_files.list
	
-- 
Lloyd Foss Jr
Myxa Corporation
lfoss@myxa.com


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

Date: Thu, 02 Aug 2001 12:20:27 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I handle linked lists?
Message-Id: <fAba7.67$l_m.172947968@news.frii.net>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.

+
  How do I handle linked lists?

    In general, you usually don't need a linked list in Perl, since with
    regular arrays, you can push and pop or shift and unshift at either end,
    or you can use splice to add and/or remove arbitrary number of elements
    at arbitrary points. Both pop and shift are both O(1) operations on
    Perl's dynamic arrays. In the absence of shifts and pops, push in
    general needs to reallocate on the order every log(N) times, and unshift
    will need to copy pointers each time.

    If you really, really wanted, you could use structures as described in
    the perldsc manpage or the perltoot manpage and do just what the
    algorithm book tells you to do. For example, imagine a list node like
    this:

        $node = {
            VALUE => 42,
            LINK  => undef,
        };

    You could walk the list this way:

        print "List: ";
        for ($node = $head;  $node; $node = $node->{LINK}) {
            print $node->{VALUE}, " ";
        }
        print "\n";

    You could add to the list this way:

        my ($head, $tail);
        $tail = append($head, 1);       # grow a new head
        for $value ( 2 .. 10 ) {
            $tail = append($tail, $value);
        }

        sub append {
            my($list, $value) = @_;
            my $node = { VALUE => $value };
            if ($list) {
                $node->{LINK} = $list->{LINK};
                $list->{LINK} = $node;
            } else {
                $_[0] = $node;      # replace caller's version
            }
            return $node;
        }

    But again, Perl's built-in are virtually always good enough.

- 

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to

    news:news.answers

or to the many thousands of other useful Usenet news groups.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-1999 Tom Christiansen and Nathan
    Torkington.  All rights reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.

                                                           04.44
-- 
    This space intentionally left blank


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

Date: 02 Aug 2001 13:50:11 +0100
From: nobull@mail.com
Subject: Re: FAQ: What is the difference between $array[1] and @array[1]?
Message-Id: <u9u1zq7hj0.fsf@wcl-l.bham.ac.uk>

Chris Stith <mischief@velma.motion.net> writes:

> PerlFAQ Server <faq@denver.pm.org> wrote:

> >   What is the difference between $array[1] and @array[1]?
> 
> Could this FAQ snippet ________PLEASE________ be removed from
> the autopost rotation? If not now, at least when Perl 6 is
> closer to release?

For those of us who've not been following Perl6 developments could you
please say (in a couple of lines) how this changes in Perl6.

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


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

Date: Thu, 2 Aug 2001 09:29:55 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: FAQ: What is the difference between $array[1] and @array[1]?
Message-Id: <slrn9milei.qtq.tadmc@tadmc26.august.net>

nobull@mail.com <nobull@mail.com> wrote:
>Chris Stith <mischief@velma.motion.net> writes:
>
>> PerlFAQ Server <faq@denver.pm.org> wrote:
>
>> >   What is the difference between $array[1] and @array[1]?
>> 
>> Could this FAQ snippet ________PLEASE________ be removed from
>> the autopost rotation? If not now, at least when Perl 6 is
>> closer to release?


I suggest not now, nor when closer to release.

I think they should be perl6ified only after perl6 has been released.


>For those of us who've not been following Perl6 developments could you
>please say (in a couple of lines) how this changes in Perl6.


From Damian's "Exegesis 2",

   http://dev.perl.org/perl6/exegesis/2

see the "A sigil is for life, not just for value type" section.


   In Perl 6, a scalar always has a leading $, an array always 
   has a leading @ (even when accessing its elements or slicing it), 
   and a hash always has a leading % (even when accessing its 
   entries or slicing it).

   In other words, the sigil no longer (sometimes) indicates the 
   type of the resulting value. Instead, it (always) tells you 
   exactly what kind of variable you're messing about with, 
   regardless of what kind of messing about you're doing.


So "@array[1]" is how you access the second element of the @array
in Perl 6, and "$array[1]" is short for "$array.[1]", where $array
is a reference to an array, and dot is the dereferencing operator.

( $array.[1] in perl6 ===  $array->[1] in perl5 )


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


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

Date: Thu, 2 Aug 2001 13:16:33 +0200
From: "Manuel Körner" <manuel.koerner@rexroth.de>
Subject: Re: global variables
Message-Id: <9kbcq1$1815@sunny.mannesmann.de>

here's the sourcefile which to include with require:

# filename test.pl
use strict;
package test;
our $TRUE = 1;
 ...

# sourcefile which includes the test.pl
use strict;
require "./test.pl"
 ...
return $TRUE;
 ...

error message:
"Global symbol $TRUE requires explicit package name at ...

Thank you

Manuel Körner

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> schrieb im Newsbeitrag
news:9kb6it$o31$1@mamenchi.zrz.TU-Berlin.DE...
> According to Manuel Körner <manuel.koerner@rexroth.de>:
> > hi to all,
> >
> > if i include perl source with the require command and
> > define some global variables in this source for example
> > our $TRUE = 1 and i try to access the variable in the
> > main module this would cause an error and i don't know
> > why.
>
> *sigh*
>
> How do you "define" the variable in the external source?  Is it
> in its own package, or package main?  How do you "try to access"
> the variable in the main program?  Under a fully qualified name, or
> in the default package?  Are you running under "strict"?  Finally,
> what error does it cause?
>
> Even in a seemingly simple situation you must give us *something*
> to go on.[1]
>
> BTW, it is not a good idea to introduce a particular value for boolean
> true in Perl.  Since almost every scalar value is true, a comparison
> to your $TRUE will turn out wrong in most cases.
>
> Anno
>
> [1] If I sound like Kira here, that's because she's right in some
>     things, just like stopped clock is right twice a day.  Be glad
>     I didn't ask him to "define his parameters".




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

Date: 2 Aug 2001 12:34:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: global variables
Message-Id: <9kbhc5$4ql$1@mamenchi.zrz.TU-Berlin.DE>

According to Manuel Körner <manuel.koerner@rexroth.de>:

Please place your reply below the (suitably trimmed) quoted material.

> here's the sourcefile which to include with require:
> 
> # filename test.pl
> use strict;
> package test;
> our $TRUE = 1;
> ...
> 
> # sourcefile which includes the test.pl
> use strict;
> require "./test.pl"
> ...
> return $TRUE;
> ...
> 
> error message:
> "Global symbol $TRUE requires explicit package name at ...
> 
> Thank you
> 
> Manuel Körner

Okay, so you're running under strict, which is good.  In test.pl
you declare $TRUE with our.  As "perldoc -f our" tells you, this
dispenses you from using the fully qualified $main::TRUE in the
current block. The current block is the whole file test.pl, since
"our" happens top level, but not any more.  Your main program
constitutes another block, and you need to dispense yourself again.
Add another "our $TRUE;" to the main program and all will be well.

Anno

[jeopardectomy]


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

Date: Thu, 2 Aug 2001 15:49:23 +0200
From: <666.diablo@wanadoo.fr>
Subject: how to change environnement variable in perl (Win32)
Message-Id: <9kbls6$6of$1@wanadoo.fr>

I would like to change the environnement variable called Hi

In batch file, I decare it like this:
SET Hi=Hello
And use it :
ECHO %Hi%
After I call a perl script, and I can import this value using:
$ENV{Hi}

It works for reading, but if I change $ENV{Hi}in the perl scrip:
$ENV{Hi}="Good Bye";

after the perl script is finished, the %Hi% variable is still set to Hello
instead of "Good Bye".

Do you know how to make environnement variable change in my perl script
still available after execution?

Gaetan
PS: please forward you message at 666.diablo@wanadoo.fr
thanks




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

Date: Thu, 02 Aug 2001 12:02:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: how to validate a regular expression..
Message-Id: <91gimtos8ulselp6uqpss8hden4ho2kc9s@4ax.com>

Sarah Lin wrote:

>Hi there. how do i validate a regular expression that entered by the user?
>perl will die if "(q1" is entered, and that's the thing i try to avoid..
>any PM for this? any help?
>thanks.

	$pat = '(q1';
	eval q["" =~ /$pat/];
	# use $@ as a flag (true -> error) + error message

or

	eval q[ qr/$pat/ ];


It's even safe with patterns like

	$pat = '@{[print "Hello!\n"]}';

-- 
	Bart.


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

Date: Thu, 02 Aug 2001 11:30:54 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Is regex in grep() automatically precompiled?
Message-Id: <t4dimt45ecgduqld8r6h04sm0dacdu09v4@4ax.com>

Tassilo von Parseval wrote:

>Lately I had been frequently grep()ping through @arrays, like in
>@result = grep(/$pat/, @array);
>
>$pat now could either be a string: $pat = '^ha|lo$';
>or rather a precompiled pattern: $pat = qr(^ha|lo$);
>
>Now I wonder whether Perl internally precompiles the grep-pattern for 
>the sake of performance or whether this should still be done by hand. 
>The description of grep() in the perldocs doesn't throw any light on 
>that so I hoped somehere in this group might now.

As Anno already wrote: there's nothing special about grep() that would
warrant such an entry in the docs. The same rules apply to the grep()
block as to the rest of Perl.

When I first tested qr(), I was rather disappointed with the poor
performance. It turned out that often, using just a plain string as a
pattern, was actually faster than using a precompiled qr() string!

There may have been changes to Perl's regex engine. It could be that
/$pat/ currently indeed checks to see if $pat has changed since last
time, and decide not to recompile the pattern if not. If that is the
case, even //o would not be as beneficial as it used to be, as it would
only skip the comparison. I don't know, I'm just speculating.

BTW if you need to be able to change the pattern during the run of the
script, then //o can't be used. Even then, you can always fall back on
generating a sub on the fly, from a string:

	my $grep = eval 'sub { grep /$pat/o, @_ }'
	  or die "Cannot eval grep sub: $@";
	@result = $grep->(@array);

Note that the first time you call the $grep sub (*with* a parameter),
should be in the scope of $pat, perhaps like this:

	$grep->("");


You can always benchmark.

-- 
	Bart.


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

Date: Thu, 02 Aug 2001 14:19:01 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Is regex in grep() automatically precompiled?
Message-Id: <3B694535.7080508@post.rwth-aachen.de>

Bart Lateur wrote:

>Tassilo von Parseval wrote:
>
>>Lately I had been frequently grep()ping through @arrays, like in
>>@result = grep(/$pat/, @array);
>>
>>$pat now could either be a string: $pat = '^ha|lo$';
>>or rather a precompiled pattern: $pat = qr(^ha|lo$);
>>
>>Now I wonder whether Perl internally precompiles the grep-pattern for 
>>the sake of performance or whether this should still be done by hand. 
>>The description of grep() in the perldocs doesn't throw any light on 
>>that so I hoped somehere in this group might now.
>>
>
>As Anno already wrote: there's nothing special about grep() that would
>warrant such an entry in the docs. The same rules apply to the grep()
>block as to the rest of Perl.
>

Actually I forgot that grep () is not equal to the UNIX-grep. I just 
thought, the first parameter of grep() would always be a regex but it 
can naturally be an arbitrary expression as well. That was the reason 
for my confusing question.

>When I first tested qr(), I was rather disappointed with the poor
>performance. It turned out that often, using just a plain string as a
>pattern, was actually faster than using a precompiled qr() string!
>

While waiting for replies, I made a benchmark of grep versus for-loop 
over an array with 100000 elements each with both pre-compiled and 
non-pre-compiled patterns. qr() does in fact perform slightly worse both 
for grep and for. It also shows that grep is on overage 10% quicker than 
a for-loop which sort of surprised me since I heard that grep wouldn't 
be so very performant.


Thanks for the explanations,
Tassilo

-- 
Engineering:    "How will this work?"
Science:        "Why will this work?"
Management:     "When will this work?"
Liberal Arts:   "Do you want fries with that?"




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

Date: 02 Aug 2001 06:21:10 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Is regex in grep() automatically precompiled?
Message-Id: <m1wv4miomx.fsf@halfdome.holdit.com>

>>>>> "Tassilo" == Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> writes:

Tassilo> Actually I forgot that grep () is not equal to the UNIX-grep. I just
Tassilo> thought, the first parameter of grep() would always be a regex but it
Tassilo> can naturally be an arbitrary expression as well. That was the reason
Tassilo> for my confusing question.

When we teach grep in class, we deliberately DON'T show a regex
example for the first ten bullets.  We do things like $_ % 2 for odd,
-T for all text files, and so on, thus getting the students familiar
with $_ as a placeholder.  Then when we finally fire /Perl/ on them,
it's natural as to what's happening: it's /Perl/ against that $_
placeholder.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 02 Aug 2001 05:28:08 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: join lines ?
Message-Id: <3B694758.5ECC1EA6@stomp.stomp.tokyo>

Yves Orton slobbered and drooled:
 
> Godzilla! wrote:
> > Yves Orton ignorantly and hatefully trolled:
> > > Godzilla! wrote:
> > > > Tim wrote:
> > > > > Godzilla! wrote:
> > > > > > Tim wrote:

> > > #!perl

> > Your code produces incorrect results.
 
> Prove it Lizard.  I dont think you can.

 
Clearly you don't think. Your incorrect results
serve as proof.


Godzilla!


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

Date: 2 Aug 2001 07:09:02 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Matching Strings in an array
Message-Id: <74f348f7.0108020609.700ae943@posting.google.com>

"Andrew Hamm" <ahamm@sanderson.net.au> wrote in message news:<3b68e089@news.iprimus.com.au>...
> Ryan Gralinski wrote in message ...
> If you REALLY mean you want every member of @words to be found in $cname,
> then try:
> 
> foreach $cname (@covers)
> {
>     $dang_nabbit = 0;
>     grep { $cname =~ /$_/ or $dang_nabbit = 1 } @words;
>     if(not $dang_nabbit) { do this }
> }

Or if you have a lot of elements in both arrays maybe

COVER: foreach $cname (@covers) {
        
	$cname!~/$_/ && next COVER foreach (@words); # Bail on negative match
        print $cname." matches all words\n";
}

Yves


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

Date: 2 Aug 2001 07:13:26 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Module help needed!
Message-Id: <74f348f7.0108020613.6475ccb4@posting.google.com>

BCC <a@b.c> wrote in message news:<3B66C901.8FD0673@b.c>...
> Not at all!  Thank you (and Tassilo) for very helpful replys.  
> 
> Okay, gotta go, perltoot is waiting!
> 
> Bryan
> 
> > ps (Maybe this all is more than you wanted to know??)
> > :-)

May I also recommend perlboot?

Yves


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

Date: 02 Aug 2001 07:19:57 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Module help needed!
Message-Id: <m1bslyilwy.fsf@halfdome.holdit.com>

>>>>> "Yves" == Yves Orton <demerphq@hotmail.com> writes:

Yves> BCC <a@b.c> wrote in message news:<3B66C901.8FD0673@b.c>...
>> Not at all!  Thank you (and Tassilo) for very helpful replys.  
>> 
>> Okay, gotta go, perltoot is waiting!
>> 
>> Bryan
>> 
>> > ps (Maybe this all is more than you wanted to know??)
>> > :-)

Yves> May I also recommend perlboot?

I certainly would.  But then again, I'm biased. :)

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 2 Aug 2001 08:58:48 -0500
From: "Allan" <clarke__@__hyperformix.com>
Subject: non-blocking read on win32, how?
Message-Id: <bZca7.16$cz4.38002@news.uswest.net>

I'm trying to read the standard output of a process from another
process. The read needs to be NON-BLOCKING, the reason
is that this is part of a GUI that needs to update during long
operations.

If I use a call like open(INPUT,"outputsomestuff.exe |"), I can read
from the file handle, but I hang until the executable finishes. I have
tried using IO::Handle with the nonblocking(1) call, but get the same
behavior. The classical approach is to use fileevent() but this does not
pick up output piecemeal on Win32. I have tried IO::Select, but it
works only with sockets.

Is there any solution to this? Should I regret ever being the pioneer
and pushing use of Perl (and Tk)?

Allan




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

Date: Thu, 02 Aug 2001 12:26:51 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Passing subroutine as an argument to another subroutine.
Message-Id: <lphimtgh5q5i73p8vbif7a05f9gavuchad@4ax.com>

Irfan Baig wrote:

>For example, if XX is a sub that reads down a directory tree for
>filenames. The 'source' argument is the top folder path, and then the YY sub
>is  rename(). This should effectively rename files in the tree according
>to some set of rules. *However* the rename sub can be replaced by the
>caller with, for example, unlink(), at the caller's will.
>
>Is this possible, and if so, how do I go about writing the code for this?

See the module File::Find.

You can always substitute 

	sub { ... whatever it should do ... }

for &wanted.

-- 
	Bart.


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

Date: 2 Aug 2001 07:04:18 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Re: password protact a file
Message-Id: <a73bcad1.0108020604.22955aa3@posting.google.com>

Martien Verbruggen wrote
> 	Damian James <damian@qimr.edu.au> wrote:
> > Jag Man chose Thu, 02 Aug 2001 00:16:19 GMT to say this:

> >>How can it be done from perl, any built in function?   similar to "vi -x".

> > The direct equivalent to `vi -x` would be crypt(). See `perldoc -f crypt`.

> Not really.
> The -x option to vi tells it to decrypt and encrypt a file on load and
> save.

Ya!  The OP's question is worth while considering.
For the synopsis:

perl -MX hello.pl
Input password to protect source code: ********
Enter password again: ********
Done.  Now you may run your program by: perl -MX hello.px (or just hello.px)

perl -MX hello.px
hello, world

cat hello.px
kadsfdasfjdsakfagkfdsjh

perl -MX=decrypt hello.px
Input password: ****
Invalid password, sorry.

perl -MX=decrypt hello.px
Input password: ********
Done.  hello.px decrypt to hello.pl

cat hello.pl
print "hello,world\n";

If perl provides such standard source code protection,
it would be good (or not good?) for the Perl Society.

What do you think about that?

John Lin


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

Date: Thu, 02 Aug 2001 14:57:52 GMT
From: David Marshall <marshall@chezmarshall.com>
Subject: Perl Journal Update
Message-Id: <MPG.15d334817e3f785498968d@news.earthlink.net>

The Perl Journal (http://www.tpj.com) is being reformulated as a 
quarterly supplement to Sys Admin magazine.  The first supplement will be 
"polybagged" with the October 2001 issue.

On the "Subscribe" page at http://www.tpj.com is a link by which you can 
subscribe to Sys Admin.

You can also subscribe to Sys Admin at http://www.enews.com (my 
employer), for a few bucks less.



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

Date: Thu, 02 Aug 2001 13:23:31 GMT
From: Martin Heinsdorf <martinheinsdorf@codesign.net>
Subject: PerlModule Apache::DBI
Message-Id: <3B695464.C83E6EC0@codesign.net>

I installed the personal edition of Oracle 8i on Windows2000, which
comes with an Apache web server that appears to contain mod_perl. I want
to use persistent database connections, so I uncommented the line

#PerlModule Apache::DBI

in ...\Apache\conf\httpd.conf.

After I did this, the web server will no longer start up, and there's
nothing in the error log to tell me what's wrong. Does anybody know why
the web server won't start? Is there some other configuration setting
that I need to have at the same time?

Thanks

Martin Heinsdorf



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

Date: Thu, 02 Aug 2001 12:21:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: question on Here documents
Message-Id: <4fhimtk7l0dksopqkmu5uibgnml2arfas2@4ax.com>

nobull@mail.com wrote:

>merlyn@stonehenge.com (Randal L. Schwartz) writes:
>
>>     $ perldoc -q expand function calls string
>
>>     If you prefer scalar context, similar chicanery is also useful for
>>     arbitrary expressions:
>> 
>>         print "That yields ${\($n + 5)} widgets\n";
>
>Please note: this is wrong.  See thread following the last time the FAQ
>bot posted this FAQ.

Yup.

If you prefer scalar context, use the word "scalar".

-- 
	Bart.


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

Date: Thu, 2 Aug 2001 10:42:11 -0400
From: "Young C. Fan" <yf32@cornell.edu>
Subject: Regular expression issue
Message-Id: <9kbosc$fbu$1@news01.cit.cornell.edu>

Hi,

I'm wondering if it's possible to use pass a matched pattern in a
substitution to a subroutine to handle further processing, before handing
the string back to the substitution. I know what I have below is bad syntax,
but it should illustrate what I'm trying to do.

Is this kind of thing possible, and if so, how do you do it? If not, what
can you do that's equivalent? If you can show me an example or two, that
would be really appreciated.

Thank you,

Young


$text =~ s!<tagname>(.*?)</tagname>!change($1)!sgi;

sub change {
 my ($text) = @_;
 # make changes to string passed as parameter, return changed string
}





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

Date: Thu, 02 Aug 2001 15:46:01 +0100
From: Paul Johnston <paul.johnston@dsvr.co.uk>
Subject: Re: Regular expression issue
Message-Id: <3B6967A9.E278A842@dsvr.co.uk>

Hi,

> I know what I have below is bad syntax, but it should illustrate 

You're soooooooooo nearly right.

> $text =~ s!<tagname>(.*?)</tagname>!change($1)!sgi;

$text =~ s!<tagname>(.*?)</tagname>!change($1)!sgie;
(notice the 'e' in the options)

Paul


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

Date: Thu, 02 Aug 2001 14:32:35 GMT
From: gurm@intrasof.com (Smiley)
Subject: Re: Reporting Questionable Programming Activity
Message-Id: <3b696452.366381038@news1.on.sympatico.ca>

Thank you, no.  I'm perfectly capable of editing the code myself, my
boss just wanted me to check into whether there's a group like that
set up.

>
>Would you like to hire me to fix it for you.
>
>HHJK
>
>
>



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

Date: 2 Aug 2001 06:11:45 -0700
From: samara_biz@hotmail.com (Alex)
Subject: Re: Script works on PWS but not IIS?
Message-Id: <c7d9d63c.0108020511.1585293a@posting.google.com>

> but you forgot one thing ! you perhaps dont' have ntfs on your machine and
> ntfs makes things complecated ...
> 
> the admin of the iis-server must grant the IUSR_xxx write permissions on the
> file ...

Thanks for the answer!

Actually, I do have ntfs on the local webserver. I kinda guessed that
I need write permissions for IUSR_xxx on that file, but then what
confuses me is how come I don't have that permission set on that file
on my local webserver and the script still runs.

Alex


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

Date: 2 Aug 2001 06:24:48 -0700
From: joerivdv007@hotmail.com (joeri)
Subject: substring matching and assigning to variable
Message-Id: <91052d3d.0108020524.4d5f0b78@posting.google.com>

Hi,

I need to assign a substring to a variable. The problem is that the
string contains non-alphanumeric characters. This is what I want to
do:

$spelling = substr(/alpha\(\'.*/, 7, -3)

OR

I can delete the "(" and "'" and try substr(/alpha.*/, 5) (which would
be better for me), but again that won't work.

I've read through the "Programming Perl" book, but I can't find the
answer.

Thanx,

Joeri


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

Date: Thu, 02 Aug 2001 14:51:36 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: substring matching and assigning to variable
Message-Id: <3B695AE8.79E2BB21@guideguide.com>

joeri wrote:
> 
> Hi,
> 
> I need to assign a substring to a variable. The problem is that the
> string contains non-alphanumeric characters. This is what I want to
> do:
> 
> $spelling = substr(/alpha\(\'.*/, 7, -3)
> 
> OR
> 
> I can delete the "(" and "'" and try substr(/alpha.*/, 5) (which would
> be better for me), but again that won't work.

I don't believe the // operator is doing what you think. 

substr EXPR, OFFSET, LENGTH

(from Prog. Perl)

"...extracts a substring out of the string given by EXPR and returns
it".

What is the string returned by //?

I'd start looking for an operator that's going to return your desired
string, then plug that string into substr().

Jasper
-- 
      split//,'019617511192'.
      '17011111610114101114'.
      '21011141011840799901'.
            '17101174';
            foreach(0..
            $#_){$_[$_
            ++]^=$_[$_
            --]^=$_[$_
]^=$_[++    $_]if!($_%
2)}$g.=$_  ,chr($g)=~
 /(\w)/&&($o.=$1and
   $g='')foreach@_;
      print"$o\n"


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

Date: Thu, 02 Aug 2001 08:54:23 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: substring matching and assigning to variable
Message-Id: <3B695B8F.6A489FC4@home.com>

joeri wrote:
> 
> I need to assign a substring to a variable. The problem is that the
> string contains non-alphanumeric characters. This is what I want to
> do:
> 
> $spelling = substr(/alpha\(\'.*/, 7, -3)

What's that? The first argument to substr() must be a string, not a
regex. Furthermore, substr() doesn't care whether or not your string
contains non-alphanumerics. They're just characters.

> I've read through the "Programming Perl" book, but I can't find the
> answer.

Maybe you should read perlfunc.

perldoc -f substr

substr EXPR, OFFSET, LEN, REPLACEMENT
substr EXPR, OFFSET, LEN
substr EXPR, OFFSET

    Extracts a substring out of EXPR and returns it. First character is 
    at offset 0, or whatever you've set $[ to (but don't do that). If 
    OFFSET is negative (or more precisely, less than $[), starts that 
    far from the end of the string. If LENGTH is omitted, returns 
    everything to the end of the string. If LENGTH is negative, leaves 
    that many characters off the end of the string. 

    [...]

-mjc


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

Date: 2 Aug 2001 07:30:03 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: The perlish way to write this?
Message-Id: <74f348f7.0108020630.74280dec@posting.google.com>

Uri Guttman <uri@sysarch.com> wrote in message news:<x7r8uvz4qx.fsf@home.sysarch.com>...
> >>>>> "B" == BCC  <a@b.c> writes:
> 
>   B> sub imageButton {
>   B>   my ($href, $image, $alt, $border, $align) = @_;
>   B>   $alt    = "" if !$alt;
> 
> the ||= op is a common idiom for assigning defaults. it's only weakness
> is if you had a 0 in there and wanted to keep it.
> 
> 
>   B>   $border = "0" if !$border;
>   B>   $align  = "abscenter" if !$align;
> 
> 	$border ||= '0' ;
> 	$align ||= 'abscenter ;

Just curious, Uri, as to why you prefer the above to the shift ||
syntax. (I added the mandatory stuff on my own volition) Is it a speed
issue or just personal preference?

sub imageButton {
    my $href  =shift || die "Missing mandatory parameter \$href\n";
    my $image =shift || die "Missing mandatory parameter \$image\n";
    my $alt   =shift || "";
    my $border=shift || "0";
    my $align =shift || "abscenter";

    
Yves




> 
> 
> 
>   B>   print "<a href=$href><img src=$image align=$align border=$border
>   B> alt=\'$alt\'></a>";
> 
> 
> yech! learn about perl's great variant quoting operators. either qq or a
> here doc would be much nicer there. you don't need to escape ' in a
> normal double quoted string. also you need quotes around all the tag
> values for legal html
> 
> for html i almost always use here docs:
> 
> 	print <<HTML ;
> <a href="$href"><img src="$image" align="$align" border="$border"
> alt="$alt"></a>
> HTML
> 
> uri


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

Date: Thu, 02 Aug 2001 14:04:51 GMT
From: Dan Baker <dan@nospam_dtbakerprojects.com>
Subject: which module to mirror between servers?
Message-Id: <3B695E53.3FA2687D@nospam_dtbakerprojects.com>

I have a projects coming up to mirror a specific directory of files
between two servers... actually a localhost webserver on a win98
machine, and a remote (LINUX or UNIX) host. I'm looking for a place to
start reading; input on which module(s) might be the best to use.

In the initial phases the updates will only be going one direction. from
localhost to webserver... but later I may have to deal with pulling
files that are updated on the webhost bak to the localhost.

should I just use one of the FTP modules and create my own lists of file
modify dates?

Is there a more robust module already available for webserver mirroring?

thanx,

Dan


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

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


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