[7129] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 754 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 22 12:17:55 1997

Date: Tue, 22 Jul 97 09:00:20 -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           Tue, 22 Jul 1997     Volume: 8 Number: 754

Today's topics:
     Re: 'case' like statements, is it SWITCH? <sfairey@adc.metrica.co.uk>
     Re: //o and backreferences (Mark Nottingham)
     ??- Formatting output for sendmail <lnzadams@slip.net>
     Re: Checking for valid Email... <maelstrom@deathsdoor.com>
     Creating a directory in a Unix1  <byoo@celerity.com>
     Re: Going from Perl 5.001 => v5.004 <rootbeer@teleport.com>
     Re: multicolumn output <rootbeer@teleport.com>
     need perl v-4.035 <amiri@ascinc.com>
     Re: Newbie:  How do you call gzip from perl? (Jeff Stampes)
     Re: process handling <rootbeer@teleport.com>
     Re: Questons (Bill Napier)
     Re: Re-Flowing ASCII Text (Matthew D. Healy)
     Re: regex problem <kvan@diku.dk>
     Running Unix Commands via perl silvern@vetrol.com
     Tie a hash of hashes ? <calle@studentREMOVETOREPLY.adb.gu.se>
     Unix silvern@vetrol.com
     Re: Wanted ! (Nathan Patwardhan)
     win32 passing vars to execute a system command <abailey@cahners.com>
     Re: WWWlib-perl5 module or a better way? <rootbeer@teleport.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 22 Jul 1997 10:25:33 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: Pui Ming WONG <s11976@net2.hkbu.edu.hk>
Subject: Re: 'case' like statements, is it SWITCH?
Message-Id: <33D47C8D.F8E4393E@adc.metrica.co.uk>

Pui Ming WONG wrote:

> I'm quite used to the using the 'case' --->  'esac' statements
> in writing my shell scripts.
> Now i would like such similar statements in perl. I read the
> manual and the 'switch' statments look like it. BUT, the examples
> i saw have 'if's using together with the switch', which i think
> to myself, then why not just use ifs.
> Is 'switch' really the 'case' equivalents . If so, what should it
> be like in perl.
> If not, what other semantics will do the 'case' like branches under
> perl?
> --
>         __
>    / \_/  )             __   Pui Ming WONG (E-mail: pm@hkbu.edu.hk)
>   /      ( -------------  }  System Support Programmer
>  (  =l=ll===============__}  Computing & Telecomm. Services Centre
>   \   _  (                   Hong Kong Baptist University
>    \_/ \__)                  224 Warerloo Road, Hong Kong

  See the FAQ at www.perl.com there is a section on exactly this topic.

Simon



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

Date: Tue, 22 Jul 1997 08:22:13 +1000
From: mnot@pobox.com (Mark Nottingham)
Subject: Re: //o and backreferences
Message-Id: <mnot-ya02408000R2207970822130001@192.168.1.1>

In article <slrn5t6lob.sp6.evenh@ra.pvv.ntnu.no>, evenh@ra.pvv.ntnu.no
(Even Holen) wrote:

>Have you consider another solution to how to solve your problem? First
>of all you uses a lot of grouping here, and secondly you (in the code 
>you have showed us) only use \16...
>
>My suggestion is to try using split, something like 
> split(/[ \t\n"]*/, $line) seems to do the trick. And then rather do
>some extra stuff stripping characters from some of the fields.


Actually, this started life out as a split, but I've seen a marked speed
improvement by using a regex... I do use all of the groups with variables
further down the script.

I think my problem was that I didn't fully understand the doco regarding
/o... and Tom made an excellent suggestion to speed things up by anchoring
the beginning and end of the expression (which I haven't implemented yet,
but I expect to speed things up nicely).


Thanks,

-- 
Mark Nottingham
Melbourne, Australia
mnot@pobox.com


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

Date: Mon, 21 Jul 1997 09:09:45 -0700
From: Lindsay Adams <lnzadams@slip.net>
Subject: ??- Formatting output for sendmail
Message-Id: <33D389C5.3B708329@slip.net>

I have just started programming in Perl, and my project is coming along
nicely, in fact it works perfectly except for one thing. It generates an

output file that is basically a really complicated mail merge. It does
it just fine and I can open the generated file and pass it to sendmail
as the body of an email, but...

What I want to do is have the output file sent as an attachment.

This may be slightly Off subject but if anyone knows how to format the
output to sendmail so that I can send it as an attached file instead of
as the body of the email, I would be most appreciative.

Please reply to my email address as I rarely have time to scour the
newsgroups these days.

thank you much!
Anyone else curious about this answer may also email me and I will
forward all responses to you.

lnzadams@slip.net



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

Date: Tue, 22 Jul 1997 05:01:46 -0600
From: Maelstrom <maelstrom@deathsdoor.com>
Subject: Re: Checking for valid Email...
Message-Id: <869565507.30614@dejanews.com>

In article <5q2oaj$147@fridge-nf0.shore.net>,
  nvp@shore.net (Nathan V. Patwardhan) wrote:
>
> Brandon Wilkins (wilkins@digitaldaze.com) wrote:
>
> : How do I go about checking if a email address is basically valid (In
> : form...)?
>
> You check Dejanews for the answer to this frequently asked question,
> and use the examples you find there to answer your question.

Oh _very_ nice.  I am in a similair position to the original poster and I
just decided to do this.  All I can find is whiney posts telling people
to look in Deja News.  So I checked the old database and found what I
suppose was the original thread being referred to.  So I started reading
that and could find nothing but flames and arguments in varying intensity
on varous subjects.  After 30 minutes I was disconected, having just used
my four hours worth of time. Incidentally I had just come from the FAQ at
www.perl.com and looking at the section for 'How do validate input' I
recieved the following gem of information "See the more specific
questions(numbers, email addresses, etc.) for details". Where?	Is there
some kind of lobotomy you need to have before you can understand Perl
that takes away any ability to communicate helpful information in written
english?

Last time I asked for help here I got about three helpful replies and 7
flames. I guess that's a standard ratio for any comp group so I'm hoping
for similair good results this time.  Does anyone want to tell me how I
can make sure a form input ($RESULTS{'email'}) contains a '@' character
and no spaces?

 Bear in mind that I'm writing this free, for a friend who wont be making
any profit of it either so it's hardly fair to disembowl me for asking a
stupid question.  If anyone would like to help me and thinks they can do
so without causing this newsgroup to implode in a bandwith-wasting
inferno it would be great.  If you would rather flame then feel free but
don't be suprised or offended when you're ignored.

--Maelstrom

"It's comments like these that remind me of the story about a little
mouse. Seems this mouse was always complaining to the other mice. "I want
more!" said the mouse. "And I want it now." This went on day after day,
month after month, year after year. Well, the other mice soon tired of
this routine, and beat the living crap out of that mouse. I think we
could all learn a lesson from that little mouse, Mr. Futz" Bobby Hodad 
___  |\  | \  \  \Whoo look, I have 7 lines in my sig instead of 4.  Now
you have to kill me!

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


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

Date: Mon, 21 Jul 1997 16:08:22 +0900
From: Brandon Yoo <byoo@celerity.com>
Subject: Creating a directory in a Unix1 
Message-Id: <33D30AE5.D2EA1011@celerity.com>

I'm trying to create a directory in Unix with perl:

mkdir ("xx", 777);

This does not give me a "drwxrwxrwx" access. What mode number should I
have to use ?

Thanks in advance.

byoo@hotmail.com



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

Date: Mon, 21 Jul 1997 09:02:14 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Dave Rolfe <rolfe@pt9547.ped.pto.ford.com>
Subject: Re: Going from Perl 5.001 => v5.004
Message-Id: <Pine.GSO.3.96.970721085757.19811N-100000@kelly.teleport.com>

On Mon, 21 Jul 1997, Dave Rolfe wrote: 

> 	I'm currently using Perl v5.001 and I'd like to upgrade to
> v5.004. Does anyone know if there are any gotchas with doing this? 

Yes, and they should all be documented in the release notes and other
documentation which come with the 5.004 source. But it's important to know
that you don't need to discard your working binary to install the new one:
You can (and usually should) keep both. This way, if you find that there
is a problem with a script which you don't have time or ability to fix,
you can simply keep running it under the older version by changing the #!
line. 

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/



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

Date: Mon, 21 Jul 1997 17:27:55 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: hughes@acsu.buffalo.edu
Subject: Re: multicolumn output
Message-Id: <Pine.GSO.3.96.970721172110.6975A-100000@kelly.teleport.com>

On Mon, 21 Jul 1997 hughes@acsu.buffalo.edu wrote:

> How do I force multicolumn output?  In shell there's a simple filter,
> but is there something similar in Perl? 

Sure. You could either open your output stream to the same filter, or you
could re-write that filter in Perl and use that. Your code might use a
piped open, which is documented in perlfunc(1), under open.

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/



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

Date: Mon, 21 Jul 1997 21:45:33 GMT
From: Djavad Amiri <amiri@ascinc.com>
Subject: need perl v-4.035
Message-Id: <33D3D87D.34B6@ascinc.com>

hi Guys!

Is someone here who know where can I find the Perl version 4.035 or
later


Thanks in advance.
/Djavad




||---------------------------------||
|> Alternative System Concepts Inc
|> Djavad Amiri  M.Sc CE 
|>
|> Design Automation Engineer
|>    
|> Phone:  +1 603-437-2234     
|> Fax:    +1 603-437-2722   
|> e-mail:  amiri@ascinc.com
|> website:  www.ascinc.com 
|>                                       
||--------------------------------||


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

Date: 21 Jul 1997 18:32:24 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: Newbie:  How do you call gzip from perl?
Message-Id: <5r09vo$ebn$1@neocad.com>

David Sperling (rika@aloha.net) wrote:
: I'd like to know the code needed to run gzip from a perl script.

Then I suggest reading up on system() and using backticks for
system commands, and learn the differences between them.

Depending on what you want, you'll be doing something like:

system "gzip", "file";

or 

`gzip file`;


--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com


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

Date: Mon, 21 Jul 1997 12:45:56 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: alan@wj.com
Subject: Re: process handling
Message-Id: <Pine.GSO.3.96.970721124137.7819J-100000@kelly.teleport.com>

On 21 Jul 1997, Alan Strassberg wrote:

> 	I want to test if a process has died, and restart it if it has.
> 	A simple "ps ax | grep process" and restart if missing.

Usually, you can find out if your process is alive by sending it signal 0,
like this.

    sub proc_is_alive {
        kill 0, $_[0];
    }

    print "It's still alive\n" if proc_is_alive($some_pid);

(I say 'usually' because this can't be used so simply to test whether
somebody else's processes are alive. But in your case, I think this will
do the job.) 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/



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

Date: 21 Jul 1997 14:57:36 GMT
From: napier@blue.seas.upenn.edu (Bill Napier)
Subject: Re: Questons
Message-Id: <5qvtd0$4m4@netnews.upenn.edu>

Ed Vander Bush (temp.ed.vanderbush@bentley.com) wrote:
>	Also If I wrtie a program in Vi or any editor and save it (Say as
>'hello') then type chmod u+x hello  then type hello all I get is bad
>command If I type perl hello it works What can I do about this?

It's one of 2 things.  
The #! line doesn't point to the perl binary.
 . is not in your path ("./hello"). 

The fixes are
Make the #! line point to perl
Type ./hello

Bill Napier - CSE '98 | e-mail: napier@eniac.seas.upenn.edu
----------------------| WWW:    http://www.seas.upenn.edu/~napier
 This space for rent  | finger for more information (phone, PGP, etc.)
-----------------------------------------------------------------------
/earth is 98% full ... please delete anyone you can.


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

Date: Mon, 21 Jul 1997 14:21:52 -0500
From: Matthew.Healy@yale.edu (Matthew D. Healy)
Subject: Re: Re-Flowing ASCII Text
Message-Id: <Matthew.Healy-2107971421520001@pudding.med.yale.edu>

In article <5qvhtc$3nt$1@nz12.rz.uni-karlsruhe.de>, s_haber@ira.uka.de
(Marc Haber) wrote:

> Hi!
> 
> I would like to have a perl program that takes a text file and
> re-flows it to some other line width while preserving paragraphs.
> Before writing it myself, I'd like to ask if this special kind of
> wheel already has been invented.

You are right that this wheel already exists:

1. There are several text-massaging modules on CPAN that might do what
you want.

2. Many flavors of Unix come with a utility called fmt that does what
you probably want.  However, check docs before you try it, because
there are _also_ versions where fmt is the command to reformat the
hard drives!

3. The O'Reilly book {Unix Power Tools} has a little script that
uses sed/nroff to fake fmt on SysVile versions that lack it.
--------
Matthew.Healy@yale.edu           http://ycmi.med.yale.edu/~healy/
As of 09 Jul 1997, only 905 days until Y2K....
Any person with a phone line can become a town crier with a voice
that resonates farther than it could from any soapbox.
--The US Supreme Court, overturning the Communications Decency Act


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

Date: Tue, 22 Jul 1997 03:26:00 +0200
From: Kvan <kvan@diku.dk>
Subject: Re: regex problem
Message-Id: <Pine.HPP.3.95.970722031949.11834B-100000@dvalin.diku.dk>

On Mon, 21 Jul 1997, Sanjay Malunjkar wrote:

> I am sure others must have run into this problem too.

Depends on how well they understand their regexps :)

> #I am trying escape some characters in a string if that character is not
> #already escaped.
> map {print;~s/([^\\])([$restricted_chars])/$1\\$2/go;print
> ",escaped=$_\n"}
>     qw( sanjay    sajasndasdj$%^@!*()[]{}\/     &;`'\"|*?~<>^()[]{}$);
> 
> When I run this code,it seems to only escapes every second character.

It may seem so, but in fact it is (of course :) doing what you told it to.
You told it to escape every "restricted" character which is _preceded_ by
any non-\ character. Thus, in the string "g%@^" the pattern will match 
"g%" and "@^", returning (correctly) "g\%@\^". What you want is

> map {print;~s/([$restricted_chars])/\\$1/go;print
> ",escaped=$_\n"}

This said, I started learning Perl about 6 hours ago. This was all covered
in Programming Perl (the camel book), which is available on-line at
http://www.ora.com

Maybe it'd also be worth getting a copy of 'Mastering Regular
Expressions'. I know I'm rushing out to buy it.

Regards,
Kvan.

-------Casper Kvan Clausen------ | 'Ah, Warmark, everything that passes
---------<kvan@diku.dk>--------- |  unattempted is impossible.'
'kvan' on pbmserv@eiss.erols.com |   
http://www.diku.dk/students/kvan |        - Lord Mhoram, Son of Variol.      



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

Date: Mon, 21 Jul 1997 22:36:13 -0400
From: silvern@vetrol.com
Subject: Running Unix Commands via perl
Message-Id: <33D41C9D.493D@vetrol.com>

How can i set up a perl script to run forms through to access unix
commands on a remote host?


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

Date: Tue, 22 Jul 1997 09:43:23 +0200
From: Calle Aasman <calle@studentREMOVETOREPLY.adb.gu.se>
Subject: Tie a hash of hashes ?
Message-Id: <33D4649B.20EF@studentREMOVETOREPLY.adb.gu.se>

I would like to put a hash-of-hashes in a DBM, this can't be done, what
are the options?
Is there a way to use tie somehow?

If anyone could help me out on this I would be very happy...

/Calle


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

Date: Mon, 21 Jul 1997 22:46:48 -0400
From: silvern@vetrol.com
Subject: Unix
Message-Id: <33D41F18.4A3F@vetrol.com>

Im looking for a script to run unix commands from a form input.

PLEASE if you know where to find "The most dangerous script on the NET",
PLEASE(I stress) let me know where to find it


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

Date: 21 Jul 1997 21:33:09 GMT
From: nvp@ruby.ora.com (Nathan Patwardhan)
Subject: Re: Wanted !
Message-Id: <5r0kil$4n8$1@amber.ora.com>

Bruce Davidson (allied@pair.com) wrote:
: Any kind perly show me a script for "copy filename1 filename2"

Read the documentation that was included with the File::Copy module
that was included with your Perl distribution.

Hope this helps!

--
Nate Patwardhan
nvp@ora.com
 


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

Date: Mon, 21 Jul 1997 15:52:53 -0400
From: Alan Bailey <abailey@cahners.com>
Subject: win32 passing vars to execute a system command
Message-Id: <33D3BE15.5936@cahners.com>

I was wondering if anyone had any idea on passing variables to running a
n os system command. For example if I want to run a dos dir command, I
can do this by the command: system('dir > c:\data\results.txt'). However
if I want to make the directory or file a variable instead so I could
easily modify I'm not sure how to do. I've looked at the qx command and
the back tick operator. 

Thanks, Alan


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

Date: Mon, 21 Jul 1997 22:03:23 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Mwebernet <mwebernet@aol.com>
Subject: Re: WWWlib-perl5 module or a better way?
Message-Id: <Pine.GSO.3.96.970721215106.24293G-100000@kelly.teleport.com>

On 22 Jul 1997, Mwebernet wrote:

> Do you know how to retrieve web pages on remote systems with perl?  The
> only way I know of is with the libwww module.  Is there another way?

Is there some reason you don't want to use the module? If I knew what you
don't like about it, I might be able to offer a way around those
shortcomings. But the reason you see it suggested so often is because it's
generally the best way.

If you must have another way, here's one. But it may be a little buggy. I
think it may have some undesirable shortcomings of its own. :-)

    $url = q{http://www.perl.com/CPAN/};
    print qq{Could you please retrieve this web page?\n
	$url\n\nThank you. :-)\n};

Seriously, you'll need to tell more about why you don't like a solution
which is already coded, documented, and debugged for you. 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/



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

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

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