[6399] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 24 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 27 14:28:23 1997

Date: Thu, 27 Feb 97 11:00:27 -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           Thu, 27 Feb 1997     Volume: 8 Number: 24

Today's topics:
     !!!help me please!!! <anon7@ntplx.net>
     Re: !!!help me please!!! (Nathan V. Patwardhan)
     Childishly easy problem for a perl stud <cbehrens@cyberhighway.net>
     Counting Character Positions on a line for Database <omc@worldnet.att.net>
     Re: Counting Character Positions on a line for Database (Nathan V. Patwardhan)
     Counting the number of functions in C/C++ source <Doug.Carter?@tek.com>
     Re: FILE LOCKING <neiled@enteract.com>
     Re: File Locking (Bob Dixon)
     Re: File Locking (Nathan V. Patwardhan)
     Re: FILE LOCKING (Rand Simberg)
     Re: File Locking (Chris Russo)
     Re: Generating a randomly sorted list of integers (Jan Schipmolder)
     Re: Gross error in regular expression (...)? clause (Jeffrey)
     Re: help: date to time conversion <jander@ml.com>
     Hiring Webpage Designers (Jon Sullivan)
     Re: How to define a C++ static method in Perl (Jagadeesh Venugopal)
     Re: How to keep parent processing running until child e (Clinton Pierce)
     Re: How to spam - legitimately (Chris Nandor)
     Re: HOW TO SPLIT A SIMPLE STRING (Peter G. Ford)
     I'll be in Arlington VA next week and weekend ... <merlyn@stonehenge.com>
     My Witzend<--I : Curses install problem on SCO UNIX (Dave Wheeler)
     Newbie question: string replacement for MIF <lynne@sweng.stortek.com>
     Optimizing nested loops (Doug Alcorn)
     Oraperl for NCR, any one have a complied copy? <orange@globalserve.net>
     Re: Problems reading file using <> operator (Dan Rasmussen)
     Re: Regular Expression question <jander@ml.com>
     RE: Removing trailing and leading spaces (Avi)
     Using Perl and Sendmail to email a gif or jpeg <news@sawcomputer.com>
     Re: Using Perl and Sendmail to email a gif or jpeg (Nathan V. Patwardhan)
     Which database in Perl? (Guy Saner)
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: Thu, 27 Feb 1997 12:24:24 -0500
From: Allen Joslin <anon7@ntplx.net>
Subject: !!!help me please!!!
Message-Id: <3315C339.3AF3@ntplx.net>

Hi All,

	I'm trying to learn enough perl to modify a script called WWWBoard (by
Matt Wright, who I've tried to contact -- unsuccessfully) in order to
hide any/all obtainable user info in the posted messages, to try to help
catch anonymous posters of obscene msgs.

	I've found the $ENV 'REMOTE_HOST' but it only seems to take me back to
the users' host.  I can't seem to get the users' id/username.  Is that
possible?
	
	Is there a list of $ENV somewhere?

	What's the best way to identify a user of a site that's running perl
scripts?

Thanks,

Al;


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

Date: 27 Feb 1997 17:49:12 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: !!!help me please!!!
Message-Id: <5f4heo$dfm@fridge-nf0.shore.net>

Allen Joslin (anon7@ntplx.net) wrote:
: 	I'm trying to learn enough perl to modify a script called WWWBoard (by
: Matt Wright, who I've tried to contact -- unsuccessfully) in order to
: hide any/all obtainable user info in the posted messages, to try to help
: catch anonymous posters of obscene msgs.

Wow, good luck with your endeavors.  ;-)

Seriously, there's no good way to do this.  I'd strongly suggest
looking into some docs about CGI/Security/environment variables
from your favorite search engine!

One way to get information about the "environment" is to use %ENV, a
hash of environmental variables.

Ex: 

#!/usr/local/bin/perl

print "Content-Type: text/html\n\n";

foreach $key (keys %ENV) {
   print("$key = $ENV{$key}<BR>\n");
}

exit;


--
Nathan V. Patwardhan
nvp@shore.net
"What is your favorite color?
Blue ... I mean yellow ... aieeeee!
	--From the Holy Grail"


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

Date: 27 Feb 1997 18:19:10 GMT
From: "Chris Behrens" <cbehrens@cyberhighway.net>
Subject: Childishly easy problem for a perl stud
Message-Id: <01bc24da$7d1b41a0$a574d7ce@iac165>

OK guys....

I am a Perl newbie;

I have a form which submits an part of an URL. I need a perl script which
takes the GET
input, concatenates it to the rest of the (preformatted) URL and redirects
it.

Anyone know of any examples?

Please email me with any response...
-- 
Chris Behrens
cbehrens@cyberhighway.net
Microsoft Site Builder Level 2
http://www.deltav.net

"Are we not drawn onward, we few, drawn onward
to new era?"


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

Date: Thu, 27 Feb 1997 12:19:45 -0500
From: Michael DeVivio <omc@worldnet.att.net>
Subject: Counting Character Positions on a line for Database
Message-Id: <3315C231.6CD9@worldnet.att.net>

Hello,

I am a fairly new PERL programmer with some luck workong with flat file
databases on the web.

