[6373] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 995 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 23 09:17:20 1997

Date: Sun, 23 Feb 97 06:00:48 -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           Sun, 23 Feb 1997     Volume: 7 Number: 995

Today's topics:
     >> processes (Sven Schwyn)
     Re: Appending to the start of a File? (Guy Saner)
     Re: Camel eats my bits (with contest) (Jeffrey)
     Re: efficiency of many fixed strings vs one regex (Jeffrey)
     Re: futur de perl et java-script (William Denton)
     Re: Getting positions in matched string (Dave Thomas)
     Re: Help in setting up S/// (Jeffrey)
     Re: HELP (Nathan V. Patwardhan)
     Help: DB_File? <q13382@bang.cig.mot.com>
     Re: How to spam - legitimately (Jeffrey)
     Re: limit execution time? (Jeffrey)
     Matching before and after a word? (Alex Kulbe)
     Nested if in compound if statement <tshell@mcs.net>
     Re: pattern matching of sorts (Jeffrey)
     Re: Perl on Windows 95 (Hans Schrader)
     Re: regexp: comma-delimited (csv) with "" inside (Jeffrey)
     Re: Regular Expression - Always seems simple/I always f <dbenhur@egames.com>
     Re: Regular Expression - Always seems simple/I always f (Tad McClellan)
     Re: simple new question! (Jonas Bofjall)
     Re: simple new question! (Jonas Bofjall)
     Re: syntax error (Dave Thomas)
     Re: Uploading cgi script (with perl?) <rjc@overcom.com>
     Re: Win95 can't always do this! ( Was: Re: Perl on Wind (Hans Schrader)
     Re: Windows95 (Nathan V. Patwardhan)
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: 22 Feb 1997 21:00:02 GMT
From: schwyn@amiga.icu.net.ch (Sven Schwyn)
Subject: >> processes
Message-Id: <5enmoi$sb0@news.eunet.ch>

I've just switched from VMS to Unix and therefore am not that familiar with it
yet. I need some quick help for porting a mailserver from DCL to Perl. Here's 
the quiz:

I need some Perl-script that invokes a command as a detached process (the way 
nohup does) and then quits, leaving the detached process running. Later, 
another Perl-script should check, whether this detached process is still 
alive. BUT: This second script does NOT know the pid of the detached process, 
it just knows the owner of the process and the name of the command running. 
(The command mentioned is the mailserver itself and is NOT allowed to be 
running more than once by rule.)

Please reply by mail (as well).
Thanx for any kind of hint or code! I just don't have the time to figure it 
out myself this time ;-) 
                           -gen


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

Date: Sun, 23 Feb 1997 10:16:48 GMT
From: gs@iscon.demon.co.uk (Guy Saner)
Subject: Re: Appending to the start of a File?
Message-Id: <3310186c.2012253@news.demon.co.uk>
Keywords: *

On 22 Feb 1997 13:26:27 GMT, mjtg@cus.cam.ac.uk (M.J.T. Guy) wrote:

>Guy Saner <gs@iscon.demon.co.uk> wrote:
>>
>>I'm trying to get a routine working that opens a text file and appends a line
>>to the start of it. I would also like it to remove the last line from it as
>>well. The number of lines in the file will, therefore, be kept constant.
>>I know I could read it all into an array and then UNSHIFT and POP, but
>>can you think of a better way to do it.
>
>  perl -pi.bak -e 'BEGIN { $x="line to add\n" }; ($x,$_)=($_,$x)' myfile
>
>
>Mike Guy

How does this translate into a script file?
It's for a CGI script. Yes I know you're going to tell me to ask
in a CGI newsgroup, but from my experience, the answers I
get here are better.

Guy Saner


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

Date: 23 Feb 1997 12:17:05 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: jari@iki.fi (Jari =?ISO-8859-1?Q?M=E4kel=E4?=)
Subject: Re: Camel eats my bits (with contest)
Message-Id: <JFRIEDL.97Feb23211705@tubby.nff.ncl.omron.co.jp>


