[7889] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1514 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 20 16:07:27 1997

Date: Sat, 20 Dec 97 13:00:25 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 20 Dec 1997     Volume: 8 Number: 1514

Today's topics:
     Binaries of Perl for Win95 where (not Activestate) <edward@hairnet.demon.co.uk>
     Re: bug? (was: Bitwise XOR (^) doesn't work on strings? <rootbeer@teleport.com>
     Re: Can I use -d,-e,-s.... in WinNT ? <koos_pol@bigfoot.com>
     Re: csh ==> perl? <rootbeer@teleport.com>
     Re: Downloading ALL CPAN Modules? <rootbeer@teleport.com>
     Re: failed exec() (Justin Vallon)
     Re: Finding the longest common prefix over a list of st (Justin Vallon)
     Re: getting directory size <rootbeer@teleport.com>
     Re: Happy birthday Perl! <Rosie@dozyrosy.demon.co.uk>
     Re: Help needed <rjk@coos.dartmouth.edu>
     Re: Help on accessing the cgi-bin directory <rootbeer@teleport.com>
     Re: Help with pattern matching please? (Tad McClellan)
     Re: Help with pattern matching please? <rjk@coos.dartmouth.edu>
     Re: HELP!  Bitwise XOR (^) doesn't work on strings? <rootbeer@teleport.com>
     Re: HHEELLPP! <rootbeer@teleport.com>
     Re: need simple mailer perl scipt <rootbeer@teleport.com>
     Re: Perl editor needed (Don Groves)
     perl glue between C and the web <Rakesh.Chitradurga@sdrc.com>
     Re: perl glue between C and the web (Nathan V. Patwardhan)
     Re: Read in Mailfolder <rjk@coos.dartmouth.edu>
     Re: Read in Mailfolder <rootbeer@teleport.com>
     Re: references to globalise locally generatied filehand (John Devitofranceschi)
     Re: Regular Expression Question - non greedy match (John Moreno)
     Re: Scanning the access_log file <rootbeer@teleport.com>
     Re: sending email (Net::SMTP).. problem <rootbeer@teleport.com>
     split bug in perl5.004? bryl@medicine.wustl.edu
     Re: Statistics for comp.lang.perl.misc (Danny Aldham)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sat, 20 Dec 1997 20:00:02 -0000
From: "Edward Betts" <edward@hairnet.demon.co.uk>
To: comp.lang.perl.misc
Subject: Binaries of Perl for Win95 where (not Activestate)
Message-Id: <HRNT8836C39A0@hairnet.demon.co.uk>

I want to do some database work with perl on a windows 95 box. Activestate
port of perl 5.003 does not support DBM, but the latest version of the real
Perl 5.004 does support it and does compile on Windows. Only problem is I
have no windows C compiler.

Anyone willing to compile it for me or tell me where I could find a compiled
version?

--
Edward Betts, http://www.hairnet.demon.co.uk/edward




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

Date: Sat, 20 Dec 1997 12:13:02 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Tad McClellan <tadmc@metronet.com>
Subject: Re: bug? (was: Bitwise XOR (^) doesn't work on strings?)
Message-Id: <Pine.GSO.3.96.971220120422.2947R-100000@user2.teleport.com>

On Sat, 20 Dec 1997, Tad McClellan wrote:

> This appears to be a bug in the documentation to me.

Yes, it did to me, too. I'm appending the doc patch I submitted early in
November. Does this seem to cover the lacks that you're seeing? Let me
know of anything that's still missing - I'd rather overdocument rather
than underdocument! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!

Here's a doc patch to cover bitwise string operations. The examples are
all ASCII-based due to my shortage of EBCDIC machinery.  :-) 

--- perl5.004_04/pod/perlop.pod.orig	Wed Nov  5 07:57:17 1997
+++ perl5.004_04/pod/perlop.pod	Thu Nov  6 08:30:58 1997
@@ -145,7 +145,7 @@
 to C<"-bareword">.
 
 Unary "~" performs bitwise negation, i.e., 1's complement.
-(See also L<Integer Arithmetic>.)
+(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
 
 Unary "+" has no effect whatsoever, even on strings.  It is useful
 syntactically for separating a function name from a parenthesized expression
@@ -300,15 +300,15 @@
 =head2 Bitwise And
 
 Binary "&" returns its operators ANDed together bit by bit.
-(See also L<Integer Arithmetic>.)
+(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
 
 =head2 Bitwise Or and Exclusive Or
 
 Binary "|" returns its operators ORed together bit by bit.
-(See also L<Integer Arithmetic>.)
+(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
 
 Binary "^" returns its operators XORed together bit by bit.
-(See also L<Integer Arithmetic>.)
+(See also L<Integer Arithmetic> and L<Bitwise String Operators>.)
 
 =head2 C-style Logical And
 
@@ -1213,6 +1213,34 @@
 expression represents so that the interpreter
 won't have to.
 
+=head2 Bitwise String Operators
+
+Bitstrings of any size may be manipulated by the bitwise operators
+(C<~ | & ^>).
+
+If the operands to a binary bitwise op are strings of different sizes,
+B<or> and B<xor> ops will act as if the shorter operand had additional
+zero bits on the right, while the B<and> op will act as if the longer
+operand were truncated to the length of the shorter.
+
+    # ASCII-based examples 
+    print "j p \n" ^ " a h";        	# prints "JAPH\n"
+    print "JA" | "  ph\n";          	# prints "japh\n"
+    print "japh\nJunk" & '_____';   	# prints "JAPH\n";
+    print 'p N$' ^ " E<H\n";		# prints "Perl\n";
+
+If you are intending to manipulate bitstrings, you should be certain that
+you're supplying bitstrings: If an operand is a number, that will imply
+a B<numeric> bitwise operation. You may explicitly show which type of
+operation you intend by using C<""> or C<0+>, as in the examples below.
+
+    $foo =  150  |  105 ;	# yields 255  (0x96 | 0x69 is 0xFF)
+    $foo = '150' |  105 ;	# yields 255
+    $foo =  150  | '105';	# yields 255
+    $foo = '150' | '105';	# yields string '155' (under ASCII)
+
+    $baz = 0+$foo & 0+$bar;	# both ops explicitly numeric
+    $biz = "$foo" ^ "$bar";	# both ops explicitly stringy
 
 =head2 Integer Arithmetic
 
@@ -1230,7 +1258,8 @@
 which lasts until the end of that BLOCK.
 
 The bitwise operators ("&", "|", "^", "~", "<<", and ">>") always
-produce integral results.  However, C<use integer> still has meaning
+produce integral results.  (But see also L<Bitwise String Operators>.)
+However, C<use integer> still has meaning
 for them.  By default, their results are interpreted as unsigned
 integers.  However, if C<use integer> is in effect, their results are
 interpreted as signed integers.  For example, C<~0> usually evaluates




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

Date: Fri, 19 Dec 1997 12:40:11 +0100
From: Koos Pol <koos_pol@bigfoot.com>
Subject: Re: Can I use -d,-e,-s.... in WinNT ?
Message-Id: <349A5D1B.795C@bigfoot.com>

Q-ball wrote:
> 
> Hello :
> I had installed the Perl for Win32 in my PC (OS : NT4.0 )
> But I don't know can I use the
> parameter  ( -e : check if files exit  ,-f,-d. -T.........)
> under NT to check the file's attribute ?Or I must use them in UNIX ?
> 
>  If I couldn't . How should I modify the function
> 
>   if(-d  $filename) {
>    ...........
>  in order to check the attribute of  file in NT ?
> 
> Thanks......

I use 'em as-is under OS/2 Warp, and I would be VERY surprised if it
wouldn't work as well as-is under NT.

-- 
Koos Pol
----------------------------------------------------------------------
S.C. Pol                                           tel: +31 20 3116122
PC Systems Administrator                   email: Koos_Pol@bigfoot.com
Compuware Europe                 PGP public key available upon request

      A little inaccuracy sometimes saves tons of explanation.
                        -- H. H. Munroe


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

Date: Sat, 20 Dec 1997 11:51:47 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Pete Thurmes <pete@isis.spa.umn.edu>
Subject: Re: csh ==> perl?
Message-Id: <Pine.GSO.3.96.971220115110.2947M-100000@user2.teleport.com>

On Fri, 19 Dec 1997, Pete Thurmes wrote:

> I am curious about whether there is a csh-to-perl translator around,

    http://www.perl.com/CPAN/doc/manual/html/pod/perlfaq8/
          How_can_I_convert_my_shel_scrip.html

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Sat, 20 Dec 1997 10:53:30 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: "Roy S. Rapoport" <rsr@best.com>
Subject: Re: Downloading ALL CPAN Modules?
Message-Id: <Pine.GSO.3.96.971220105221.2947E-100000@user2.teleport.com>

On 19 Dec 1997, Roy S. Rapoport wrote:

> B) Has anyone come up with an automated way to get all the modules? It
>    doesn't _look_ like the CPAN module deals with 'install *' ...

If the CPAN module doesn't have an easy way to install all of the modules
(or at least the ones with version numbers of at least 1, say) you should
fix it and use the perlbug program to submit your patch. :-)  Thanks!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Sat, 20 Dec 1997 15:11:33 -0500
From: vallon@mindspring.com (Justin Vallon)
Subject: Re: failed exec()
Message-Id: <19971220151133297271@user-37kb6dq.dialup.mindspring.com>

M.J.T. Guy <mjtg@cus.cam.ac.uk> wrote:

> Not actually answering your question, since others have done that, but ...
> 
> David Minsterman  <daminste@mailbox.syr.edu> wrote:
> >What I am using is this:    exec "java $programname"
> 
> That is dangerous, if the $programname is somehow user supplied.
> Consider what happens if the $programname were '; rm -rf /'
> (or corresponding for non-unix systems).   Use the multi-argument form
> of exec instead.   It's also more efficient.
> 
>        exec 'java', $programname or die "exec failed: $!"
> 
> 
> Mike Guy

If exec "string" calls exec, that is not an issue, since you would
require the shell to run multiple commands.  Remember, exec loads the
program 'java', and gives it arguments (":", "rm", "-rf", "/"), which
java would probably barf on.

I would worry about system("blah blah $user_arg").

The list-exec is nicer anyway to be explicit about arguments (spaces,
etc).

-- 
-Justin
vallon@mindspring.com


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

Date: Sat, 20 Dec 1997 15:11:36 -0500
From: vallon@mindspring.com (Justin Vallon)
Subject: Re: Finding the longest common prefix over a list of strings
Message-Id: <19971220151136297429@user-37kb6dq.dialup.mindspring.com>

This may be dead, but:

local @words = qw(silly sally sorted seven sequences);

local $min = $words[0];
local $max = $words[0];

for $w (@words) {
        if ($w lt $min) { $min = $w; }
        if ($w gt $max) { $max = $w; }
}

local $lower_len = 0;
local $upper_len = length($min);
if ($upper_len < length($max)) { $upper_len = length($max); }

while ($lower_len < $upper_len) {
        local $mid_len = int(($lower_len + $upper_len + 1)/2);
        if (substr($min, 0, $mid_len) ne substr($max, 0, $mid_len)) {
                $upper_len = $mid_len - 1;
        } else {
                $lower_len = $mid_len;
        }
}

local $prefix = substr $min, 0, $lower_len;
print "$prefix\n";



Run time: O(N + ln k).
      T = 1*N + ln k.



Ken Fox <fox@pt0204.pto.ford.com> wrote:

> abigail@fnx.com (Abigail) writes:
> > Here's an optimal version:
> > 
> > my @words = ("word1", "word2", "word3", ...., "wordN");
> > my $end   = length $words [0] - 1;
> > 
> > foreach my $w (1 .. $#words) {
> >     $end = length $words [$w] - 1 if $end >= length $words [$w];
> >     foreach my $i (0 .. length $words [$w] - 1) {
>                           ^^^^^^^^^^^^^^^^^^^^^^
> Should be $end?
> 
> >         if (substr ($words [$w - 1], $i, 1) ne
> >             substr ($words [$w],     $i, 1)) {
> >             $end = $i - 1;
> >             last;
> >         }
> >     }
> >     last if $end < 0;
> > }
> > $prefix = substr $words [0], 0, $end + 1;
> 
> In my original posting, I gave a similar (cleaner?) algorithm:
> 
>   my @words = qw(the thick thesis thoroughly threw thor);
> 
>   my $offset = 0;
>   my $reference = shift @words;
>   my $prefix;
> 
>   MATCH: while (1) {
>       $prefix = substr($reference, $offset, 1);
>       foreach (@words) {
>           if (substr($_, $offset, 1) ne $prefix) {
>               $prefix = substr($reference, 0, $offset);
>               last MATCH;
>           }
>       }
>       ++$offset;
>   }
> 
>   print "$prefix\n";
> 
> This algorithm is O(N) where N is the number of words in the input.
> Actually, it has run-time T(k*N+f) where N is the number of words in the
> input, k is the length of the common prefix, and f is the number of
> false prefix matches that are tested (f < N).  For those that don't
> know, it's standard in Big-O notation to drop all the constants used in
> the run-time bound, so T(k*N+f) ends up O(N).
> 
> Abigail's algorithm is also O(N), but mine will short circuit as soon as
> possible, whereas Abigail's might do a lot of work only to throw it away
> on the last word.  Try both algorithms on the input set of 100 "fubar"s
> with one "snafu" at the end.
> 
> I (almost) agree with Abigail's analysis of the regex:
> 
> > ++ >  (join(',', @words).',') =~ /^(\w*)\w*,(\1\w*,)*$/;
> > 
> > For this, I'm going to prove a lowerbound on the run time for a
> > specific example. I will use W for Omega, as ascii doesn't have
> > Greek symbols.
> > 
> > Take N - 1 words of length k all sharing the same prefix, and let that
> > prefix be at least k/2 characters long. Let the last word not have
> > any prefix in common with the rest (except for the empty string).
> > 
> > The join will generate a string of length W (k * N). Due to the
> > greedyness and backtracking of the regex machine, after being
> > discovered a certain prefix didn't make it, the regex machine
> > will try a prefix one shorter, and start all over again.
> > 
> > After finding the common prefix for the first N - 1 words, it
> > has to scan W (k * N) words before it fails and needs to backtrack.
>                         ^^^^^
> Should be characters.
> 
> > It needs to backtrack W (k) times. Hence, a total running time of
> > W (k^2 * N).
> > 
> > Clearly, Ilya's algorithm beats the regex hands down.
> 
> So regex is linear in N, but geometric in k.  If we know that the common
> prefix is short, then it's probably ok to use it.  (Keep in mind that
> this is a lower bound because it ignores all sorts of ugly stuff like
> repeated scanning over the non-prefix parts of words and looking for
> commas.)  My original algorithm and Abigail's algorithm both have have a
> lower bound of W(k*N) though.  If k is a constant then k^2 is too... ;)
> 
> I think Abigail's example of a long prefix is a specially formulated
> worst case.  Will it ever appear in practice?  For *my* purposes, I'm
> doubtful.  I find in my sample data as N becomes larger, the prefix
> length becomes smaller.  For short prefixes the regex algorithm becomes
> (nearly) linear.  Caveat emptor.
> 
> Abigail's algorithm is superior to the regex from a theoretical view,
> but it fails miserably.  Why?  Because Big-O notation ignores
> computational "constants" and "implementation details".  :-)  Perl is
> *much* faster at regex execution than it is at "normal" code execution.
> The total work done in opcode dispatch, argument passing, etc. for
> Abigail's optimized solution exceeds the regex execution, even though
> the regex has poorer performance bounds.
> 
> I don't know if regex ever becomes worse than Abigail's algorithm, but
> for my input (filenames with a known matching partial prefix), the regex
> wins all test cases I've given it.
> 
> > Tushar Samant (scribble@shoga.wwa.com) writes:
> > ++ The reasons for suggesting benchmarking are different.  The check I
> > ++ suggested will make a difference depending on what the specific sample
> > ++ of inputs is. If the "typical" sample ...
> 
> You'll surely lose this argument with Abigail.  You'll have to think
> like a theorist to win.  You raise a valid point:  to perform a valid
> performance analysis we need a sample dataset, but which dataset?  How
> about any of them?  Abigail can analyze her algorithm with any input so
> your argument doesn't float.  She can even pick the worst case dataset
> and give you a definitive formula for the algorithm's performance.
> 
> What you need benchmarking for is for computing the run-time (Big-T
> notation) of an algorithm.  This serves as raw data to verify that an
> analysis is of the proper order.  It also can be used for estimating the
> constants that Big-O notation drops.
> 
> For instance, benchmarking shows that the regex solution is faster on
> today's hardware, with today's Perl interpreter when given one of my
> reasonable input sets.  This means that the constants in Abigail's analysis
> matter.
> 
> Most of the time that's all anybody really wants to know anyway.  ;)
> 
> - Ken


