[10140] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3733 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 16 20:07:19 1998

Date: Wed, 16 Sep 98 17:01:16 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 16 Sep 1998     Volume: 8 Number: 3733

Today's topics:
    Re: and? or? (logical operator question) (Mark-Jason Dominus)
        Comparing arrays ? (Phil Taylor)
    Re: Diff between two text files (Mike)
    Re: Help with Perl problem (Martien Verbruggen)
    Re: how safe is xor encryption ? (Michael J Gebis)
    Re: how safe is xor encryption ? <eashton@bbnplanet.com>
    Re: how safe is xor encryption ? (Abigail)
    Re: how safe is xor encryption ? (Michael J Gebis)
    Re: how safe is xor encryption ? (Mark-Jason Dominus)
    Re: how safe is xor encryption ? <uri@camel.fastserv.com>
    Re: how safe is xor encryption ? (Michael J Gebis)
    Re: how safe is xor encryption ? beyret@my-dejanews.com
    Re: Is there any FAQ? <jhi@alpha.hut.fi>
    Re: milliseconds? (Andrew M. Langmead)
    Re: newbie DATE question (Abigail)
    Re: Perl & Java - differences and uses (Sean McAfee)
    Re: Perl & Java - differences and uses <uri@camel.fastserv.com>
    Re: Perl & Java - differences and uses (Abigail)
    Re: Printing lines between patterns (Abigail)
        Remove files/Dir help <sales@madm.com>
    Re: splitting by certain spaces (Abigail)
    Re: STD I/O for WIN32 Perl (Tye McQueen)
    Re: STDOUT into array (Martien Verbruggen)
        trying to use print<<END; with CGI.pm <alanson@umich.edu>
        Unix Perl server? <jdubois@keane.com>
    Re: Uploading & Downloading <jdubois@keane.com>
    Re: Who posts original posts on CLPM? <rick.delaney@shaw.wave.ca>
    Re: Who posts original posts on CLPM? <sauvin@osmic.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 16 Sep 1998 19:50:44 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: and? or? (logical operator question)
Message-Id: <6tpisk$7pm$1@monet.op.net>

In article <36001932.1329@DejahsPrivateIce.com>,
Mary E Tyler  <dejah@DejahsPrivateIce.com> wrote:
>open (SLOG, ">>$MyLog") and open (CLOG, ">>$MyComments") or die"etc";
>maybe what i really want to know is: will this work?

Yes.

Also, if the first open fails, it'll die immediately without trying
the second file.  (This is what you would expect from the C `&&'
operator.)



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

Date: Wed, 16 Sep 1998 22:29:29 GMT
From: phil@ackltd.demon.co.uk (Phil Taylor)
Subject: Comparing arrays ?
Message-Id: <36003a0f.14962015@news.demon.co.uk>

I've got an array which contains a series of codes ie

@array1 = ("01", "02");

and I have another array which contains the above codes with a decode
separated by a colon ie

@array2 = ("01:Element01", "02:Element02", "03:Element03", ........)

I want to end up with @array2 to only contain elements relating to
codes "01" and "02" ie

@array2 =  ("01:Element01", "02:Element02")

Can anyone suggest a neat way to achieve this?

Thanks

Phil 


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

Date: 16 Sep 1998 21:34:00 GMT
From: schutzmd@SPAMFREEjmu.edu (Mike)
Subject: Re: Diff between two text files
Message-Id: <6tpas8$f06$1@lark.jmu.edu>

Srikanth Natarajan (nkanth@cnd.hp.com) wrote:
> Hi

> Is there a way to compare two text files for differences in
> Perl

> I need to write code which works on both NT and UNIX


Just create two scalar arrays, and use regular file input to populate the
arrays.  Then just compare the arrays by index, and you're all set.  Of
course you'll have to create a simply line-counting algorithm, depending
on how you want to synchronize the arrays when lines are different.

- mike -


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

Date: Wed, 16 Sep 1998 23:13:33 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Help with Perl problem
Message-Id: <xCXL1.15$G65.107504@nsw.nnrp.telstra.net>

Please read the following information on how to choose a good subject
line: http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

In article <35ff46d5.1266349@news.netkonect.co.uk>,
	mike @debtware.co.uk writes:
> Can anyone kelp me please. I am trying to write a perl program where I
> pass two arguments on then command line. The first is the input file
> the second is the output file.
> 
> The command line reads:
> 
> perl myprog.pl filename1 filename2
> 
> In the code I have:
> 
> $file1 = @ARGV[0]
> $file2 = @ARGV[1]

Those are array slices. You probably wanted $ARGV[0] and $ARGV[1].

> open (InFile, $file1);
> open (OutFile, $file2);

You don't check to see if the open succeeded:

open (INFILE, $file1) || die "Couldn't open '$file1' for read: $!";

Also, you use the file handle OutFile, which suggests to me that you
want to open it for writing, not for reading:

open (OUTFILE, ">$file2") || die "Couldn't open '$file2' for write: $!";

> Can you reply by e-mail to mike@jbcs.co.ok

No. If you post here, you can get your answer here as well. Especially
since your From: line doesn't have the same address as this one. Fix
your From: line, and you might get a better response.

Martien
-- 
Martien Verbruggen                  | My friend has a baby. I'm writing down
Webmaster www.tradingpost.com.au    | all the noises the baby makes so later
Commercial Dynamics Pty. Ltd.       | I can ask him what he meant - Steven
NSW, Australia                      | Wright


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

Date: 16 Sep 1998 22:00:18 GMT
From: gebis@fee.ecn.purdue.edu (Michael J Gebis)
Subject: Re: how safe is xor encryption ?
Message-Id: <6tpcdi$1mf@mozo.cc.purdue.edu>

abigail@fnx.com (Abigail) writes:

}Mark-Jason Dominus (mjd@op.net) wrote on MDCCCXLII September MCMXCIII in
}<URL: news:6touoo$5j0$1@monet.op.net>:
}++ I still think `xor' is probably a poor choice.


} "The next step up in complexity for the cryptographer is to use a key
}  longer than the plaintext, making the above attack useless. In fact,
}  constructing an unbreakable cipher is easy. First choose a random bit
}  string as the key.