I have a report I get every month that has information I need but many
of the characters on each line I do not. Each character position on a
line means something, for example characters 45-52 might be a phone
number called. My question is how do I get only the characters I want so
I can make them $variables for my program. Are there any good sorting
programs on the market or can I write a simple script to access these
characters and export them to a simple flatfile database?

Thank you in advance for your replies and if possible, please send them
to my e-mail address (omc@worldnet.att.net).

Regards,

Michael


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

Date: 27 Feb 1997 17:40:09 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Counting Character Positions on a line for Database
Message-Id: <5f4gtp$dfm@fridge-nf0.shore.net>

Michael DeVivio (omc@worldnet.att.net) wrote:

: I have a report I get every month that has information I need but many
: of the characters on each line I do not. Each character position on a
: line means something, for example characters 45-52 might be a phone

If I understand your question correctly, you might want to look into
substr(), which considers position in a line (string).  This should be
documented in one of the Perl manpages, like perlfunc -> you could always
"grep" for it.  :-)

--
Nathan V. Patwardhan
nvp@shore.net
"What is your favorite color?
Blue ... I mean yellow ... aieeeee!
	--From the Holy Grail"


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

Date: Thu, 27 Feb 1997 08:30:14 -0800
From: Doug Carter <Doug.Carter?@tek.com>
Subject: Counting the number of functions in C/C++ source
Message-Id: <3315B696.3E22@tek.com>

Does anyone have a perl script that counts the number of
functions in C/C++ source code?

TIA,

Doug Carter
Tektronix, Beaverton

-- 
Please remove the ? in my email path to reply.


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

Date: 27 Feb 1997 16:31:27 GMT
From: "Neil Edmondson" <neiled@enteract.com>
Subject: Re: FILE LOCKING
Message-Id: <01bc24cb$73269280$6b9a70cf@default>



Neil Edmondson <neiled@enteract.com> wrote in article
<01bc2455$75ba6060$1d94e5cf@default>...
> Although the following code will do what I want (that is I can live with
> the risk).  There's a big hole re: locking.  What strategies exist to
deal
> with the possibility that someone else may grab the file and screw with
it
> in between reading and writing?
> 
> 		open (SESSION, "<" . $session_file);		# Open the file for reading
> 		flock (SESSION, $exclusive_lock);			# and lock it for exclusive use
> 		$session_ID = <SESSION>;			#
> 		flock (SESSION, $remove_lock);			# Give the file back
> 		close (SESSION);
> 
> 		$session_ID++;					# Bump the session counter
> 
> 		open (SESSION, ">" . $session_file);		# Open the file for writing
> 		flock (SESSION, $exclusive_lock);			# and lock it for exclusive use
> 		print SESSION $session_ID;			# and rewrite
> 		flock (SESSION, $remove_lock);			# Give the file back
> 		close (SESSION);
> 
> TIA, Neil
> neil@weaveware.com

Here's my own solution to this little problem if anyone's interested...

                @ARGV = ($session_file);
                $^I = ".bak";                                   # Make a
backup while
                while (<>) {                                    # copy-pass
editing
                        $_++;                                   # Bump the
session ID
                        print;                                  # Rewrite
                }

                open (SESSION, "<" . $session_file);            # Open the
file for reading
                $session_ID = <SESSION>;                        # Set the
session ID
                close (SESSION);


> 
> ---------------------------------
> Collectible baskets on the web at
> 
> http://www.weaveware.com
> ---------------------------------
> 


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

Date: Thu, 27 Feb 1997 16:58:49 GMT
From: sasrmd@unx.sas.com (Bob Dixon)
Subject: Re: File Locking
Message-Id: <sasrmd.857062729@sas.com>

Tom Christiansen <tchrist@mox.perl.com> writes:

> [courtesy cc of this posting sent to cited author via email]

>In comp.lang.perl.misc, 
>    jhoglund@skypoint.com (Jamie Hoglund) writes:
>:  open(FILE,"+>filename"); 

>BUG BUG BUG: Your open mode is wrong.  You need +< instead.

  On my system +< fails if the file doesn't already exist and +>