-- 
-Justin
vallon@mindspring.com


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

Date: Sat, 20 Dec 1997 11:11:42 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Brian <signal@shreve.net>
Subject: Re: getting directory size
Message-Id: <Pine.GSO.3.96.971220105546.2947F-100000@user2.teleport.com>

On Fri, 19 Dec 1997, Brian wrote:

> I am looking for a native perl function or library that will have
> something similar to the "du" command in it so I can get directory
> sizes.  

Maybe you want to use stat, or the filetests like -s?

> chdir "/home/cust";

It's probably good to check that this chdir succeeded. Or, better, avoid
it altogether - there's no pressing reason that a directory need to be
your current working directory if you're merely examining its contents. 
(This assumes that you'll avoid using du, or other external programs, of
course. But if you want it to be faster, avoiding externals is a good
idea.) 

> while(<*>) {

I'd use readdir instead of a glob. It won't forget about the dot files,
and it will be faster, since it won't take extra time sorting the list of
names.

>         if(/htm/ || /HTM/) { 

Maybe you mean to use /\.html?$/i there. You're not interested in a file 
named HTML.txt, are you? :-)

>             $percent=(($size/6000000)*100);

It's probably better to not hardcode a constant like that. I'd use
something like this at the top of the script... 

    use constant WHATEVER => 6_000_000;

 ...except I'd use a better name than WHATEVER, one which would make it
clear(er) what's going on here. Say, STANDARD_QUOTA or something.

>             printf "%s\t%s\t%d%%\n",$currentdir,$size,$percent;

Coming from a C programming background, are you? :-)  It's better to use
print instead of printf in general. First, round off the value of
$percent, if needed, then you can use this.

	print "$currentdir\t$size\t$percent%\n";