[mail and post]

Jari =?ISO-8859-1?Q?M=E4kel=E4?= <jari@iki.fi> wrote:
|> I was comfortably reading the Blue Camel on a bus on my way to work
|> when I reached the end of page 75. What I saw was devastating and
|> inhumane if not against the Paris Peace Treaty. There was this
|> example:
|> 
|> tr[\200-\377]
|>   [\000-\177];                  # delete 8th bit
|> 
|> I know the people over the pond seem to have a strange hobby of eating
|> the 8th bit but I thought the Camel people are not contaminated by
|> this disease.

What's wrong with stripping bits? It's a common task for me when I'm
transliterating among Japanese encodings, and it's one of many applications
of tr.

The whole world is not ISO8859-1.

	Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> 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: 23 Feb 1997 12:22:28 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: efficiency of many fixed strings vs one regex
Message-Id: <JFRIEDL.97Feb23212228@tubby.nff.ncl.omron.co.jp>


[mail and post]

Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
|> [A complimentary Cc of this posting was sent to Rahul Dhesi
|> <dhesi@22245864.trackme.com>],
|> who wrote in article <5egfan$spn@samba.rahul.net>:
|> >    /\@somedomain\.com/ && &found;
|> >    /\@anotherdomain\.com/ && &found;
|> >    /\@yetanother\.com/ && &found;
|> >    /\@fourthdomain\.com/ && &found;
|> > 
|> > Is it better if I combine them into the following?
|> > 
|> >    /\@(somedomain|anotherdomain|yetanother|fourthdomain)\.com/ && &found;
|> 
|> b) If you want to explain results from these tests, you may need to
|> read the Hip-Owl book by Jeffrey Friedl.

I can't disagree with that advice :-)
[see chapter 5]

|> c) One may expect that the particular regexp above _might_ be improved
|> by merging

What's particular about this is that the whole regex leads with a fixed
string ('@'), so that allows the engine to quickly discount strings that
don't even have a '@', and to start the match only from places in the
string where '@' appears.

Doing
	/\@this|\@that|\@other/
would be slow death, though.

	Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> 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: 23 Feb 1997 04:24:49 -0500
From: buff@interlog.com (William Denton)
Subject: Re: futur de perl et java-script
Message-Id: <5ep2d1$acb@gold.interlog.com>

Abigail <abigail@ny.fnx.com> wrote:

: Like en.comp.lang.perl.misc? I don't know about fr and de, I never
: read there, but nl.* is not for postings in Dutch, but for subjects
: related to the Netherlands. Of course, the language use most will be
: Dutch, but postings in another language are welcome too.

The can.* (Canada) groups get posting in both English and French,
although by far the majority are in English.  Given our language
problems, there are some flames, but mostly everyone gets along.  If
someone posted in Inuktituk, I'd just skip over it.

: Why should someone who isn't able to write good English denied the
: right to post a question to comp.lang.perl.misc?

I agree with you entirely.  I've read articles from people with good
questions who don't speak English very well, and while it is the
lingua franca of the Internet, there's no reason why they can't post
in their native tongue, perhaps including their best attempt at a
translation.  Someone's bound to figure it out and offer up a reply.
If someone doesn't like non-Engish articles, the subject line will
tell them to skip it.

Bill

-- 
-- 
William Denton : Toronto, Ontario, Canada : buff@interlog.com


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

Date: 23 Feb 1997 13:42:36 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Getting positions in matched string
Message-Id: <slrn5h0i5c.568.dave@fast.thomases.com>

On 22 Feb 1997 13:18:21 -0500, Owen Taylor <owt1@cornell.edu> wrote:
> Owen Taylor <owt1@cornell.edu> writes:
> 
> Looks like I left out the punchline of the example. To make
> things a bit clearer:
> 
> > Given a string representing a perl regex with inserted slashes,
> >   
> >     $pat = "((AB|AAB)/)*C/DD?"
> > 
> > and a string to match against,
> > 
> >     $str = "AABABCD"
> 
> The result I wanted was:
> 
>       "AAB/AB/C/D"
> 