overwrites the file if it does (which I don't want).  What I did was:

open(FILE, "+<filename") || open("+>filename") || die "etc";

  I'm interested in criticism/comments on the above, since I'm
relatively new to perl.

--
--

Bob Dixon (sasrmd@unx.sas.com)
Tool Development and Training
SAS Institute, Inc.
919-677-8000, x6685, R-2138  


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

Date: 27 Feb 1997 17:37:07 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: File Locking
Message-Id: <5f4go3$dfm@fridge-nf0.shore.net>

Bob Dixon (sasrmd@unx.sas.com) wrote:

:   On my system +< fails if the file doesn't already exist and +>
: overwrites the file if it does (which I don't want).  What I did was:

Right.  From the Perl docs, you'll note that +< will fail if the file
does not exist.  +> will create a new file in read/write.

: open(FILE, "+<filename") || open("+>filename") || die "etc";

You might try something like:

$filename = 'filename';
if(-e "$filename") {
   ### open r/w
} else {
   ### open c/r/w
}

--
Nathan V. Patwardhan
nvp@shore.net
"What is your favorite color?
Blue ... I mean yellow ... aieeeee!
	--From the Holy Grail"


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

Date: Thu, 27 Feb 1997 17:50:25 GMT
From: simberg@interglobal.org (Rand Simberg)
Subject: Re: FILE LOCKING
Message-Id: <3315a5c1.71585835@nntp.ix.netcom.com>

On 27 Feb 1997 02:26:57 GMT, in a place far, far away, "Neil
Edmondson" <neiled@enteract.com> made the phosphor on my monitor glow
in such a way as to indicate that:

>Although the following code will do what I want (that is I can live with
>the risk).  There's a big hole re: locking.  What strategies exist to deal
>with the possibility that someone else may grab the file and screw with it
>in between reading and writing?
>
>		open (SESSION, "<" . $session_file);		# Open the file for reading
>		flock (SESSION, $exclusive_lock);			# and lock it for exclusive use
>		$session_ID = <SESSION>;			#
>		flock (SESSION, $remove_lock);			# Give the file back
>		close (SESSION);
>
>		$session_ID++;					# Bump the session counter
>
>		open (SESSION, ">" . $session_file);		# Open the file for writing
>		flock (SESSION, $exclusive_lock);			# and lock it for exclusive use
>		print SESSION $session_ID;			# and rewrite
>		flock (SESSION, $remove_lock);			# Give the file back
>		close (SESSION);

I asked a similar question a couple of days ago:

<QUESTION>Maybe there's an obvious answer to this, but I'm concerned
about how
to use flock.  If I want to update a file, I need to open it for a
rewrite, but if I do this, I lose all of the data in it before I can
process it.  So I open it for read only first, read the data, close
it, and then reopen it for a rewrite.  Each time I do this, I lock it,
but I'm concerned that another program instance will grab the file in
between the time that I close it for the read, and reopen it for the
rewrite.  

How do I ensure that I have exclusive use of the file throughout the
period in which I need to both read and rewrite it?  Can I do an open
for rewrite (with a different filehandle) before I close the read
filehandle?</QUESTION>

To which I got the reply:

<SOLUTION>
I found this in the man-page for open:

If the filename begins with ``<'' or nothing, the file is opened for
input. If the filename begins with ``>'', the file is opened for
output. If the filename begins with ``>>'', the file is opened for
appending. You can put a '+' in front of the '>' or '<' to indicate
that you want both read and write access to the file; thus '+<' is
usually preferred for read/write updates--the '+>' mode would clobber
the file first. These correspond to the fopen(3) modes of 'r', 'r+',
'w', 'w+', 'a', and 'a+'.

So +< is enough.</SOLUTION>

This may help you also.  Just do one file open and close with +<.

************************************************************************
simberg@interglobal.org  * 310 372-7963 (CA) 307 739-1296 (Jackson Hole)  
interglobal space lines  * 307 733-1391 (Fax) http://www.interglobal.org 

"Extraordinary launch vehicles require extraordinary markets..."


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

Date: Thu, 27 Feb 1997 09:51:00 -0800
From: crusso@alink.net (Chris Russo)
Subject: Re: File Locking
Message-Id: <crusso-2702970951000001@buzz.alink.net>

[mailed and posted]

In article <5f3jfa$jha$1@csnews.cs.colorado.edu>, tchrist@mox.perl.com
(Tom Christiansen) wrote:

>
>:  flock(FILE,8);
>:  close(FILE); 
>
>BUG BUG BUG: You unlocked the file before your data made
>it to disk.  Close the thing, or autoflush the handle.

Ya know, I was wondering if that was a possibility.

Is this also the case when you open the file in append mode?

If so, the new camel book has a bug in flock's example program, because it
does an unlock, then a close, without ever turning buffering off (I'm
assuming you mean turning buffering off when you use the term
"autoflush").

Chris Russo

----------------------------------------------------------------------
Chris Russo                          A-Link Network Services, Inc.
crusso@alink.net                     Bolo me
http://www.alink.net/~crusso


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

Date: 27 Feb 1997 17:23:46 GMT
From: schip@lmsc.lockheed.com (Jan Schipmolder)
Subject: Re: Generating a randomly sorted list of integers
Message-Id: <5f4fv2$eig@butch.lmsc.lockheed.com>

spammers@must.die.com wrote:
: >"I'm writing this on my Timex Sinclair, with only 2K of memory..."  ;-)
: 
: I was surprised how little memory I had available when I ported some
: scripts from Unix to MacPerl. I "randomize" /usr/dict/words or whatever

Here is a faster way to pick a random word from /usr/dict/words:

- use stat to find the length of the file
- go to a random offset from the beginning
- read one line
- this line is probably not a full line, since you went to a random spot
  in the file
- read one more line
- this line is a full line from the file; it's also "random"
- since /usr/dict/words has one word per line, you now have a random word
- repeat if the second read gave you end-of-file

--
jan.b.schipmolder@lmco.com


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

Date: 27 Feb 1997 17:36:33 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Gross error in regular expression (...)? clause
Message-Id: <JFRIEDL.97Feb28023633@tubby.nff.ncl.omron.co.jp>


[mail and post]

Mark-Jason Dominus <mjd@plover.com> wrote:
|> $RX_US = "U(\.|nited)?\s*S(\.|tates)?(\s*(of\s*)?A(\.|merica)?)?";
|
|> WARNING: `United States' did NOT match $RX_US.
|> WARNING: `United States of America' did NOT match $RX_US.
|
|> 
|> Why didn't those two strings match?

Probably because all your backslashes are lost by the doublequoted-string
processing, so the regex engine sees 's' where you want it to see '\s'.
Either escape the escapes, or use single quotes.

(PS: don't feel too bad about getting bitten by this -- even I still forget
     about it from time to time!)

Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@ora.com> Omron Corp, Nagaokakyo, Kyoto 617 Japan
See my Jap<->Eng dictionary at http://www.wg.omron.co.jp/cgi-bin/j-e
O'Reilly's Regular Expression book: http://enterprise.ic.gc.ca/~jfriedl/regex/


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

Date: 27 Feb 1997 09:36:09 -0600
From: Jim Anderson <jander@ml.com>
Subject: Re: help: date to time conversion
Message-Id: <wkbrai2gt1y.fsf@swapsdvlp15.i-did-not-set--mail-host-address--so-shoot-me>

paul@comp.lancs.ac.uk (Paul Rayson) writes:

> I want to convert a string 'Wed Feb 26 13:17:09 GMT 1997' to a time
> stamp (number of seconds since 1970) in order to compare dates. I've
> looked at localtime and timelocal and so on, but I think I need the
> reverse of ctime. Has this already been done anywhere?

check Date::Format in the TimeDate package.

-- 
Jim Anderson			jander@ml.com
Consultant-at-large		jander@jander.com
				(212) 449-1598


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

Date: Thu, 27 Feb 1997 18:06:50 GMT
From: jons@compute.com (Jon Sullivan)
Subject: Hiring Webpage Designers
Message-Id: <3315cd27.8674717@news.ni.net>

Network Intensive of Irvine, California, is accepting applications for
full time Webpage Illustrators/Designers.  This is a salaried
position.  The ideal candidate would have experience designing
webpages at a professional level, familiarity with UNIX, Photoshop
expertise, proven design skills, an understanding of CGI and Perl,
good customer interaction skills, and familiarity with emerging web
technologies.  Illustration skills are a major plus.

We are not interested in freelance or telecommuting developers.  Our
developers work closely together to bring our customers polished and
professional designs.

We specialize in custom Web solutions, back-end programming, on-line
commerce, and complete connectivity solutions.

Please e-mail your resume to employment@ni.net or mail it to: 

                       Network Intensive
                       8001 Irvine Center Drive, Suite 1130
                       Irvine, California 92718
                       Attn: Employment Opportunities 

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

Network Intensive, a complete network solution provider, is a
full-service provider of network consultation, and high-performance
products and services to technically oriented businesses of the
greater LA Basin and Albuquerque, New Mexico markets. The company is
headquartered in Irvine, California , with a regional office in
Albuquerque, New Mexico. Sales are handled directly through the
technical account teams operating from both locations. For more
information, visit the Network Intensive Web Site: http://www.ni.net,
or businesses can call Network Intensive at 1-800-273-5600.



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

Date: 27 Feb 1997 16:09:26 GMT
From: jvenu@ctp.com (Jagadeesh Venugopal)
Subject: Re: How to define a C++ static method in Perl
Message-Id: <5f4bjm$qi6@concorde.ctp.com>

In article <33159FCA.59E2B600@india.ti.com> Ajitesh Das <baku@india.ti.com> writes:
>Hi All,
>  I am facing a problem while working with perl object.
>I need to have a methoed in a Perl class, which will be 
>a "static" method. ( eg same C++ static method ) 
>Can anybody give me an example/URL?....
>

Please refer to Tom's excellent Perl OO tutorial:
http://www.perl.com/perl/all_about/perltoot.html

>P.S : Please send me a copy of your reply via E-mail

Sorry. People who answer read this newsgroup. It is not 
unreasonable to expect people who seek answers to do 
the same. 

Jagadeesh
(Personal opinions only)

-- 
 /\/\ |Jagadeesh K. Venugopal, jvenu@ctp.com |http://w3.ctp.com/~jvenu 
/ /_.\|Cambridge Technology Partners, Inc.   |http://www.ccs.neu.edu/home/jkvg 
\  /./|304 Vassar St.  Cambridge, MA 02139   |
 \/\/ |Phone: 617.374.2028 FAX: 617.374.8300 +


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

Date: 27 Feb 1997 17:15:19 GMT
From: cpierce1@cp501.fsic.ford.com (Clinton Pierce)
To: Brett Denner <dennerbw@lmco.lmtas.com>
Subject: Re: How to keep parent processing running until child exits?
Message-Id: <5f4ff7$oc92@eccws1.dearborn.ford.com>

In article <33146D40.41C6@lmco.lmtas.com>,
	Brett Denner <dennerbw@lmco.lmtas.com> writes:
>I need to fork a child process to accomplish a task, and, in the
>meantime, have the parent process execute a loop until the child process
>is finished....
>
>I know how to fork a child and have the parent wait until the child is
>finished before the parent continues:

Cool, then you're ALMOST there...

> [edited]
>I want to do something like the following:
>
>  if ($pid = fork)
>      {
>      # parent process
>      TASK:
>      while (1)
>          {
>          # do some repetitive task while child runs
>          last TASK if &child_is_finished($pid);
>          }
>      }
>  elsif (defined $pid)
>      {
>      # child process
>      exit;
>      }
>
>Is there a way to accomplish what the "&child_is_finish($pid)" function
>does in the preceding example?

Yes.  The waitpid() you've been diddling with waits for a signal from the
child and in your case, hangs until the signal is received.  UNIX children
send a signal to their parent process when they die.

What you need to to is:

	while(1) {
		last if ($sigchld_received);
	}

Setup a signal handler to catch the signal coming in from the child
and set $sigchld_received if you get it.  Relevant UNIX/Perl functions 
and manpages are signal(2), chapter 6 in the Perl 5 Camel book and kill(1).
The REAPER() function in Chapter 6, page 340 (10/96 printing) does almost
exactly what you want...


PS: Remember to code stuff so that if the child exits TOO SOON that you 
don't wait around forever for a signal that you'll never get, 'cause
you've already received it.  HINT.

-- 
+----------------------------------------------------------------------------+
|    Clinton A. Pierce      |   "If you rush a Miracle Man,   | http://www.  |
|    cpierce1@ford.com      |     you get rotten miracles"    | dcicorp.com/ |
|     cpierce@mica.net      |--Miracle Max, The Pricess Bride | ~clintp      |
+----------------------------------------------------------------------------+
GCM/GCSd-s+:+a-C++UALIS++++P++++L++E---t++X+b+++DI++++G++e+>++h----r+++y+++>y*



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

Date: Thu, 27 Feb 1997 10:56:09 -0500
From: pudge@pobox.com (Chris Nandor)
Subject: Re: How to spam - legitimately
Message-Id: <pudge-ya02408000R2702971056090001@news.idt.net>

Alright, here's a new one (name withheld, posted to comp.lang.perl.modules):

#You can send me by email

Now THAT would be an interesting trick ... ;-)