> closedir DIR;

How'd that get in there? :-)

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!




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

Date: Sat, 20 Dec 1997 18:20:29 +0000
From: Rosemary I H Powell <Rosie@dozyrosy.demon.co.uk>
Subject: Re: Happy birthday Perl!
Message-Id: <jjAvgNAtxAn0Ew22@dozyrosy.demon.co.uk>

In article <349A8BEC.300@usa.net>, the count <eglamkowski@usa.net>
writes
>So, what's everybody's favorite feature of perl?

So far, hashes!

And being able to come for help to c.l.p.m. when I make a hash of things
:-)
Rosemary
-------------------------------------------------------------------
| Rosemary I.H.Powell  EMail: Home: rosemary@dozyrosy.demon.co.uk |     
|                             Work: r.i.h.powell@rl.ac.uk         |
|                       http://www.netlink.co.uk/users/dozyrosy/  |
|                       http://www.dozyrosy.demon.co.uk/          | 
-------------------------------------------------------------------


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

Date: Sat, 20 Dec 1997 13:57:22 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
To: Creede Lambard <fearless@io.com>
Subject: Re: Help needed
Message-Id: <349C1512.CB13C429@coos.dartmouth.edu>

Creede Lambard wrote:
> 
> You're very close. This *can* be a simple problem. The big trick is in
> making sure you get the right match every time. In general, one way to do it
> is:
> 
> Say you want to find what's between "foo" and "bar" in a string $baz. You
> could do something like this:
> 
> $_ = $baz;
> $match = /foo([.\n]*?)bar/ && $1;