It is HIGHLY important to have a truly random bit string.  People
choose correlated keys.  The method as described in the orignal post
is not the one-time-pad tannenbaum is describing here.

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Wed, 16 Sep 1998 22:04:37 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: how safe is xor encryption ?
Message-Id: <36003392.BEADF409@bbnplanet.com>

Ok. I stand corrected. I am still not absolutely certain that this is
100% secure, but certainly much more than I thought. I'll just go mug
the cute waiter instead for my CC fix. ;) 

Interesting tidbit from www.cypher.net. 


Why are One-Time Pads Perfectly Secure?

If the key is truly random, an xor-based one-time pad is perfectly
secure against ciphertext-only cryptanalysis. This means an attacker
can't compute the plaintext from the ciphertext without knowlege of the
key, even via a brute force search of the space of all keys! Trying all
possible keys doesn't help you at all, because all possible plaintexts
are equally likely decryptions of the ciphertext. 

This result is true regardless of how few bits the key has or how much
you know about the structure of the plaintext. To see this, suppose you
intercept a very small, 8-bit, ciphertext. You know it is either the
ASCII character 'S' or the ASCII character 'A' encrypted with a one-time
pad. You also know that if it's 'S', the enemy will attack by sea, and
if it's 'A', the enemy will attack by air. That's a lot to know. All you
are missing is the key, a silly little 8-bit one-time pad. 

You assign your crack staff of cryptanalysts to try all 256 8-bit
one-time pads. This is a brute force search of the keyspace. 

The results of the brute force search of the keyspace is that your staff
finds one 8-bit key that decrypts the ciphertext to 'S' and one that
decrypts it to 'A'. And you still don't know which one is the actual
plaintext. 

This argument is easilly generalized to keys (and plaintexts) of
arbitrary length. 


e.

"All of us, all of us, all of us trying to save our immortal souls, some
ways seemingly more round-about and mysterious than others. We're having
a good time here. But hope all will be revealed soon."  R. Carver


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

Date: 16 Sep 1998 22:14:38 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: how safe is xor encryption ?
Message-Id: <6tpd8e$mvi$1@client3.news.psi.net>