#================================================================
Last year I went fishing with Salvador Dali.  He was using a
dotted line.  He caught every other fish.

   --Steven Wright

Chris Nandor                                      pudge@pobox.com
PGP Key 1024/B76E72AD                           http://pudge.net/
Keyfingerprint = 08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6


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

Date: 27 Feb 1997 16:36:33 GMT
From: pgf@space.mit.edu (Peter G. Ford)
Subject: Re: HOW TO SPLIT A SIMPLE STRING
Message-Id: <slrn5hbe0g.a7v.pgf@acis.mit.edu>

On Fri, 14 Feb 1997 13:47:44 -0500, I R A Aggie <fl_aggie@hotmail.com>
wrote:
>In article <5e254b$to6$1@news.nyu.edu>, donahue@acf2.nyu.edu (Adam M.
>Donahue) wrote:
>
>+I have a a six character string,
>+ say 012345, that I want to split into three variables, $one, $two, $three
>+ that would then have 01, 23, 45.  The original string has no
>+ delimiters, though.
>
>+ What's the best way to do this?  It seems like an easy task, but I can't
>+ figure it out.
>
>$var1=substr($string,0,2);
>$var2=substr($string,2,2);
>$var3=substr($string,4,2);

# How about...
 
($var1,$var2,$var3) = $string =~ /(..)(..)(..)/;
 