You could, but you definitely would not want to!

'.' is not a metacharacter inside a character class.  The above
regexp would match only if the string between foo and bar 
consists entirely of periods and newlines!

The correct way to do what you suggest is:

$match = /foo(.*?)bar/s && $1;

The /s modifier allows '.' to match newlines.

Chipmunk


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

Date: Sat, 20 Dec 1997 11:19:17 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Jason Schutz <jds35239@pegasus.cc.ucf.edu>
Subject: Re: Help on accessing the cgi-bin directory
Message-Id: <Pine.GSO.3.96.971220111651.2947H-100000@user2.teleport.com>

On Fri, 19 Dec 1997, Jason Schutz wrote:

>     I don't know what the problem is, maybe just a lack of privlidges,
> but I have the password for an account on an NT server and the cgi-bin I
> need to access runs parallel to my directory and I can't access it.  Is
> there any way other than saying cd ../cgi-bin  (which I tried) to access
> this directory.  Plus I've tried using put and get put that doesn't work
> either.  Please help.

It sounds as if your webmaster needs to help you. If he or she won't, get
a better one.  :-) 

Of course, there's nothing in this question about Perl. If you have
further questions about Perl which aren't answered in the docs, feel free
to post them here.  But if your question is about, say, a webserver, it
really belongs in a newsgroup about webservers, since the people there can
give you a better and more-complete answer than we can here. Good luck! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Sat, 20 Dec 1997 12:40:35 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Help with pattern matching please?
Message-Id: <3f3h76.qn1.ln@localhost>