OK - firstly, the pattern has to match the input, not the output, so I'm
assuming the pattern you wanted was /(AB|AAB)*CDD?/.

The first thing I tried was

   @flds = m/^(AB|AAB)*(C)(DD?)$/;
   print join('/', @flds);

In an array context, m// returns a list of the sub-matches $1, $2 ...
However, this didn't work, because matching AABABCD, $1 would be set to tha
nlast time the (AB|AAB) expression matched, which was 'AB'.

Instead, I fell back on hackin' it out in two phases using the useful m//g
and \G combinations. I know there's a better way in there somewhere, but its
too early...

   $str = 'AABABCD';

   @flds = ();

   push (@flds, $1) while ($str =~ /\G(AB|AAB)/g);
   if ($str =~ /\G(C)(DD?)/g) {
     push @flds, $1, $2;
     print join('/', @flds), "\n";
   }

Regards

Dave



-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: 23 Feb 1997 11:58:38 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: Help in setting up S///
Message-Id: <JFRIEDL.97Feb23205838@tubby.nff.ncl.omron.co.jp>


[email and post]

Honza Pazdziora <adelton@fi.muni.cz> wrote:
|> > better with:
|> > s/(\s+)\*(\s+)/$1 $2/;
|> 
|> And wouldn't s/^(\s+?)\*(\s+?)/$1 $2/; be more correct and faster?

It would be correct (because the leading ^ is needed), but that aside,
it would be much slower. There is no logical difference between /\s+\*/ and
/\s+?\*/, but in general the non-greedy versions can be much slower. I had
an article in The Perl Journal all about this (Vol 1 No 3 / Autumn 1996).

The trailing /\s+?/ may well be faster than /\s+/, but in this case, you
can just use /\s/ and be done with it! (it's not being replaced -- the
original problem, I believe, only needed to ensure whitespace after the
asterisk. If that's not needed, the trailing (\s+) bit can be removed
altogether.

	Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> 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: 23 Feb 1997 08:26:33 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: HELP
Message-Id: <5eouvp$lsd@fridge-nf0.shore.net>

ben (wildkat@primenet.com) wrote:
: I have a perl file that I was given and have made the necessary change
: to it and would like someone to comfile or make the file a cgi file if I
: sent it to them.  I'm unfamiliar with Perl and need help.  It is written

Sounds like you need to read some docs on CGI programming.  :-)  You might
try a book called _CGI Primer Plus for Windows_ published by Waite Group
Press.  All the examples are written for Windows 95/NT.

--
Nathan V. Patwardhan
nvp@shore.net
"A stitch in time saves nine."


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

Date: 23 Feb 1997 12:27:36 GMT
From: "Mongkol Horburapa" <q13382@bang.cig.mot.com>
Subject: Help: DB_File?
Message-Id: <01bc2183$ce746c20$f01d01d9@mkz>

Is DB_File a buit-in module in Perl?
When I write a Perl program and use DB_File, it can't find the module.
It shows something like this..

Can't locate DB_File.pm in @INC at .....

Thanks for help...



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

Date: 23 Feb 1997 12:34:08 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: chris@ixlabs.com
Subject: Re: How to spam - legitimately
Message-Id: <JFRIEDL.97Feb23213408@tubby.nff.ncl.omron.co.jp>


[mail and post]

Chris Schoenfeld <chris@ixlabs.com> wrote:
|> We have a client who has 18,000 registered web site users.
|> They want the users to have the ability te request certain daily data
|> sent to them via email (they give us the address when they register).

Please do *not* use "spam" in an email sense (with appologies to Hormel)
except in reference to unsolicted email sent out by the lowest scum of the
earth (i.e. bulk unsolicited email). If people *ask* for it, by definition
it is NOT spam.