Elaine -HappyFunBall- Ashton (eashton@bbnplanet.com) wrote on MDCCCXLII
September MCMXCIII in <URL: news:36001D95.FC206F90@bbnplanet.com>:
++ Abigail wrote:
++ 
++ > No. You need the key *and* the encrypted number.
++ 
++ Correct. But, if I can get the key, I can probably get on the machine
++ and find the database. Unless, of course, I missed something.
++ 
++ > Impossible is the right answer. The beauty of XOR encryption is that even
++ > if you brute force try all keys, and you hit the right one, you have
++ > absolutely no idea it is the right key.
++ 
++ Well, brute force is an ugly way to go about spending a Sunday
++ afternoon, but I don't know that impossible is the correct term.

Sure it is. Pick an encrypted string E. Pick a plain text P, any text
you want (with the same length). Create a key K = E xor P. That will
"decrypt" E to P.

++ > For instance, I might give you the encrypted text "t^R][S".  You might
++ > try keys, and find out that XORring with "123456" gives "Elaine". However,
++ > XORring with "5-:)4=" will give you "Ashton". And a key of "<?16>!" will
++ > give you "Hacker". For any 6 character string, there will be a unique,
++ > 6 character key that, when applied to the encrypted text, gives you the
++ > target text.
++ 
++ This is true and I may be dead before I could break it, but then again,
++ I could get lucky. Modern cryptanalysis is making great strides and with
++ more computing power than ever before. I never like to say that anything
++ is impossible, just improbable...for now. They broke purple without a
++ cray didn't they?

It has nothing to do with number of keys to check. It has all to do
with not being able to answer the question "is this a correct key?".

Here it is again:

     Encrypted text       Key            Plain text
     t^R][S               123456         Elaine
     t^R][S               5-:)4=         Ashton
     t^R][S               <?16>!         Hacker


There aren't separate encryption/decryption keys so you can perform
a M = D(E(M)) test. For *every* possible list of CC#, there will be
a (unique) key that decrypts a certain encrypted string to that CC#.

So, all your brute force can do is generate a list of all possible CC#'s. 
But that's something I can do without using a list of encrypted numbers.



Abigail
-- 
perl  -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
          for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
          print chr 0x$& and q
          qq}*excess********}'


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

Date: 16 Sep 1998 22:14:30 GMT
From: gebis@fee.ecn.purdue.edu (Michael J Gebis)
Subject: Re: how safe is xor encryption ?
Message-Id: <6tpd86$2a2@mozo.cc.purdue.edu>

Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com> writes:

}Ok. I stand corrected. I am still not absolutely certain that this is
}100% secure, but certainly much more than I thought. I'll just go mug
}the cute waiter instead for my CC fix. ;) 

}Interesting tidbit from www.cypher.net. 

}Why are One-Time Pads Perfectly Secure?

}If the key is truly random, an xor-based one-time pad is perfectly
 ^^^^^^^^^^^^^^^^^^^^^^^^^^

Nobody chooses "truly random" bitstrings for a key.

(Well, maybe Data does, but no _humans_)

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: 16 Sep 1998 18:22:44 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: how safe is xor encryption ?
Message-Id: <6tpdnk$7hj$1@monet.op.net>

In article <6tp5s3$127@enews2.newsguy.com>,
Felix S. Gallo <fsg@newsguy.com> wrote:
>But as a novitiate crank pedant,
>I earn valuable Usenet points towards my next advancement 

Don't forget that you also need three box tops!

>pointing out that some of his language here tends towards the
>careless: there's a difference between a '53-bit key phrase' and
>a key phrase with 53 bits of entropy, normally, especially if the
>phrase is 'customer-selected'

Mea culpa.  I was deliberately using shorthand to avoid confusing the
real issues with Too Much Jargon.  But since you brought it up, what I
really meant to say is that the customers, considered as a source of
keys, must be an ergodic source with at least 53.15 bits of entropy
per key.

Pedantically Yours, and in Quest of Box Tops,
	I remain, 
	Yr Humble and Obedient Servant,

		Jas: Dominus







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

Date: 16 Sep 1998 18:34:25 -0400
From: Uri Guttman <uri@camel.fastserv.com>
Subject: Re: how safe is xor encryption ?
Message-Id: <sar90jj8z66.fsf@camel.fastserv.com>

>>>>> "MJG" == Michael J Gebis <gebis@fee.ecn.purdue.edu> writes:

  MJG> Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com> writes:

  MJG> }Why are One-Time Pads Perfectly Secure?

  MJG> }If the key is truly random, an xor-based one-time pad is
  MJG> perfectly ^^^^^^^^^^^^^^^^^^^^^^^^^^

  MJG> Nobody chooses "truly random" bitstrings for a key.