Bart Lateur (bart.mediamind@tornado.be) wrote:
: aml@world.std.com (Andrew M. Langmead) wrote:

: >One way of solving it would be to use the \Q and maybe the \E escape
: >sequences to "quote" metacharacters. But since you want to match the

[snip]

: A "neat" solution (it is in the PODs, I'm sure), is to replace all
                           ^^^^^^^^^^^

Yes it is.

Let's go have a look at it:

from 'perlre':

--------------------------
=head2 WARNING on \1 vs $1

Some people get too used to writing things like

    $pattern =~ s/(\W)/\\\1/g;

This is grandfathered for the RHS of a substitute to avoid shocking the
B<sed> addicts, but it's a dirty habit to get into.  That's because in
PerlThink, the righthand side of a C<s///> is a double-quoted string.  C<\1> in
the usual double-quoted string means a control-A.  The customary Unix
meaning of C<\1> is kludged in for C<s///>.  However, if you get into the habit
of doing that, you get yourself into trouble if you then add an C</e>
modifier.

    s/(\d+)/ \1 + 1 /eg;

Or if you try to do

    s/(\d+)/\1000/;

You can't disambiguate that by saying C<\{1}000>, whereas you can fix it with
C<${1}000>.  Basically, the operation of interpolation should not be confused
with the operation of matching a backreference.  Certainly they mean two
different things on the I<left> side of the C<s///>.
--------------------------


: non-word characters (i.e. no letters, digits and underscore) by it
: preceded wit ha backslash:

: 	$_ = ".Chr";
: 	s/(\W)/\\\1/g;


Elsewhere in that same man page, it gives this way of doing it
without succumbing to a 'dirty habit'  ;-)


    $pattern =~ s/(\W)/\\$1/g;


Which is a "-w clean" way to do it, though quotemeta() seems much
better from a maintenance standpoint:

   $pattern = quotemeta($pattern);


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 20 Dec 1997 14:23:40 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Help with pattern matching please?
Message-Id: <349C1B3C.9C3599E5@coos.dartmouth.edu>

Bart Lateur wrote:
> 
> [Discussion of \Q and \E]
>
> A "neat" solution (it is in the PODs, I'm sure), is to replace all
> non-word characters (i.e. no letters, digits and underscore) by it
> preceded wit ha backslash:
> 
>         $_ = ".Chr";
>         s/(\W)/\\\1/g;
>         print ;
> =>
>         \.Chr

Um...  Your "neat" solution is simply another way of doing what you were
just discussing:

$_ = ".Chr";
$_ = "\Q$_\E";

Chipmunk


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

Date: Sat, 20 Dec 1997 11:47:45 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Bart Lateur <bart.mediamind@tornado.be>
Subject: Re: HELP!  Bitwise XOR (^) doesn't work on strings?
Message-Id: <Pine.GSO.3.96.971220112911.2947L-100000@user2.teleport.com>

On Sat, 20 Dec 1997, Bart Lateur wrote, concerning bitwise string and
numeric operations:

> This doesn't make sense. We've always been told that "a scalar is a
> scalar". 

Then whoever told you that was lying to you. :-)  That's not necessarily a
sin: I do that in my classes, but I tell everybody in advance that I'll
lie a little in unimportant ways. 