Every day, _Money_ Magazine sends me email, and I look forward to it because
I asked to be sent their _Money Daily_ (send mail to dailymail@pathfinder.com
to get info yourself -- I recommend it to people that use money in America).
It's certainly not spam.

Remember, spamming is a capitol offense. Just say no.

	Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> 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: 23 Feb 1997 12:38:26 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: Eric Wong <egwong@netcom.com>
Subject: Re: limit execution time?
Message-Id: <JFRIEDL.97Feb23213826@tubby.nff.ncl.omron.co.jp>


[mail and post]

Eric Wong <egwong@netcom.com> wrote:

|> :    Is there any way to limit the execution time of a Perl script
|> : somehow, in case it gets caught in an infinite loop or something.
|
|> How about using fork()?  Something like:
|>   #!/usr/local/bin/perl -w
|>   
|>   if ($child = fork()) {
|>     sleep 60;                 # one minute to finish job
|>     kill 9, $child;
|>   }
|>   else {
|>     # script goes here
|>   }


I don't see any reason to use fork or start another process (unless, of
course, you use sleep or other incandations of the alarm in your script.
Just have $SIG{ALRM} be a routine that kills the process and set your alarm().

I use something like this in my ultra-complex CGIs that might get caught up
in deadlock accessing certain files -- I have the alarm routine write out
a message to a (non-deadlockable) file and then die.

	Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> 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: 23 Feb 1997 12:44:44 GMT
From: s_akulbe@rzw4.rz.uni-ulm.de (Alex Kulbe)
Subject: Matching before and after a word?
Message-Id: <5epe3s$47m$1@news.belwue.de>

Hallo,

1.
I'm trying to match the word before and after a matched word.

@words = (one,two,three,four,five);

@match =~ grep (/three/,@words);

By using "$`" or "$'" I only get the hole substring.

2. How do I match the last word before a "\n"?

Any Ideas?

Regards,

-alex (s_akulbe@rzw4.rz.uni-ulm.de)



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

Date: Sun, 23 Feb 1997 05:51:40 -0600
From: Timothy Shell <tshell@mcs.net>
Subject: Nested if in compound if statement
Message-Id: <33102F4C.1C0D@mcs.net>

I have two segments of code like this that I need to combine:

1.   if (
	($a =~ /\balpha\b/) && ($b =~ /\bbeta\b/) && 
	($c =~ /\bgamma\b/) && ($d =~ /\bdelta\b/) 
	)

2.    	if ($one == 1) {dog >= cat;}
 	elsif ($two == 1) {dog <= cat;}
	else {dog == cat;}

Each segment in my actual program seems to work, but I have had no luck
combining them.

The program should match a record if the four conditions in segment one
are met, and then check to see which condition of segment two must be
met, and then check that condition.

Any help on this would be appreciated,

Thanks,

-- 
Timothy Shell : tshell@mcs.net

Freedom's Nest:  http://www.bomis.com/fn


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

Date: 23 Feb 1997 12:01:03 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: pattern matching of sorts
Message-Id: <JFRIEDL.97Feb23210103@tubby.nff.ncl.omron.co.jp>


[mail & post]

Honza Pazdziora <adelton@fi.muni.cz> wrote:
|> > I need to take a scalar variable and determine how many alphanumeric
|> > characters and non-alphanumeric characters it contains.
|> 
|> Yes, it's rather easy to make an infinite loop and it's hard to debug,
|> if you do not send the source code. But:
|> 
|> $w = 0;
|> while ($data =~ /\w/g) { $w++; }


A simple
	$w = tr/a-zA-Z0-9//
should be much faster (also, remember, \w includes an underscore, which is
not alphanumeric).

	Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> 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: Sun, 23 Feb 97 07:29:06 GMT
From: hans.schrader@geol.uib.no (Hans Schrader)
Subject: Re: Perl on Windows 95
Message-Id: <5eos74$n60$4@toralf.uib.no>