a real one time pad doesn't have to be truly random, it just needs high
enough entropy and no way of deducing the next pad from the current
one. 

in the discussed application, a simple text string for a key is not
random enough so that all possible messages can be decoded. therefore it
is possible to break it with a brute force test of many strings of
english, etc. but it still may take a while.

uri

-- 
Uri Guttman                             Speed up your web server with Fast CGI!
uri@fastengines.com                                  http://www.fastengines.com


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

Date: 16 Sep 1998 22:50:39 GMT
From: gebis@fee.ecn.purdue.edu (Michael J Gebis)
Subject: Re: how safe is xor encryption ?
Message-Id: <6tpfbv$3an@mozo.cc.purdue.edu>

In response to M-J-D's challenge:

#!/usr/bin/perl5 -w
$cc="012345678";
$k ="brainwash"; # Why not?

$ciphertext = $cc ^ $k;
undef $k; #FORGET THE KEY

@cipher = split(//,$ciphertext);


$regexp = "";
foreach $letter (@cipher) {
    $regexp .= '[';
    foreach $digit (qw(0 1 2 3 4 5 6 7 8 9)) {
	print $letter ^ $digit;
	$regexp.= quotemeta($letter ^ $digit);
    }
    $regexp .= ']';
    print "\n";
}

print "Regexp is $regexp\n";

open(WORDS,'/usr/dict/words') or die "Blowme:$!";
while(<WORDS>) {
    chomp;
    if(m/^$regexp$/) {
	print $_, ":",$_^$ciphertext,"\n";
    }
}
# I get two possible matches.  That sure seems pretty doable.
# Obviously, this particular program only works with a single word,
# and assumes the length is known, but it seems that it wouldn't be
# that difficult to extend it.  I sure hope this proves my point.
-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Wed, 16 Sep 1998 23:35:28 GMT
From: beyret@my-dejanews.com
Subject: Re: how safe is xor encryption ?
Message-Id: <6tpi00$7j0$1@nnrp1.dejanews.com>


>
> I'm not sure that RedHat would be my first choice for a host storing
> sensitive data, encrypted or not due to the number of exploits that
> currently exist for it and are proliferating everyday. Perhaps I have
> been a bit obtuse as well. My point in all of this is that one must
> consider all of the options if one truly wants to make a secure
> e-commerce solution.

well, i do not think that it is the distribution that matters for security
but the kernel version, versions of daemons etc. distributions are just combo
boxes, so another distribution using the same versions of sendmail, kernel,
etc etc. would have same vulnerabilities anyway.

> I wasn't criticising the encryption idea, but the confidence it seems to
> evoke. What if someone added a few lines of code to your script and
> mailed all of the customers info at the time of sign-up to an email
> address? You cannot always prevent things such as this, but dreaming up
> ways to compromise your site and considering them in the solution is
> important.

that is a very good point. i'll think about this. yeah, instead of wasting
time with decrypting CC#s in database, a cracker would prefer that way.

can a perl code be made human unreadable? write it once, and sort of convert
it to a format that is still executable but not readable?

if the CGI is written in C, since it is compiled to binary, code can not be
edited (say i chewed :) the source code after compilation and cracker can't
find it).

ersin

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 17 Sep 1998 01:43:34 +0300
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: Is there any FAQ?
Message-Id: <oeeg1dru19l.fsf@alpha.hut.fi>


"Hansi Hinterseer" <elchmann@hotmail.com> writes:

> Hi!
> 
> I wondered if there is a FAQ about Perl or the NGs. Is there? Or any
> recommended tutorials?
> 
> Thanks, Hansi

Just curious: exactly how long did you follow this newsgroup?
Or how many web searches did you make?

-- 
$jhi++; # http://www.iki.fi/~jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen


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

Date: Wed, 16 Sep 1998 22:36:20 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: milliseconds?
Message-Id: <EzEEsK.135@world.std.com>

miho21@yahoo.com writes:

>OUCH! no need to bite, tom :) If you look, youll see a question mark at the
>end of every sentence in the post since i do not claim to really know perl
>that much. how bout an explanation instead?

I would think that it would save Tom a lot of time if he wrote the
explanation once and everyone else referred to that explanation if
they needed it. After all, there are probably more people who want to
know what qw/STRING/ is than there are of him.