(Want to know how I lie? For example, I'll say that within single quotes,
you should be sure to backslash the literal single quote mark and the
literal backslash symbol itself. That's not the real rule, but it's
simpler than the real rule and will always work. And I'll say that you
should always check the return value from opening a file, even though
there are some legitimate cases where you don't need to - but once you
know what those are, you're way beyond listening to my rules! :-) 

> From a programmer's viewpoint (as opposed an implementor's
> viewpoint) we cannot distinguish between a string and a number. 

Not so. You may not know what's in a particular scalar variable, but you
can always force an expression to be seen as an integer or as a string.

	0+$foo			# gotta be an integer
	"$foo"			# sure, it's a string

If there's any doubt at all, you should use one of these methods to force
Perl to see things your way. 

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Sat, 20 Dec 1997 11:12:57 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: sportspic <sportspic@stlnet.com>
Subject: Re: HHEELLPP!
Message-Id: <Pine.GSO.3.96.971220111236.2947G-100000@user2.teleport.com>

On Fri, 19 Dec 1997, sportspic wrote:

> Subject: HHEELLPP!

Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.

    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

> I am a newbie...I am trying and set up a guestbook script(The guestbook
> at "Matt's Script Archive" to be exact) and I keep getting an "Internal
> Server Error" when trying to add to the guestbook.Can somebody please
> help me!

When you're having trouble with a CGI program in Perl, you should first
look at the please-don't-be-offended-by-the-name Idiot's Guide to solving
such problems. It's available on CPAN. Hope this helps!

   http://www.perl.com/CPAN/
   http://www.perl.org/CPAN/
   http://www.perl.org/CPAN/doc/FAQs/cgi/idiots-guide.html
   http://www.perl.org/CPAN/doc/manual/html/pod/

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Sat, 20 Dec 1997 11:28:30 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Frank Cseh <cseh@best.com>
Subject: Re: need simple mailer perl scipt
Message-Id: <Pine.GSO.3.96.971220112739.2947K-100000@user2.teleport.com>

On Fri, 19 Dec 1997, Frank Cseh wrote:

> I need a simple perl script,  that mails to me a URL 
> the visitor entered on my web page in an InputBox -form.
> The SendTo address in my email address, the URL should be put in the
> Body field.

I recommend writing this yourself; it should be good practise. There are
several modules which should help to make it easy. If you get stuck, let
us know how far you've gotten. Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Sat, 20 Dec 1997 11:53:13 -0800
From: see@my.sig (Don Groves)
Subject: Re: Perl editor needed
Message-Id: <MPG.f05c2062807b293989690@news.europa.com>

In article <x6yb1gvudb.fsf@stone.america.net>, jstone@america.net says...

> I don't think that people can really appreciate the benefits of an
> editor with features designed for programming until they have used one
> regularly for a while (my personal choice is Emacs although there are
> others -- particularly it seems on the Windows platform).
> 
> Benefits like color syntax-highlighting, automated indentation (with
> selectable style), brace/bracket/paren matching, tags support, class
> browser, single command commenting and uncommmenting of entire regions
> of code, integrated compilation and debugging, and other
> programming-specific features are benefits that I could not live
> without and program with MS-Word.
> 
> There are free as well as commercial editors for programmers.  I would
> encourage you to try one (or a few) if coding (whether in Perl, C,
> Java, or whatever) is something you do on a regular basis.  You might
> be very pleasantly surprised.
> 
> Jeff
> 

Win95/NT programmers looking for a programmers editor should give
UltraEdit a try.  It is cheap, very fast, and supports color syntax-
highlighting for up to 6 languages of your choice (including Perl),
and has a very nice tabbed-panel interface for switching between
buffers with a single click.  You can run Perl from within the editor
and capture the output to a buffer.  Highly recommended.

Having said that, I have just installed Linux and once I am comfortable
with Emacs, I'll probably start using it for both Linux and NT editing.
Just like Jeff, I'll likely not want to give up all those other features.

Don

#------------------------------------------------------------
my %sig = (name => "Don Groves", email => "groves\@acm.org");
#------------------------------------------------------------


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

Date: Sat, 20 Dec 1997 12:42:53 -0500
From: Rakesh Chitradurga <Rakesh.Chitradurga@sdrc.com>
Subject: perl glue between C and the web
Message-Id: <349C039C.BD74AB0E@sdrc.com>

Hi ,
I am trying to embed a perl interpreter in C  and I have been able to
run a perl program from C code
using the  API in the perlembed manuals.
But I am also trying to run a  perl_CGI program which uses the CGI.pm
on my web server .
Effectively what I am trying to do is this:

perl_parse (..... "filename is  whatever.pl");