# Moral: never use 3 lines of Perl if you can accomplish the same
# thing in one (while thoroughly confusing everyone in the process).
 
--
Peter Ford
<pgf@space.mit.edu>




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

Date: 27 Feb 1997 08:52:46 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: I'll be in Arlington VA next week and weekend ...
Message-Id: <8c7mjuutyp.fsf@gadget.cscaper.com>


 ... teaching a Perl class at the Washington Post.

Since I'm not one to refuse a free meal, if anyone wants to buy me
dinner, I can promise an interesting evening of war stories, both Perl
and legal.  Let me know by email.  Past experience dictates that you
should put in your request early, so as not to miss out. :-)

Also, if you have any tips about relaxing or interesting things to do
in or near Arlington on the weekend, I'd be happy to listen.

ObPerl: for ($n = 0; /(?=pat)/g; $n++) {;} # count overlapping pattern in $_

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 551 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Thu, 27 Feb 1997 17:08:59 GMT
From: Dave@xenware.demon.co.uk (Dave Wheeler)
Subject: My Witzend<--I : Curses install problem on SCO UNIX
Message-Id: <3315bd6a.1660905@news.demon.co.uk>

System SCO UNIX 3.2v4.2

Having downloaded the perlcurses module from CPAN and attempted to
install following the instructions in the INSTALL file, I get the
following while trying to run the demo:-

>Can't load module Curses, dynamic loading not available in this perl. 
>(You may need to build a new perl executable which either supports
>dynamic loading or has the Curses module statically linked into it.)
>at /opt/lib/perl5/site_perl/Curses.pm line 8
> BEGIN failed--compilation aborted at demo line 3.