Oh wait. Since he's responsible for a good part (if not most) of the
standard perl documentation, he probably already did write the
explanation down. Its in the perlop document. (and if he didn't write
that particular section, he knew he didn't have to because it was
already there.) All we need is to have everyone look for their answers
there.

Programming is something that requires a certain amount of research
skills. If you post a question for evey single construct you have not
come accross before, it will get a little tedious, don't you think?


What does "$a" mean?
What does "=" mean?
What does "+" mean?
What do "{" and "}" mean?
What does "print" mean?
 ...
What does "use Fctl(:flock)" mean?
 ...
(ad nauseum)

I think it is time to bring out my Lego analogy again.

The sytactic elements of Perl are similar to the individual elements
of a Lego set. Each individual block is fairly uninteresting examined
by itself, but they can be put together in an infinate variety of
interesting ways. Programmers are very likely programmers because they
love the infinate possibilities that computers give them, and they
congregate in places like comp.lang.perl.misc because they love
discussing with each other things that they can build with the
language. Discussing the definition of a particular syntactic element
is about exciting as discussing an individual Lego block.

-- 
Andrew Langmead


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

Date: 16 Sep 1998 22:56:42 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: newbie DATE question
Message-Id: <6tpfna$nk4$1@client3.news.psi.net>

Bryan Ingram (cg@cgiworx.com) wrote on MDCCCXLII September MCMXCIII in
<URL: news:360027B0.F2FE342F@cgiworx.com>:
++ Hi ..
++ 
++ I'm a C programmer, just getting around to learning Perl ..and I love
++ it! ;)
++ 
++ I'm working on an a program where I need to take the current date and
++ increment it by 1 day.  Is there a nifty routine to do this in Perl, or
++ must I do all the checking myself?  e,g ..must I manually code the logic
++ to determine if the day has exceeded the max for the current month, etc?

use constant HOURS   => 24;
use constant MINUTES => 60;
use constant SECONDS => 60;

sub tomorrow () {
    local $_ = 1 x HOURS x MINUTES x SECONDS;
    s/1/sleep $&/eg;
    scalar localtime;
}



Abigail
-- 
perl -wleprint -eqq-@{[ -eqw+ -eJust -eanother -ePerl -eHacker -e+]}-


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

Date: Wed, 16 Sep 1998 22:11:03 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Perl & Java - differences and uses
Message-Id: <XHWL1.3206$F7.12691224@news.itd.umich.edu>

In article <36003E68.B2A63F34@bioreason.com>,
Andrew Dalke  <dalke@bioreason.com> wrote:
>As I recall, regular expressions in Perl are not first class
>elements.  For example, you cannot make a list of regular
>expressions.

>I have an interactive system for doing re searches against
>a string (actually, Prosite pattern searches against protein
>sequences).  I want to register a set of patterns, read a
>string, and search it.

>Eg (written on the fly so there are probably errors):

>import re
>patterns = []
>def add_pattern(pat, name):
>  patterns.append( (re.compile(pat), name) )
>
># returns number of matches found
>def search(str):
>  count = 0
>  for pat in patterns:
>    m = pat[0].search(str)
>    if m:
>      # could put more info here, like start&end pos, match text
>      print "Found", pat[1]
>      count = count + 1
>  return count

>The closest I can think of in Perl is to construct some perl
>code and eval it dynamically, like:
[snip]

I was thinking about this myself recently, and figured that anonymous
subroutines could be used to encapsulate regular expressions:

sub regex {
	my $re = shift;
	# Either:
	eval "sub { shift =~ /$re/ }";
	# or:
	sub { shift =~ /$re/ };
	# (The first generates its return value slowly, but matches quickly
	# thenceforth; vice versa for the second.)
}

@patterns = map { regex $_ } 'e{2}', '^A', 'B$';  # (say)

sub search {
	my $str = shift;
	my $count = 0;
	foreach my $pattern (@patterns) {
		$count++ if &$pattern($str);
	}
	$count;
}

Definitely workable, though not at all obvious.  It has the nice behavior
that context propagates down to the anonymous subs, so you can do something
like this:

$re = regex '(?g)(\w+)';
@words = &$re("This is a test");  # @words is now ("This", "is", "a", "test")

-- 
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


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