In article <33101ebd.19454071@news.swva.net>, bernie@fantasyfarm.com (Bernie Cosell) wrote:
Follow the instructions on these perl page- I have exactly the same setup 
and all works just fine!
URL="http://hjs.geol.uib.no/Perl/index3.htm"

>Mark Perry <mdperry@cougar.netutah.net> wrote:
>
>} I am setting up a website and I want to use some scripts.  I want to
>} test them to make sure they work befor sending them to the ISP.  I
>} downloaded Perl for Windows 95/NT.  I can see if a script compiles and
>} what its output is in a dos box by typing C:\>perl myscript.pl.  
>} 
>} I would like to also see how it works by loading the page into Netscape
>} locally and then running the script (like it would on a server).  Is
>} this possible.  When I tried clicking on the button that calls the
>} script nothing happened.
>
>Well, depending on how complicated your script is, I check that stuff the
>simple way: do "perl myscript.pl >myscript.html" and then just give
>Netscape the Location "C:\mydir\myscript.html"
>
>  /Bernie\
>-- 
>Bernie Cosell                     Fantasy Farm Fibers
>bernie@fantasyfarm.com            Pearisburg, VA
>    -->  Too many people, too few sheep  <--          

Hans Schrader-Eureka's SySop:
"nglhs@alf.uib.no"--"http://hjs.geol.uib.no/"


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

Date: 23 Feb 1997 12:59:45 GMT
From: jfriedl@tubby.nff.ncl.omron.co.jp (Jeffrey)
To: siffert@shell.wco.com (Curt Siffert)
Subject: Re: regexp: comma-delimited (csv) with "" inside
Message-Id: <JFRIEDL.97Feb23215945@tubby.nff.ncl.omron.co.jp>


[mail and post]

Curt Siffert <siffert@shell.wco.com> wrote:
|> I've been reading Jeffrey's Owl book and there is extensive work 
|> with the CSV example - If you're making a comma-delimited file
|> by exporting from Excel, for instance, it will put quotes around
|> phrases with commas in them.  His example takes that into account
|> so it won't split on those internal commas.  However, what of phrases
|> that also have quotes?
|> 
|> When exporting to CSV:
|> 
|> Earvin "Magic" Johnson     yields    "Earvin ""Magic"" Johnson"
|> 
|> 
|> The code I'm using:
|> 
|>   push(@new, $+) while $text =~ m{
|>       "([^\"\\]*(?:\\.[^\"\\]*)*)",?  # groups the phrase inside the quotes
|>     | ([^,]+),?
|>     | ,
|>   }gx;
|>   push(@new, undef) if substr($text,-1,1) eq ',';
|> 
|> 
|> This unfortunately treats "Earvin ", "Magic", and " Johnson" as three
|> separate fields.

Geez, this is news to me. Sorry 'bout that.