This file whatever.pl  uses the CGI.pm lib to construct a html file and
do whatever it needs to do with it.
The pb is that the perl script ends up executing in offline mode  when
I run the C program as the perl interpreter is in
my C code. What I want to achieve is  to have  my web server run the
perl script ilke the
CGI examples.
In fact when I run the whatever.pl on  my web server it runs fine and
displays the
output as I want to.
The problem as you might have guessed is to find the glue that ties the
C code with the
web. The actual intent would be to pass arguments to /from C modules to
the
perl programs that would do any CGI processing.
Any pointers on how I  might go about this would be appreciated.  Any
pointers to any documenation
on similar efforts  would also be appreciated.
Thanks
Rakesh




--
Rakesh.Chitradurga@sdrc.com________________________



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

Date: 20 Dec 1997 18:31:23 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: perl glue between C and the web
Message-Id: <67h2tr$61a@fridge.shore.net>

Rakesh Chitradurga (Rakesh.Chitradurga@sdrc.com) wrote:

: I am trying to embed a perl interpreter in C  and I have been able to
: run a perl program from C code
: using the  API in the perlembed manuals.

Your linewrap is atrocious, sir.

Are you already running Apache?  If not, I'd strongly suggest looking
into the following:
1) Apache 1.2.4 http://www.apache.org/
2) mod_perl http://www.perl.com/CPAN/modules/by-module/Apache/

--
Nathan V. Patwardhan
please don't send spam to pres@whitehouse.gov


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

Date: Sat, 20 Dec 1997 14:37:45 -0500
From: Chipmunk <rjk@coos.dartmouth.edu>
Subject: Re: Read in Mailfolder
Message-Id: <349C1E89.8DA205C5@coos.dartmouth.edu>

Puck wrote:
> 
> Hi !
> 
> Can someone give me a script that shows how to read in
> /var/spool/mail/root or /var/spool/mail/user_name ?
> 
> Please don't make it to complicate because I'm new at perl !

$file = "/var/spool/mail/root";
open(MAILF, $file) or die "Unable to open $file: $!";
undef $/;
$mail = <MAILF>;


Do you want to parse the mailfolder into messages or somesuch?
Keep in mind that the script will have to be more complicated
in that case.

Chipmunk


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

Date: Sat, 20 Dec 1997 11:55:44 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Puck <tpuck@usa.net>
Subject: Re: Read in Mailfolder
Message-Id: <Pine.GSO.3.96.971220115435.2947O-100000@user2.teleport.com>

On Sat, 20 Dec 1997, Puck wrote:

> Can someone give me a script that shows how to read in
> /var/spool/mail/root or /var/spool/mail/user_name ?

Any good book on Perl for beginners should show you how to make a script
which can read files. I recommend the Llama, available at your favorite
bookstore. Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Sat, 20 Dec 1997 20:36:18 GMT
From: jdvf.nospam@concentric.net (John Devitofranceschi)
Subject: Re: references to globalise locally generatied filehandles
Message-Id: <349c2abe.19634393@news.concentric.net>

On 17 Dec 1997 17:11:19 GMT, Tom Christiansen <tchrist@mox.perl.com>
wrote:

>:a filename and returns a filehandle (actually, it is a little
>:more complicated, but the problem lies here).
>:
>:        sub newopen {
>:             my $path = shift;
>:             local *FH;  # not my!
>:             open (FH, $path) || return undef;
>:             return \*FH;
>:         }
>:         $fh = newopen('/etc/passwd');
>
>The bug is the backslash there in the return.  Although 
>when I first wrote that code it worked fine, for reasons
>that are less than perfectly clear, it now has to be 
>return *FH instead.  The Camel and manpages have been 
>corrected, but perhaps you were reading something old.
>
>You might want to consider doing 
>
>    use Symbol;
>    $fh = gensym();
>
>Check the manpage on the standard Symbol manpage.
>
>--tom

That works for me!  However, what I really want is to 
assign the returned filehandle to a hash value like this:

$myFHs{$afile}= newopen($afile);

However, this seems to not work when I try to read from
<$myFHs{$afile}>

Is something funny going on here?

cheers,
jd




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

Date: Sat, 20 Dec 1997 13:54:14 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: Regular Expression Question - non greedy match
Message-Id: <1d1k9zo.t6fe9f1gby4rhN@roxboro-188.interpath.net>

Honza Pazdziora <adelton@fi.muni.cz> wrote:

> phenix@interpath.com (John Moreno) writes:
> 
> > I was trying to correct a soup file that had been edited so that the
> > article length was correct and ran into some behavior that I don't
> > understand (why not what).
> > 
> > I'm slurping the whole file in and then using the expression:
> > 
> > $count = s/(#! rnews )(\d+\n)(.+?)/$1.(length $3).("\n").$3/gse;
> > 
> > Which gives 1 char for the (length $3), I would have thought that it
> > would go until it hit the next #! rnews.
> > 
> > Why doesn't it?
> 
> Why should it? You said .+? which means at least one any character and
> the least possible count. Which gives us nice 1.

I understand what it was doing, I'm just not sure why the ? wasn't more
greedy - I would have thought that when using the /g that a ? at the end
of a expression would wrap around around to the beginning of the
expression.  But on thinking about it I guess it could be a problem with
infinite recursion.

> You probably wanted something like
> 
> (#! rnews )(\d+\n)(.+?(?=#!|$))
> 
> to make it extend till next #! or end.

I used (rnews )(\d+\n)(.+?)(#!) and then corrected the last one by hand,
didn't think of the lookahead until after I'd done it.

-- 
John Moreno


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

Date: Sat, 20 Dec 1997 12:00:47 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Don <dgoyette@NoMoreSPAMpcisys.net>
Subject: Re: Scanning the access_log file
Message-Id: <Pine.GSO.3.96.971220115700.2947P-100000@user2.teleport.com>

On 19 Dec 1997, Don wrote:

> I guess I would need the following 'routines' and/or 'code sections': 
> 
> 1. A means to scan (read through) every record in the access_log file.

Any good book for Perl beginners should show you how to read files. I
recommend the Llama book, available from your favorite bookstore.

> 2. A means to select ONLY those records that contain the string
> "~dgoyette".

You can do that using index().

> 3. A means to store all 'selected' records, or just the URL part of the
>    record (could be tens of thousands of records selected).

If you want to store those into a file or array, there should be a chapter
on either of those in any good book. If you wish to use a database, the
Llama even has a chapter about that.

> 4. A means to scan all selected records accumulating totals for each
>    'specific' filename (for example "~dgoyette/index.html/whitesat.jpg").

A hash might be good, if you wish to tally each individual file. The Llama
has a chapter on hashes as well.

> 5. A means to store the filenames and their accumulated totals in a
>    plain text file for transfer to our PC for printing and/or storage.

And writing files should be covered near where the book talks about
reading them. 

If you're not sure which one is the Llama book, there's information about
it in the perlbook manpage. Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Sat, 20 Dec 1997 11:26:01 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Chris Thornton <avies@penny-empire.com>
Subject: Re: sending email (Net::SMTP).. problem
Message-Id: <Pine.GSO.3.96.971220112511.2947J-100000@user2.teleport.com>

On Sat, 20 Dec 1997, Chris Thornton wrote:

> $mailhost = 'my.mail.server';
> $smtp = Net::SMTP->new($mailhost);

> and it all works fine if the mail server is up... the problem is, I
> need this to send mail out ALL THE TIME 

There's not a whole lot you can do if the server isn't up. But have you
tried checking the return value in $smtp? If it's undef, that's a bad
sign. :-)

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Sat, 20 Dec 1997 14:01:06 -0600
From: bryl@medicine.wustl.edu
Subject: split bug in perl5.004?
Message-Id: <882647607.1009975299@dejanews.com>

Howdy - I've looked through prior stuff in comp.land.perl.misc and
couldn't find anything that addresses a problem we're having with
perl 5.004.

We run a number of CGI script on our site (SunOS 5.6/ Apache 1.3) -
information is parsed in the usual manner with a line:

%rqp = &url_decode(split(/[&=]/,$request));

(incoming info held in $request). Since we have installed perl 5.004 we
sometimes get errors stating:

Odd number of elements in hash list at /home/user/lib/perl.library line 23
(line 23 as above).

This *only* seems to happen when the last field held in $request is blank,
so it looks like name=value&name2=value2&last_one=
though, adding white space at the end doesn't fix the problem
	i.e $request = "$request " if($request =~ /=$/);

Right now I get around it by doing a long-winded approach of
	@rqp = split(/&/,$request);
	foreach(@rqp){
		($key,$val) = split(/=/);
		&url_decode($key,$val);
		$rqp{$key} = $val;
	} # etc..

We don't have this problem with perl5.003 on the same system. Is there
any reason perl5.004 is being so much more of a stickler?

Thanks for any help..

-L. Bry, MadSci Admin

__________________________________________________________________________
                            The MAD Scientist Network
                  http://madsci.wustl.edu  http://www.madsci.org
                            webadmin@madsci.wustl.edu
                          "Ask-A-Scientist" on the WWW

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 20 Dec 1997 10:46:14 -0800
From: danny@lennon.postino.com (Danny Aldham)
Subject: Re: Statistics for comp.lang.perl.misc
Message-Id: <67h3pm$188$1@lennon.postino.com>

X-Newsreader: TIN [version 1.2 PL2]

Bart Lateur (bart.mediamind@tornado.be) wrote:
: WOW! I'm both in the top 10 and in the bottom 10!
: And it's not just me: it looks like the statistics only included 13
: posters... Anthony David is both number 4 and number 10th from the
: bottom up.
: Ah... the decline of CLPM... ;-)

Was it Sam Clemmens that said their were 3 kinds of lies: 
lies, damn lies & statistics? If you mine deep enough into
any database you will find nonsense. 

--
Danny Aldham           SCO Ace , MCSE , JAPH , DAD
Ban the neutral zone trap. It's killing our National sport.


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.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 1514
**************************************

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