Date: 16 Sep 1998 18:45:06 -0400
From: Uri Guttman <uri@camel.fastserv.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <sar7lz38yod.fsf@camel.fastserv.com>

>>>>> "SM" == Sean McAfee <mcafee@waits.facilities.med.umich.edu> writes:

  SM> In article <36003E68.B2A63F34@bioreason.com>,
  SM> Andrew Dalke  <dalke@bioreason.com> wrote:
  >> As I recall, regular expressions in Perl are not first class
  >> elements.  For example, you cannot make a list of regular
  >> expressions.

perl 5.005 can do that with the qr// operator. and regexes can be passed
around and used in any regex op.


  SM> I was thinking about this myself recently, and figured that anonymous
  SM> subroutines could be used to encapsulate regular expressions:

  SM> sub regex {
  SM> 	my $re = shift;
  SM> 	# Either:
  SM> 	eval "sub { shift =~ /$re/ }";
  SM> 	# or:
  SM> 	sub { shift =~ /$re/ };
  SM> 	# (The first generates its return value slowly, but matches quickly
  SM> 	# thenceforth; vice versa for the second.)
  SM> }

  SM> @patterns = map { regex $_ } 'e{2}', '^A', 'B$';  # (say)

  SM> sub search {
  SM> 	my $str = shift;
  SM> 	my $count = 0;
  SM> 	foreach my $pattern (@patterns) {
  SM> 		$count++ if &$pattern($str);
  SM> 	}
  SM> 	$count;
  SM> }


the technique of building a regex sub on the fly and eval'ing it is very
old and was the standard way to test multiple regexes with decent
efficiency. it is not well know by newbies but most perl hackers had it
in their idiom toolbox. there are variations on the theme including
building a single long sub to check for ANY match in a list of regexes
or counting total matches or something like the above which builds one
sub per regex. i have taught this trick to many others.

as i said above, perl 5.005 won't need that trick any more. qr// will
compile the regex and return it to a scalar. this value can be used
anywhere a regex can. you can make lists and hashes of regexes to your
heart's conetent. 

RTFM or ask zenin for much more about the new regex features.

uri

-- 
Uri Guttman                             Speed up your web server with Fast CGI!
uri@fastengines.com                                  http://www.fastengines.com


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

Date: 16 Sep 1998 23:13:26 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Perl & Java - differences and uses
Message-Id: <6tpgmm$on5$1@client3.news.psi.net>

Andrew Dalke (dalke@bioreason.com) wrote on MDCCCXLII September MCMXCIII
in <URL: news:36003E68.B2A63F34@bioreason.com>:
++ Not sure why I'm getting involved in a language war, but ...
++ 
++ Zenin <zenin@bawdycaste.org> asked:
++ > Please show *any* Python or Java code that when translated to Perl
++ > would be done uncleanly by default.  *Any* code.
++ 
++ As I recall, regular expressions in Perl are not first class
++ elements.  For example, you cannot make a list of regular
++ expressions.

Oh, sure you can:

    @regexes = qw /foo bar [bg]/;
    $_ = "a foo and a bar";
    foreach my $r (@regexes) {
        /$r/ && print $&, "\n";
    }

Or perhaps you prefer a list of compiled regexes:

    @regexes = (qr /foo/, qr /bar/, qr /[bg]/);
    $_ = "a foo and a bar";
    foreach my $r (@regexes) {
        /$r/ && print $&, "\n";
    }


++ I have an interactive system for doing re searches against
++ a string (actually, Prosite pattern searches against protein
++ sequences).  I want to register a set of patterns, read a
++ string, and search it.

FAQ.




Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: 16 Sep 1998 23:14:33 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Printing lines between patterns
Message-Id: <6tpgop$on5$2@client3.news.psi.net>

Srikanth Natarajan (nkanth@cnd.hp.com) wrote on MDCCCXLII September
MCMXCIII in <URL: news:360026B9.A6B80DB3@cnd.hp.com>:
++ 
++ I want to print all the lines between BEGIN and END
++ 
++ Any way to do this?


That's a FAQ.



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: Wed, 16 Sep 1998 15:23:29 -0700
From: "Doyle Johnson" <sales@madm.com>
Subject: Remove files/Dir help
Message-Id: <6tpeh1$n9$1@nnrp03.primenet.com>

Hi all,

   Can someone please shoot me the correct working syntax for removing
(deleting) files and directories???/ Please.....