Well after the initial /[^\"\\]*/ has matched, you're at a point where
you get either:
	the closing quote
	a backslash followed by something
  -or, with this new twist-
	two quotes in a row.

So, change:    "([^\"\\]*(?:      \\. [^\"\\]*)*)",?
to:            "([^\"\\]*(?:(?:""|\\.)[^\"\\]*)*)",?
   -------------------------^^^^^^---^-----------------------

and it should work fine.

Jeffrey
----------------------------------------------------------------------------
Jeffrey Friedl <jfriedl@omron.co.jp> 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: Sat, 22 Feb 1997 22:39:42 -0800
From: Devin Ben-Hur <dbenhur@egames.com>
To: Laurel Shimer <autopen@quake.net>
Subject: Re: Regular Expression - Always seems simple/I always fight 'em
Message-Id: <330FE62E.40BA@egames.com>

Laurel Shimer wrote:
> Would you please be so kind as to respond directly to my e-mail address
> (autopen@quake.net)? My server/newsreader connection is unreliable.

Well, sure, but it also goes to the newsgroup (public questions 
get public answers)...

> I have consulted the great LLama and Camel books.
> I have stared at my P.Ref Guide

Well, these *should* have answered your simple regex question,
but if you want more, try Jeffrey Friedl's "Using Regular 
Expressions".

> I just want to test a variable and know if it contains ALL digits or not.
> Gee it seems it ought to be some straightforward use  of \d or \D.

it is, use ^ and $ to anchor expression at beginning and end
of string, \d+ to test for one or more digits:

sub is_all_digits {
    my $str = shift;
    return ($str =~ /^\d+$/); # returns true if string is 1 or more
digits
                              # and nothing else
}

$test = "123";
print "'$test' is all digits\n" if is_all_digits($test);

> $checkit = $number;
> CheckIt();

You need to learn how to write subroutines too, passing function args
as global variables is very bad form.

HTH
--
Devin Ben-Hur      <dbenhur@egames.com>
eGames.com, Inc.   http://www.egames.com/
eMarketing, Inc.   http://www.emarket.com/
"Don't run away. We are your friends."  O-



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

Date: Sat, 22 Feb 1997 23:22:49 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Regular Expression - Always seems simple/I always fight 'em
Message-Id: <97koe5.bo2.ln@localhost>

Laurel Shimer (autopen@quake.net) wrote:
: Would you please be so kind as to respond directly to my e-mail address
: (autopen@quake.net)? My server/newsreader connection is unreliable.

: Thanks

OK.


: Laurel
: ----------
: Ok

: Resources Consulted
: --------------------
: I have consulted the great LLama and Camel books.
: I have stared at my P.Ref Guide

: I have tried all three methods which seem like they should work (see
: sample code below)


They do work (ie. they do what you told them to do).

I think you need to tell them to do something else ;-)


: I don't know what it is about regular expressions and me. I just have to
: see a million that look something like what I need to do before they sink
: into my head.


A little reading about Finite State Automata might help. 

Helped me anyway...



: Here is what I cannot make work

: Problem
: --------

: I just want to test a variable and know if it contains ALL digits or not.
: Gee it seems it ought to be some straightforward use  of \d or \D.


Easy! See below.


: Below are all three versions I tried - which as you can quite clearly see,
: do not give the desired result.

: Can you tell me what it is I just don't understand?
                             ^^^^^^^^^^^^^^^^^^^^^^^

I thinnk you have two basic misunderstandings:

1) use _one_ or more when you want at least one 

2) anchor to beginning and end of the string



: Thank you.


Hope this helps:


: Sample Code
: -------------
: shellx 16% perl5
: $number = "22";
: $string = "string";
: $checkit = $number;
: CheckIt();

: $checkit = $string;
: CheckIt();

: exit(0);

: sub CheckIt {

: print "METHOD 1 \n";
: if (($checkit !~ /\d*/)) { print "$checkit is not a digit \n"}
: else { print "$checkit is a digit\n"; }

: print "METHOD 2 \n";
: if (($checkit =~ /\D*/)) { print "$checkit is not a digit \n"}
: else { print "$checkit is a digit\n"; }

: print "METHOD 3 \n";
: if (!($checkit =~ /\d*/)) { print "$checkit is not a digit \n"}
: else { print "$checkit is a digit\n"; }

: return(0);
: }

: METHOD 1
: 22 is a digit


\d* = zero or more digits

'22' matches two digits

So you kinda lucked in to getting the right answer for this one.


: METHOD 2
: 22 is not a digit


\D* = zero or more non-digits

'22' matches zero non-digits! There is a 'null string' on each side
   of each character.



: METHOD 3
: 22 is a digit

Luck again.


: METHOD 1
: string is a digit


\d* = zero or more digits

It matched zero digits...

: METHOD 2
: string is not a digit
: METHOD 3
: string is a digit


You should also not use global variable to communicate with subroutines.

You should also, also anchor to the beginning and end of the string
being tested, else  'foo22bar' will match _both_ ...


So, I would have done it like this:


--------------
$number = "22";
$string = "string";

CheckIt($number);

CheckIt($string);

#exit(0);           # this is the default exit code anyway, its not needed


sub CheckIt {
   my $item = $_[0];

   if ( $item =~ /^\d+$/ )
      {print '$item' is all digits\n"}
   else
      {print '$item' is NOT all digits\n"}
}
--------------


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 23 Feb 1997 07:35:55 GMT
From: m9418@abc.se (Jonas Bofjall)
Subject: Re: simple new question!
Message-Id: <5eos0r$mqj@oden.abc.se>

Kevin Buhr (buhr@stat.wisc.edu) wrote:
> "y/.../.../" is only useful for character-by-character translations.
> Though it *can* do deletion and squashing, it can't replace single
> characters with longer strings the way you want it to.

OK. Too bad... It doesn't feel good for me to make multiple passes over a
string just to change this. :( I just wanted to get rid of them..

I don't understand your program very much at first sight :) but I downloaded
it to my local disk and will check it out later, to find out if it makes
multiple passes too.

> I think you meant to write "$abc" in the second line instead of "abc":
> if you use "abc", it's interpreted as the *string* "abc", and nonempty
> strings are "true", so you'll always see the output.  However, even
> the "corrected" program:

Oh, sorry about that. I missed that dollarsign when typing in my USEnet
post, I have it in my program. However, when posting here, a program
somewhere sent me a "welcome to comp.lang.perl"-text which was very good.

It mentions the strict mode, which I tried. When using strict mode my
program fills the screen with compiler errors ;) ! I don't understand most
of them, but one is very interesting. It says something like
"bareword TRUE not allowed". I think my problem is here, and that the TRUE
symbol doesn't work like I thought it did.

I've already had some problems about Perl using -1 when I expected 0... :)

> Maybe you could post a complete script that illustrates the problem?

Yes, I will do that if the TRUE symbol stuff isn't the right way to go.
Thanks very much for your help!

--
  // Jonas <job@abc.se> [2:201/262.37]


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

Date: 23 Feb 1997 07:38:45 GMT
From: m9418@abc.se (Jonas Bofjall)
Subject: Re: simple new question!
Message-Id: <5eos65$mqj@oden.abc.se>

Tom Phoenix (rootbeer@teleport.com) wrote:

> The s/// operator will do it, in separate passes. Beware changing a change

but it feels so unomptimized!
Feels like bad coding...

> You've left the dollar sign off of abc in the second line. Also, TRUE is a
> bareword on the first line; generally, that's not a good idea. I'd
> recommend 'TRUE' instead - except that then you might think that 'FALSE'
> was false! Maybe you want to use 0 for false and 1 for true? 

I think you are on to something here! Perl in strict mode complains about
that. Do you think you could explain the TRUE/FALSE logic here, because I
have a feeling that I and Perl disagree on how it should be ;).
Isn't 0 false and 1 true?

--
  // Jonas <job@abc.se> [2:201/262.37]


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

Date: 23 Feb 1997 13:53:36 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: syntax error
Message-Id: <slrn5h0iq2.568.dave@fast.thomases.com>

On 22 Feb 1997 20:09:16 GMT, Maksym Panfilov <mpanfilo@newstand.syr.edu> wrote:


> ---------------------------------------
> open(GRADES,$grades_file_) || die;
> while(<GRADES>) {
>         ($id, $quiz, $score) = split(/\ /);
>         $j = 0;
>         while ($j < $count) {
>                 if ($netid[$j] eq $id) { last; }
>                 $j++;
>         }
>         $grade[$j][$quiz] = $score;
> }
> close GRADES;
> --------------------------------------

What version of Perl are you using. This fragment compiles fine with 5.003.
However, are the values in $quiz numeric? Of not, you'll have to use an
associative array rather than an array  "$grade[$j]{$quiz}".

Regards

Dave

-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: Sun, 23 Feb 1997 04:36:15 -0500
From: Ray Cromwell <rjc@overcom.com>
To: Raul Almquist <strider@shadowmac.org>
Subject: Re: Uploading cgi script (with perl?)
Message-Id: <33100F8F.6EE@overcom.com>

Raul Almquist wrote:

>   Unfortunately, I have come to the determinization that none of the
> modules that scripts like yours, really deals with all the aspects of file
> uploading...  uploading requires more than any existing pm's provide, as
> they only provide a very limited and primitive upload functionality...
> sad to say.

   Can you be more specific as to what is really needed that is lacking,
in say, CGI.pm?

use CGI;
$query = new CGI;
$filehandle = $query->param('upload_name');
open(OUTPUT, ">$filehandle") || debug("Couldn't open $filehandle for
writing: $!");
print OUTPUT <$filehandle>;
close(OUTPUT);

With CGI.pm, the only thing lacking is helper functions to auto-save
a file for you, and functions to escape/strip dangerous filename
characters.

If you're doing CGI programming in perl, you should be using perl5 and
CGI.pm or LWP, period.


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

Date: Sun, 23 Feb 97 07:31:37 GMT
From: hans.schrader@geol.uib.no (Hans Schrader)
Subject: Re: Win95 can't always do this! ( Was: Re: Perl on Windows 95)
Message-Id: <5eosbr$n60$5@toralf.uib.no>

In article <330F8820.6F48@ibm.net>, hanklem@ibm.net wrote:
Maybe I misunderstood- BUT I can do this. You can have a look yourself at 
this URL="http://hjs.geol.uib.no/TechCorner/index.html-ssi" look for the 
BLAT_BLAH_BLAH entry!

>The subject is whether you can test your perl/CGI scripts by setting up
>a local server on Win95.
>
>Mostly you can, and I do.  However, there is one key catch.  I'm not
>familiar with the technicals, but apparently Win95 is unable to open a
>new port from your local server when your browser executes a CGI script
>that, for instance, sends email via BLAT.  So, for example, I have a
>perl script that uses BLAT to email the results of a form submission. 
>You can get this script to work from the command line, BLAT included. 
>But if you go into your browser and access an HTML page on your local
>server, and that page calls the cgi script, BLAT will fail to open a
>port to send the mail.
>
>So keep this in mind.  It will save you hours of debugfrustration.
>
>Hank
>-- 
>
>Hank LeMieux
>Freelance Web Design/JavaScript/CGI
>Santa Fe, NM, USA
>(505) 986-8166
>http://members.aol.com/HankWeb/
>
>

Hans Schrader-Eureka's SySop:
"nglhs@alf.uib.no"--"http://hjs.geol.uib.no/"


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

Date: 23 Feb 1997 08:24:49 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Windows95
Message-Id: <5eoush$lsd@fridge-nf0.shore.net>

ben (wildkat@primenet.com) wrote:
: Having trouble installing Perl for Windows 95.  It tells me I need to
: update my register.  What is the regitsry?  Has to do with command.com I

Your registry is how Windows knows how to execute programs and such.
The reason you can run .EXE files is because your registry has an entry
like (off the top of my head): .EXE /c %s %s, which tells windows to 
call x program to run any instance of a program with a .EXE extension.

You'll have to do the same with Perl.  You should run regedt32.exe in
Windows95, and search for the Scripts directory (off the top of my head -
again - I'm not in front of my Windows machine right now).  Once you've
found the directory, create a new extension, .pl, and associate it like:
 .pl %s with c:\perl\perl.exe (or whatever the path for Perl is).

Honestly, the Windows reg-edit interface is really good, and it shouldn't
be too tough for you to make this addition to your system.  If you make a 
mistake, just don't save the changes, and try again.

If you want exact details of the location of your scripts directory,
please drop me some e-mail and I'll check my Windows machine.

--
Nathan V. Patwardhan
nvp@shore.net
"A stitch in time saves nine."


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

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 V7 Issue 995
*************************************

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