I have also attempted to reinstall the perl and it gives every
appearance of installing DynaLoader ok (although I confess I am unsure
if this is required or not!)

I would be extremely grateful if anyone can throw any light on the
source of the problem ( probably me :-(   ).

TIA


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

Date: Thu, 27 Feb 1997 16:00:03 GMT
From: Lynne Frederickson <lynne@sweng.stortek.com>
Subject: Newbie question: string replacement for MIF
Message-Id: <3315AF83.AF5@sweng.stortek.com>

Hello,

This is a newbie question from a new perl programmer
with only a little C and some shell programming experience:

I am trying to write a program to search for and replace
strings for the purpose of applying a new template to
FrameMaker MIF files.

I know the basic "search and replace" syntax, and can
do what I want from the command line via commands
like this:

perl -pi.bak -e 's/oldtext/newtext/g' filename

My problem is I want to replace alot of strings, and I
want to do this on multiple files supplied as command
arguments, but I haven't yet figured out how to put that
altogether in a script that works right. What is the basic 
syntax for doing lots of string replacements?
Do I need to do something with open() to open the files from 
inside the script?  Do I need to do something with shift() to
get to the next ARGV?

As you can see, I'm embarassingly green. Any advice or
better yet, code samples, would be GREATLY appreciated.

emailed replys are also appreciated...

______________________________________________________________
Lynne Frederickson (lynne@sweng.stortek.com)     (313)665-4138


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

Date: Thu, 27 Feb 1997 00:22:01 GMT
From: alcornd@conterra.com (Doug Alcorn)
Subject: Optimizing nested loops
Message-Id: <3314d089.38899282@news.conterra.com>

I have a script I am writing.  It works, but it is slow IMO.  I am new
to perl, and am unexperienced at optimizing it.  I would appreciate
any pointers in how I can improve it.

I have two lists.  The bom file needs to be expanded based on the
part_num file.  The first field of the bom is the grade.  I need to
output as many lines as I have part numbers with the same grade,
replacing the bom grade with the part number.  Let's say my bom list
look like this:

1004~1~TN~XXXXX~1325~0000.2000~TN~~~
1006~1~TN~XXXXX~1210~0000.5000~TN~~~
1006~1~TN~XXXXX~1330~0000.1500~TN~~~
1008~1~TN~XXXXX~1340~0000.1000~TN~~~

and the part num list looks like this:

J40_00_1004.00310.0000~
J40_00_1004.00312.0000~
J40_00_1006.00412.0000~
J40_00_1008.00300.0000~

The output needs to look like this:

J40_00_1004.00310.0000~1~TN~XXXXX~1325~0000.2000~TN~~~
J40_00_1004.00312.0000~1~TN~XXXXX~1325~0000.2000~TN~~~
J40_00_1006.00412.0000~1~TN~XXXXX~1210~0000.5000~TN~~~
J40_00_1006.00412.0000~1~TN~XXXXX~1330~0000.1500~TN~~~
J40_00_1008.00300.0000~1~TN~XXXXX~1340~0000.1000~TN~~~

The bom file I have has 579 lines in it and the part_num file has 1749
lines in it.  I am told that this is average case.  When I run the
program on my box using the time command, it takes 3m49.94s.  I would
like to cut this down some as I will have to run this program
frequently.  TIA

------begin code include------

use integer;

($bom_name, $part_num_name) = @ARGV;

open (PART_NUM_FILE, $part_num_name) or die "$0: Cannot open
$part_num_name for read.\n";
foreach (<PART_NUM_FILE>) {
    chomp;
    push @part_num_list, $_;
}
close PART_NUM_FILE;

open (BOM_FILE, $bom_name) or die "$0: Cannot open $bom_name for
read.\n";
 BOM: while (<BOM_FILE>) {
     ($bom_grade, $bom_remainder) = split /~/, $_, 2;
   PART_NUM: foreach $part_num (@part_num_list) {
       ($part_grade) = ($part_num =~ m/.{6}_(\d{4})\./);
       $test = ($bom_grade <=> $part_grade);
       next BOM if ($test == -1);
       next PART_NUM if ($test == 1);
       print $part_num, $bom_remainder;
  }
}  

Doug Alcorn             | How can a moral wrong
Hartsville, SC          | be a legal right?
doug.alcorn@sonoco.com  | It can't.  Read the Bible.

Opinions expressed are not necessarily those of my employer.


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

Date: Thu, 27 Feb 1997 13:15:19 -0500
From: Angus Lai <orange@globalserve.net>
Subject: Oraperl for NCR, any one have a complied copy?
Message-Id: <3315CF36.5669@globalserve.net>

Dear friends,

	I'm looking for complied oraperl which run on NCR 2.03.

	If you have one, or you know where can get it, Please kindly tell me.
Thank you!

	If you know where can get a copy of Oracle Pro C, please also tell me,
Thank You!

-Angus


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

Date: 27 Feb 1997 13:14:13 -0500
From: dras@rasmussen.telco.stratus.com (Dan Rasmussen)
Subject: Re: Problems reading file using <> operator
Message-Id: <jloafoq3ymi.fsf@rasmussen.telco.stratus.com>


mike@stok.co.uk (Mike Stok) wrote:

<snip ... details below>
> You probably want to see if $/ is defined and if so what it contains.  It
> may be that a
> 
>   {
>     local $/ = "\n";
>     ...
>   }
> 
Thanks Mike (also to kevinl@eagles.casc.com for a similar suggestion). 
Yes, this was the problem and the solution (for the moment).  It turns out
that the user of my module was setting $/ to something unexpected.  

Did the user of my module violate any common programming practices when
they changed $/ without changing it back or should I always program defensively 
in perl (i.e. never count on default behavior)?  I have asked the user of my 
module to local $/.  Will this solve the problem or do I inherit his locals?
Should the user of my module declare $/ to be local?  kevinl@eagles.casc.com
suggested I consider using the strict module.  Will this solve all these
strange (to me) global variable problems.

Oh yeah, I should also be checking the result of my open.  Thanks also
to those that pointed this out.

Thanks again.

Dan Rasmussen
dras@sw.stratus.com
danr@an.hp.com


All the Details....

> >I have a perl module that reads from a file using the <> operator. 
> >The exact code is as follows:
> >
> >    open(PFILE, $pFile);
> >    while (<PFILE>)
> >    {
> >	if (/coc/)
> >	{
> >	    ($par, $cocInd) = /(\".*\")(.*)\)/;
> >	}
> >    }
> >    close(PFILE);
> >
> >This code works as expected when called from my test app but I have
> >problems when its used by the app it was designed for.  Specifically,
> >it is reading more than one line at a time when used by the other
> >app.  It behaves more like read() in that it seems to be reading a
> >specific number of byes rather than a line at a time.  
> 
> The <> operator reads records terminated by the contents of the perl
> special vaiarble $/ (or the end of file)  There are a few special cases,
> which are documented in the Special Variables bit of The Gory Details
> chapter in the 2nd edition of Programming Perl or in the perlvar manual
> page that comes with perl 5 (or somewhere in the monster manual page that
> comes with perl 4.xxx) 
> 
> You probably want to see if $/ is defined and if so what it contains.  It
> may be that a
> 
>   {
>     local $/ = "\n";
>     ...
>   }
> 


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

Date: 27 Feb 1997 09:43:35 -0600
From: Jim Anderson <jander@ml.com>
Subject: Re: Regular Expression question
Message-Id: <wkbohd6gspk.fsf@swapsdvlp15.i-did-not-set--mail-host-address--so-shoot-me>

Andrew Johnson <ajohnson@gpu.srv.ualberta.ca> writes:

> Darrel Riekhof wrote:
> > 
> > > With (a*), the contents of the parens is the regex /a*/, so what that
> > > matches is what $1 will be. This can be "", "a", "aa", "aaa", etc.,
> > > depending on the string. If your string was "a", then it will be "a".
> > >
> > > |> Then I tried (a*)* and $1 had ''.
> > >
> > > Yup. $1 can be filled by /a*/, and that can match "".
> > 
> > I still don't understand this part.  /a*/ will match
> > all the a's.  Then the outer star should match 0 or
> > more of the inner, but it chooses to match the empty
> > string.  I don't like this behavior.  Is there a reason
> > for it?
> > 
> 
> the outer star will try to repeat the inner regex, not what
> the inner regex matched, meaning it will try to match zero 
> or more a's again.
> 
> > Still trying to figure out the reason why it doesn't always
> > remember the maximal match......
> > 
> 
> $& does.

O'Reilly's "Mastering Regular Expressions" points out major problem
with using $`, $&, and $'. See p. 282.

-- 
Jim Anderson			jander@ml.com
Consultant-at-large		jander@jander.com
				(212) 449-1598


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

Date: Thu, 27 Feb 1997 16:42:08 GMT
From: avi@tase.co.il (Avi)
Subject: RE: Removing trailing and leading spaces
Message-Id: <33158deb.1601922@news.ibm.net.il>

Well it seems that I'm too novice.
I got 3 answers (2 on E-mail so you can't see them here) and it seems
that non of them is working. Maybe I'm doing something wrong ?
I'm trying the following solution but the variable returned is "0"
(??)

Here is what I'm trying:

$a="    just a string    ";
$a= s/^\s+|\s+$//g;
print("$a");

exit;

Here is what I'm getting:

0

Thats all. A zero. I'm afraid that this zero describes exacly my Perl
skills....

Can you help, I thought it is easy to remove leading and trailing
blanks in a string...

Help...

Thank you.

Avi

BTW: I will appriciate if you e-mail the answer as well to
avi@tase.co.il




On Wed, 26 Feb 1997 17:23:49 GMT, adelton@fi.muni.cz (Honza Pazdziora)
wrote:

>avi@tase.co.il (Avi) writes:
>
>> Hello !
>> 
>> Here is a very novice question.
>
>Yes. We read it already in the subject. Please read the periodic
>posting about Choosing good subject lines.
>
>> I want to remove trailing and leading spaces from a string.
>> 
>> i.e:
>> 
>> "   this is the input   ";
>> 
>> "this is the output";
>
>So that you subject ought to be: Removing trailing and leading spaces.
>
>Possible answer is: s/^\s+|\s+$//g;
>
>Hope this helps.
>
>[CC-ed to avi@tase.co.il]
>
>--
>------------------------------------------------------------------------
> Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
>                   I can take or leave it if I please
>------------------------------------------------------------------------



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

Date: 27 Feb 1997 17:24:59 GMT
From: "SAW Computer Enterprises" <news@sawcomputer.com>
Subject: Using Perl and Sendmail to email a gif or jpeg
Message-Id: <01bc24d3$b3362220$7ba72399@shannon>

Programming Language: Perl 5

Issue:
I need to attach (ideally embed) either a GIF or JPEG file (a company logo)
to an email
 message generated via CGI and mail.  Ideally, the image would be visible
when the
 email was opened in the email program -- e.g.,  Netscape 2.0+Mail  or MS
Mail 3.01.

Current Situation:
The current script sends the customized results of a database query to a
visitor via email.

What I Have Tried:
Reviewed several texts (CGI Programming, Camel, Llama, and Using Perl 5 for
Web
Programming with no success).  I also looked at the HTML version of Using
CGI which
 explained MIME types in Chapter 10 but covered HTTP types.  I am not sure
how to adapt
 these to my needs or if this is the correct solution.  I assume that if I
could generate a header
 for the email then I could specify MIME types but do not know enough about
MAIL or MIME to
 adapt the program.

I am looking for an understanding of this process.  Any help would be
appreciated.
An example script that shows the embedding or attaching of a file via MAIL,
or
An explaination of MIME headers as applied to MAIL, or
a reference book/article, or
a reference URL.

Thanks in advance.

Program Sample:
========================================================
========================================================

#! /usr/local/bin/perl

#### TEST OF ATTACHING A FILE


	$mailprog = '/usr/lib/sendmail'; #Access mail program

	open(MAIL,"|$mailprog -t -n"); # -t = TO Field and -n = no alias

	# Print mail header
	
		print MAIL "MIME-Version: 1.0\n" ;
		print MAIL "Content-Type: multipart/mixed;
boundary=\"------------DE55D235EE4\"\n" ;
		print MAIL "To: webmaster\@sawcomputer.com \n" ;
		print MAIL "From: zip_alert\@newpet.com \n" ;
		print MAIL "Subject: Attachment Test\n\n" ;		


	# Print Subject
	

#		print MAIL "-------------DE55D235EE4\n" ;
		print MAIL "Content-Type: text/plain; charset=us-ascii\n" ;
		print MAIL "Content-Transfer-Encoding: 7bit\n\n" ;


		print MAIL " ----------------------------------\n" ;
		print MAIL " Sample Message Text Would be Here\n\n\n" ;
		print MAIL " ------------------------------------\n" ;



#		print MAIL "--------------DE55D235EE4\n" ;
		print MAIL "Content-Type: text/html; charset=us-ascii\n";
		print MAIL "Content-Transfer-Encoding: 7bit\n" ;
		print MAIL "Content-Disposition: inline; filename=\"index.htm\"\n\n" ;

		print MAIL "<BASE HREF=\"http://www.newpet.com/main/index.htm\">\n";
		print MAIL "<HTML><BODY>" ;
		print MAIL "<IMG SRC=\"vote.gif\" ALT=\"[ Vote Here ! ]\" BORDER=\"0\"
WIDTH=\"120\" HEIGHT=\"100\">\n" ;
		print MAIL "</BODY></HTML>\n" ;

#		print MAIL "--------------DE55D235EE4--\n" ;

	 close (MAIL) ;


-- 
          ______________________________________
                Shannon A. Wenzel, Webmaster
    SAW Computer Enterprises -- Internet Presence Provider
         Small Business and Multilingual Web Pages
   www.sawcomputer.com * info@sawcomputer.com * 609.924.1178


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

Date: 27 Feb 1997 18:22:31 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Using Perl and Sendmail to email a gif or jpeg
Message-Id: <5f4jd7$g1a@fridge-nf0.shore.net>

SAW Computer Enterprises (news@sawcomputer.com) wrote:

: Issue:
: I need to attach (ideally embed) either a GIF or JPEG file (a company logo)
: to an email
[fugly linewrap respectably snipped]

It can be done, yes.  You should probably look into the MIME::*
modules from:

http://www.perl.com/CPAN/modules/by-module/MIME/

--
Nathan V. Patwardhan
nvp@shore.net
"What is your favorite color?
Blue ... I mean yellow ... aieeeee!
	--From the Holy Grail"


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

Date: Thu, 27 Feb 1997 15:55:49 GMT
From: gs@iscon.demon.co.uk (Guy Saner)
Subject: Which database in Perl?
Message-Id: <33158420.54521@news.demon.co.uk>
Keywords: *

I am programming an online database system in Perl. I have found several
modules for accessing databases, but I am unsure about which
is best. My requirements are: 

Between 2000 - 6000 records
Fully searchable under any field.
Ability to write and read records.

If anyone has suggestions about which modules I should use or what
database structure is best, I would be very grateful for any response.

Thanks in advance

Guy Saner


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

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

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

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