I am not having any luck with
rm
rmdir

Even though they are stated in the man as correct.... it might be the
systax... can someone please give me a hand?

MadmX





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

Date: 16 Sep 1998 23:16:08 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: splitting by certain spaces
Message-Id: <6tpgro$on5$3@client3.news.psi.net>

Steve . (syarbrou@ais.net) wrote on MDCCCXLII September MCMXCIII in
<URL: news:36002547.2164860@news.ais.net>:
++ 
++ Basically I need to split the first three fields, as I do with the
++ split above, and then say the rest of this line put in here.  How
++ would I do this?  Thanks.  


One reads the manual about split.



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: 16 Sep 1998 16:59:15 -0500
From: tye@fumnix.metronet.com (Tye McQueen)
Subject: Re: STD I/O for WIN32 Perl
Message-Id: <6tpcbj$fc4@fumnix.metronet.com>

Brad Murray <murrayb@vansel.alcatel.com> writes:
) 
) But it shouldn't behave randomly.  I use the following association and
) I get quite satisfactory results.  It is not the way NT sets up the
) association for you (bad NT): 
) 
)   perl->Shell->Open->Command (Default) = "c:/perl/bin/perl.exe %0 %*"

So not working on scripts with spaces in their names or in
directories with spaces in their names is satisfactory to you?
Have you tried using I/O redirection?  I've never seen that work
with the type of association you've given.

To fix the spaces problem, you need C<"%0"> in place of C<%0>
above.  I know of no fix for the I/O redirection problem when
using file associations.

) >     perl myperl.pl < foo-in.txt > foo-out.txt
) > 
) > This is the case with perl, version 5.004_02 in my world at least
) 
) This circumvents the problem entirely and has the added benefit of not
) requiring special client configuration in order to work properly.  It's
) my preference for delivered tools.

Using pl2bat does this even better.
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: Wed, 16 Sep 1998 23:23:24 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: STDOUT into array
Message-Id: <MLXL1.16$G65.107504@nsw.nnrp.telstra.net>

In article <6tnp5s$8n3$1@newshost.germany.net>,
	100.12399@germanynet.de (Steffen Golz) writes:
> Hallo!
> 
> I had a compressed file called daten.gz.
> I would like to expand this file with "zcat -c daten.gz".
> zcat copy this uncompressed information to the STDOUT cannel.
> I would like to copy this information into an array, which i can
> work with.

my @ar = `zcat daten.gz`;

or, more readable:

my @ar = qx( zcat daten.gz );

# perldoc perlop
/qx/STRING/

I am assuming here that your zcat indeed does uncompress gzipped
files. You might need gzcat. In any case, neither of them need the -c
option, because that is what they already do. uncompress and gunzip
would need the -c option to do the same as zcat and gzcat. 

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | 75% of the people make up 3/4 of the
Commercial Dynamics Pty. Ltd.       | population.
NSW, Australia                      | 


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

Date: Wed, 16 Sep 1998 19:54:23 +0000
From: Al Smith <alanson@umich.edu>
Subject: trying to use print<<END; with CGI.pm
Message-Id: <36001766.E8D19BA9@umich.edu>

it's not working and i can't find any examples anywhere:
Lincoln's
metronet
Perllang
CPAN

Am i not looking hard enough?


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

Date: Wed, 16 Sep 1998 18:15:56 -0400
From: Joseph DuBois <jdubois@keane.com>
Subject: Unix Perl server?
Message-Id: <3600389C.131ED8E7@keane.com>

Well met,

    Awhile back I remember seeing a comercial program that acted as
the perl interpreter, but stayed running as a process. Thus it cut
out the startup time of the perl interpreter.

   The problem is I do not rember the company, or product name. I
was wondering if anyone knows the name, and even better has used
or tested it.


Thanks

--
-------------------------------------------------------
Joseph DuBois
mailto:jdubois@keane.com  (Work)  http://www.keane.com/




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

Date: Wed, 16 Sep 1998 17:54:15 -0400
From: Joseph DuBois <jdubois@keane.com>
To: Ramunas Navalinskas <r.navalinskas@omnitel.net>
Subject: Re: Uploading & Downloading
Message-Id: <36003387.12A1ED2B@keane.com>



Ramunas Navalinskas wrote:

> Hello !
>
> I need any hints about managing uploading files through forms. Also, is
> there a possibility to send to the client(browser) any file, which is
> "600". I need this for the .zip files (binary transfer mode), e.g.: user
> enters username and passw., Perl script checks it and if they're
> correct, it must send a file. I don't need complete program written,
> just any suggestions how to do this, if it's possibel. Thank you.
>
> --
> Ramunas Navalinskas
> E-mail: r.navalinskas@omnitel.net

  It sounds like two different things you are asking. One is uploading files

through a web browser using forms. This is done using a multipart form. I
think only netscape supports this (not IE).

   The second is a form prompting a user for ID/password, and then
downloading
a file to the user? If so , just determine the type of file (usually by
extension) then
set the mime type and a simple  cat to stdout seems to work.
--
-------------------------------------------------------
Joseph DuBois            (Internet/Intranet Specialist)
mailto:jdubois@keane.com  (Work)  http://www.keane.com/




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

Date: Wed, 16 Sep 1998 22:13:35 GMT
From: Rick Delaney <rick.delaney@shaw.wave.ca>
Subject: Re: Who posts original posts on CLPM?
Message-Id: <36003987.CBC82999@shaw.wave.ca>

Elaine -HappyFunBall- Ashton wrote:
> 
> Ben Sauvin wrote:
> 
> >     Small sampling theory can characterise populations with an 
> > accuracy of which Ashton seems unaware. Several hundred posts taken 
> > at random from random newsgroups might prove illustrative; larger 
> > samples may well involve greater processing for diminishing 
> > theoretical return.
> >
> >     In any event, a summary statement of raw data with no further 
> > processing remains a statistic, however unprocessed. Quibbling with 
> > the meaning of this statement is playing at semantics.
> 
> Small sampling theory is one thing, 500 posts is quite another. I
> disagree, why don't we just leave it at that. Raw data is not a
> statistic, no semantics involved.

It is if it's tabulated (which it is in this case).  Whether it's a
meaningful or significant statistic is something that needs to be
decided by statistical tests such as a [tzm]-test (I forget which are
useful with this kind of data.)

A bigger problem than the sample size is the obvious sample bias from
pulling all posts from *a single date*!

> > > I am neither a statistician or a demographer, so I will refrain 
> > > from suggesting how one might go about the study of this. It is 
> > > entirely possible someone has already done this with the help of
> > > both.
> >
> >     So it would appear.
> 
> And you are either/both?
> 

I'm betting on neither.  Although is there really a profession called
demographer?

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Wed, 16 Sep 1998 19:51:31 -0400
From: Ben Sauvin <sauvin@osmic.com>
Subject: Re: Who posts original posts on CLPM?
Message-Id: <36004F03.8987F751@osmic.com>



Elaine -HappyFunBall- Ashton wrote:

> Ben Sauvin wrote:
>
> >     Small sampling theory can characterise populations with an accuracy of which
> > Ashton seems unaware. Several hundred posts taken at random from random
> > newsgroups might prove illustrative; larger samples may well involve greater
> > processing for diminishing theoretical return.
> >
> >     In any event, a summary statement of raw data with no further processing
> > remains a statistic, however unprocessed. Quibbling with the meaning of this
> > statement is playing at semantics.
>
> Small sampling theory is one thing, 500 posts is quite another. I
> disagree, why don't we just leave it at that. Raw data is not a
> statistic, no semantics involved.

    Flip a coin ten times, observing and recording the outcome of each flip. At the
end of this experiment, count the number of heads and the number of tails, expressing
the result as a ratio.

    The ratio is a statistic. Without further calculation, it might be difficult to
say with any confidence whether or not the coin be "fair", but this "raw data"
nevertheless remains the kind of statistic that can be (and often is) used as a rough
guide in decision-making.

>
>
> > > I am neither a statistician or a demographer, so I will refrain from
> > > suggesting how one might go about the study of this. It is entirely
> > > possible someone has already done this with the help of both.
> >
> >     So it would appear.
>
> And you are either/both?

    Others within this newsgroup have abundant training in the elementary statistical
methods required for such a study. It requires no special degree or formal job
description within such as the US Census.

>
>
> e.
>
> "All of us, all of us, all of us trying to save our immortal souls, some
> ways seemingly more round-about and mysterious than others. We're having
> a good time here. But hope all will be revealed soon."  R. Carver



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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3733
**************************************

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