[6372] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 994 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 23 02:07:19 1997

Date: Sat, 22 Feb 97 23:00:19 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 22 Feb 1997     Volume: 7 Number: 994

Today's topics:
     Choosing Good Subject Lines [Periodic Posting] (Dean Roehrich)
     Difference between use and require? (Thomas A. Bennedum)
     Re: futur de perl et java-script (Nathan V. Patwardhan)
     Re: futur de perl et java-script (Abigail)
     Re: futur de perl et java-script (Abigail)
     Re: futur de perl et java-script (Dave Thomas)
     Re: futur de perl et java-script (Nathan V. Patwardhan)
     Hash key created by subroutine call? <ricks@sd.znet.com>
     HELP <wildkat@primenet.com>
     Re: HOW TO SPLIT A SIMPLE STRING <billc@tibinc.com>
     Re: localtime() year value broken? (Dave Thomas)
     Re: Looking for Interactive Training CD-ROM for Perl <randy@randysoft.com>
     Perl for Oracle Webserver on NT <jarmfield@span.com.au>
     Re: Perl not working as cgi on local server <calvinn@ix.netcom.com>
     Re: piping data through unix command (Laurel Shimer)
     Re: Question Answer Script (Laurel Shimer)
     Regular Expression - Always seems simple/I always fight (Laurel Shimer)
     Re: Regular Expression - Always seems simple/I always f (Dave Thomas)
     Re: Solution for "Use of uninitialized value"? <ljohnson@isys.ca>
     Re: Solution for "Use of uninitialized value"? <ljohnson@isys.ca>
     Re: status print not printing until output (Dave Thomas)
     Re: The Disappearing DOS box and cmd32.exe <lclapp@intnet.net>
     Re: trunc arrays in subs (Walter Tice USG)
     Variable interpolation with s/// operator (Tom Burton-West)
     Re: Win95 can't always do this! ( Was: Re: Perl on Wind (Nathan V. Patwardhan)
     Windows95 <wildkat@primenet.com>
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: 23 Feb 1997 03:02:18 GMT
From: roehrich@cray.com (Dean Roehrich)
Subject: Choosing Good Subject Lines [Periodic Posting]
Message-Id: <subjects_856666936@cray.com>

NAME
     subject_lines - Choosing Good Subject Lines

DESCRIPTION
     The quality of your article's subject line will dictate the
     quality of the responses you receive.  Choose your subject
     lines wisely.

GOOD SUBJECT LINES
     These subject lines indicate exactly what the article will
     be about and are therefore quality subject lines.

             Putting Commas in a number
             Can I print "~" (tilde) in a format?
             Assigning to an @array and undefined value.
             Printing/calling date/time using unix gmtime
             How to install individual modules like CGI-Lite?
             getpwnam() & Solaris's /etc/shadow file


BAD SUBJECT LINES
     These subject lines say nothing about the content in the
     article.

             Where do I start???!! :-(
             How hard would this job be?
             Can YOU solve this simple problem?!
             Testing.
             04]?
             Simple split question

     These subject lines use negative-flash words.  See the
     section on NEGATIVE-FLASH WORDS.

             Perl newbie with cgi script problem
             Newbie needs help
             Total Beginner Reqs. Help - Please.
             Simple split question
             Can YOU solve this simple problem?!


NO SUBJECT LINE
     Many of the people who give high-quality responses will tend
     to ignore posts which have no subject line at all.

NEGATIVE-FLASH WORDS
     The following words are guaranteed to make large numbers of
     people deliberately ignore your article.  I call these
     negative-flash words.

     beginner  Many people ignore articles which have these words
               in their subject lines.

     emergency News propagation is too slow.  By the time anyone
               gets to read it your condition has probably been
               upgraded to catastrophic.  By the time you get
               their response you'll be dead.  Don't waste other
               people's time with this stuff.

     expert    See guru.

     girl      The people who can give you the highest-quality
               responses probably aren't in the mood for this
               sort of trolling.

     guru      The truth is that it's probably a non-guru
               question.  Most gurus will ignore any article that
               has this word in its subject line.

     help      It sounds like you've given up, or, more likely,
               haven't tried.  Omit this word and the rest of
               your subject line will probably be a high-quality
               attention-getter.

     newbie    See beginner.

     novice    See beginner.

     please    Don't beg.  It's a turn-off.

     question  It's too obvious, and probably answered in the
               manpages or the FAQ.

     sex       See girl.

     simple    This word should tell you something--that you need
               to look at the manpages a little harder.  Don't
               waste other people's time with this stuff.

     stupid    It's just plain derogatory.  People don't like to
               waste their time on things that are stupid.  Hint:
               don't tell them it's stupid, and you will get a
               higher-quality response.

     urgent    See emergency.

     woman     See girl.

NEGATIVE-FLASH EFFECTS
     The following effects, like the above list of negative-flash
     words, are guaranteed to make large numbers of people
     deliberately ignore your article.

     ALL CAPITALS
               Do not use all capital letters in your subject
               line.  Many people find the effect annoying or
               equate it with newcomers.  In either case they
               will ignore the posting.  Hint: There's nothing
               wrong with being a newcomer--we all were at one
               time--just don't advertise it.

     Multiple bangs!!!!!
               Multiple bangs (exclamation points) and multiple
               question marks come across as either over-zealous
               or literarily ignorant, and both effects tend to
               chase away the people who can give the highest-
               quality responses.

BAD, BARELY
     This brings us to the next category of subject lines:  Those
     which are bad but could be good with only a slight
     adjustment.

             HELP: Perl 5.002, SunOS 5.5, gcc 2.7.2, dynamic loading
             HELP: Converting text to binary


GRINCH
     Dean Roehrich,  July 26, 1996.



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

Date: 23 Feb 1997 02:23:05 GMT
From: tab@albany.net (Thomas A. Bennedum)
Subject: Difference between use and require?
Message-Id: <5eo9m9$ksc@lori.albany.net>
Keywords: module library use require

What is the difference?

I've begun writing a multi-module, object oriented API for something at
work, I'm a little confused about how to use these two commands
effectively. To be more specific, I have something like this:

a.pm	utility functions used by other modules and 'client' app
b.pm	needs a.pm, is a base class, uses Msql.pm, used by 'client'
c.pm	needs a.pm, is a subclass of b, used by 'client'
d.pm	more utility functions, used by 'client' app, uses nothing else

What would be the use/require statements at the beginning of each file,
as well as the 'client' app, so that I don't get compile errors/memory
overuse (if this is even an issue)?


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

Date: 23 Feb 1997 02:24:43 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: futur de perl et java-script
Message-Id: <5eo9pb$3qs@fridge-nf0.shore.net>

Abigail (abigail@ny.fnx.com) wrote:

: I've always seen Usenet as being a international medium. Too bad there
: are still arrogant people who think it's a US-only thingy.

I agree that Usenet is international, but I also thought that language-
specific groups existed, like fr, de, etc.

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


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

Date: Sun, 23 Feb 1997 01:57:33 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: futur de perl et java-script
Message-Id: <E619Fx.3vG@nonexistent.com>

On 21 Feb 1997 17:57:30 GMT, Tom Christiansen wrote in comp.lang.perl.misc:

++                            our lex loci hereabouts is that postings
++ be in English rendered

*ploink*

I've always seen Usenet as being a international medium. Too bad there
are still arrogant people who think it's a US-only thingy.



Abigail



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

Date: Sun, 23 Feb 1997 04:40:33 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: futur de perl et java-script
Message-Id: <E61GzL.n0C@nonexistent.com>

On 23 Feb 1997 02:24:43 GMT, Nathan V. Patwardhan wrote in comp.lang.perl.misc:
++ Abigail (abigail@ny.fnx.com) wrote:
++ 
++ : I've always seen Usenet as being a international medium. Too bad there
++ : are still arrogant people who think it's a US-only thingy.
++ 
++ I agree that Usenet is international, but I also thought that language-
++ specific groups existed, like fr, de, etc.
++ 

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.

Are you suggesting we should copy all groups and make language specific
groups with the same subject? Build barriers while the rest of the
world tries to remove them? Why should someone who isn't able to write
good English denied the right to post a question to comp.lang.perl.misc?
There might be someone - oh horror - in this groups who is able to read
French, or whatever language the poster posts in, and give an answer.
I thought that was one of the purposes of this group - sorry for being
mistaken.



Abigail



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

Date: 23 Feb 1997 06:16:48 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: futur de perl et java-script
Message-Id: <slrn5gvo1h.41f.dave@fast.thomases.com>

On 23 Feb 1997 02:24:43 GMT, Nathan V. Patwardhan <nvp@shore.net> wrote:
> Abigail (abigail@ny.fnx.com) wrote:
> 
> : I've always seen Usenet as being a international medium. Too bad there
> : are still arrogant people who think it's a US-only thingy.
> 
> I agree that Usenet is international, but I also thought that language-
> specific groups existed, like fr, de, etc.

and Perl...


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


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

Date: 23 Feb 1997 06:31:54 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: futur de perl et java-script
Message-Id: <5eoo8q$j2h@fridge-nf0.shore.net>

Abigail (abigail@ny.fnx.com) wrote:

: Are you suggesting we should copy all groups and make language specific
: groups with the same subject? 

No.  I thought that a group already existed, somewhere, as I haven't seen
too many non-English postings in clpm - ever.  I presumed.  Shame on me.

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

Never.  When did I say that?  There are plenty of English AND non-English
as-first-language postings that convey information poorly.  There are also
many that convey information well.

: There might be someone - oh horror - in this groups who is able to read
: French, or whatever language the poster posts in, and give an answer.

In the last two weeks, there have been two postings written in French.
Both postings received responses in French.  Obviously, most people don't
have a problem with replying to foreign readers.

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


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

Date: Sat, 22 Feb 1997 21:47:52 -0800
From: Rick Smith <ricks@sd.znet.com>
Subject: Hash key created by subroutine call?
Message-Id: <330FDA08.30D1@sd.znet.com>

I've been running Perl 5.003_(24 through 28) and realize this is
unsupported code.  I'm not looking for support, but just sharing
something I see, and maybe find out that I'm doing something wrong, or
there is something wrong.  I'm running on a Linux 1.2 system.

I also have perl 5.001 and do not see the problem.

#!/usr/local/bin/perl5.00328

# Calling a subroutine with a parameter which is a hash variable
# selected by a non existing key creates that key in the hash

print "Perl Version $]\n";

# An empty subroutine
sub test {
}

# An empty hash
%hash = ();

# If a hash val is first copied to a variable, and that
# variable gets passed to a subroutine, no key gets created.

# However, if a hash val is passed to a subroutine directly,
# and the key is non existent, it gets created.

&test($val = $hash{"No key created here\n"});
&test($hash{"Created this hash key\n"});

# Printing out the keys in the hash
for (keys %hash) {
  print;
}

# I see:
#   Created this hash key

# -- Rick Smith
# ricks@znet.com


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

Date: 22 Feb 1997 23:34:02 -0700
From: ben <wildkat@primenet.com>
Subject: HELP
Message-Id: <330FE31F.13BB@primenet.com>

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
in Perl 5 I believe and I made the changes in C and also saved in C and
need it saved as a Perl CGI.

Thanks


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

Date: Sat, 22 Feb 1997 21:31:53 -0500
From: Bill Cowan <billc@tibinc.com>
To: Aron Griffis <agriffis@calypso.coat.com>
Subject: Re: HOW TO SPLIT A SIMPLE STRING
Message-Id: <330FAC19.1298@tibinc.com>

Aron Griffis 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.
> 
> How about...
> 
> ($s1, $s2, $s3) = (($longstring =~ /(..)(..)(..)/), ($1, $2, $3));
> 
> -Aron
> 
> ]=====================-------------------->
> | Aron Griffis
> | Burlington Coat Factory - Network Group
> | aron.griffis@coat.com
> | http://www.css.tayloru.edu/~agriffis
> ]=====================-------------------->

Two others options are substr and unpack functions:

$s1 = substr($longstring, 0, 2);  # zero-based position
$s2 = substr($longstring, 3, 2);
$s3 = substr($longstring, 5, 2);

OR 

($s1, $s2, $s3) = unpack('A2A2A2', $longstring);

-- Bill
-----------------------------------------------------------------------
Bill Cowan <billc@tibinc.com>    Voice:919-490-0034   Fax:919-490-0143
Tiburon, Inc./3333 Durham-Chapel Hill Blvd Suite E-100/Durham, NC 27707


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

Date: 23 Feb 1997 06:25:26 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: localtime() year value broken?
Message-Id: <slrn5gvohn.41f.dave@fast.thomases.com>

On 14 Feb 1997 14:52:18 GMT, Keith Dreibelbis <dribbs@netspace.org> wrote:
> Hello,
> 
> I was trying to do something with localtime, which is supposed to work in
> the following way:
> 
> ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = 
> 	localtime($seconds_since_jan_1_1970);
> 
> $year += 1900 will give a proper 4 digit year, even past the year 2000.
> However, after 2037 it stops working.  Here's some sample output:

Internally, time is stored in a variable of type time_t - 32 bits. It is the
number of seconds since 00:00:00 GMT, January 1, 1970. This number wraps
around in 2037, hence the results you're seeing.

The forward looking among us are already writing the articles and preparing
the consultancy practices for Y2K II.

Dave


-- 

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


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

Date: Sat, 22 Feb 1997 21:32:21 -0800
From: Randy Hootman <randy@randysoft.com>
Subject: Re: Looking for Interactive Training CD-ROM for Perl
Message-Id: <330FD665.5AE8@randysoft.com>

I don't know if you know that you can get interactive perl training via
your HP intranet. Your training facility should be able to tell you
more. Check out http://www.randysoft.com for more. HP has been doing
perl training with this since last March. OF course, others interested
in this training should check out the above web site also. Many
company's are using this for internal perl training with very positive
results.

Randy Hootman
President
Randysoft


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

Date: Thu, 20 Feb 1997 15:35:47 +0930
From: Jamie Armfield <jarmfield@span.com.au>
Subject: Perl for Oracle Webserver on NT
Message-Id: <330BE9BB.2F6D@span.com.au>

Hi,

Anyone got any advice setting up Perl to work with the Oracle webserver
for NT?

Jamie


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

Date: 23 Feb 1997 05:20:14 GMT
From: "Calvin" <calvinn@ix.netcom.com>
Subject: Re: Perl not working as cgi on local server
Message-Id: <01bc2212$45bcfb60$8fa6bacd@default>

You may first want to include the header in your hello.pl program and try
again.

print "HTTP/1.0 303 See Other\r\n" if $ENV{PERLXS} eq "PerlIS";
print "Content-Type: text/html\n";

( Also make sure when you installed the perl, and it asked you what you
wanted the extension for PERLIS  files to be you left it with '.pl' , the
default value. )

God bless, 
Calvin

Hank LeMieux <hanklem@ibm.net> wrote in article <330F89C7.78DA@ibm.net>...
> Bo,
> 
> This is a simple problem to fix.  If you try to open the script directly
> with Netscape, it WILL open a perl command window and execute the script
> if you will tell Netscape that perl.exe is the helper application for
> .pl files (this is accomplished through the Netscape options menu).
> 
> However, that is not very useful, because you're not going to have
> visitors to your web site see the script execute in a command window. 
> So what you have to do is create an HTML file that calls the script (as
> in <FORM ACTION="cgi-bin/yourscritpt.pl" METHOD="GET">) and have that
> HTML file hosted on a cgi-capable server (which can be local on your
> machine, if you wish).  Then point Netscape to that HTML file and the
> script will be handled as a CGI and execute correctly.
> 
> Good Luck,
> 
> Hank
> 
> Bo Graham wrote:
> > 
> > Hello,
> > 
> > I have set up perl5 on my NT and am using Peer Web Service.  Perl runs
> > fine under cmd.exe but when I put hello.pl in my cgi-bin and type in
> > http://localhost/cgi-bin/hello.pl I get the "file save menu" in
> > netscape.  This happens even though I have set applications/x-perl to
> > run ../perl5/perl.exe
> > 
> > If I type hello.pl at the command line the program runs as expected.
> > 
> > What can I do to make this work?  I feel like I tried everything.
> > 
> > Thanks
> > Bo Graham
> > bgraham@bgraham.com
> > http://bgraham.com
> 
> -- 
> 
> Hank LeMieux
> Freelance Web Design/JavaScript/CGI
> Santa Fe, NM, USA
> (505) 986-8166
> http://members.aol.com/HankWeb/
> 
> 
> 


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

Date: Sat, 22 Feb 1997 19:43:08 -0700
From: autopen@quake.net (Laurel Shimer)
Subject: Re: piping data through unix command
Message-Id: <autopen-2202971943080001@l94.d22.quake.net>

I hope this doesn't sound dumb...

But do you need to span two different processes?

For example I often say something like 

 ....

$FileList = "FileList";

system ("ls -1 hits.*.txt > $FileList");

open (FILES, $FileList) || die("Cannot access $FileList\n");
 ......

But I have a feeling I'm totally missing what you're saying here.

And if you do have to start two processes for reasons of efficiency, could
you use system to start up the other process, and then test for the
output's presence when your done with your current process?

I'm just sort of making this last part up as I go along you understand...

Laurel



In article <330D9BB7.6F9F@mucsun.sps.mot.com>, Klaus Foerster
<klausf@mucsun.sps.mot.com> wrote:

> Hi folks,
> 
> I'd like to send data through a unix command.
> 
> I imagine it like this
> 
> 
> - perl program starts and forks.
>   -> now there are two perl processes 
>   - Process 1 should generate data and send it to a unix command 
>      (e.g. sort, its just an example I know that perl can sort as well)
>   - Process 2 should read the output of this unix command
> 
> So process 1 generates data for a unix program.
> and finishes afterwards.
> process 2 will read all the data and postprocess it.
> 
> Does anyone have a small example?
> 
> Thanx in advance.
> 
> bye
>    
> -- 
> Klaus Foerster

-- 
        The Reader's Corner: Mystery, Romance, Fantasy 
     Short stories, excerpts, themes and resources 
        http://www.autopen.com/index.shtml 
     Subscribe to our free StoryBytes publication
Current Mermaids Issue at http://www.autopen.com/mermaids.shtml


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

Date: Sat, 22 Feb 1997 20:51:10 -0700
From: autopen@quake.net (Laurel Shimer)
Subject: Re: Question Answer Script
Message-Id: <autopen-2202972051100001@l94.d22.quake.net>

If anyone would like to critique this script I wrote for Warren and note
where I've been unsophisticated about my use of indices, array handling
etc.??? I would appreciate it......

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

Warren

I enjoyed this opportunity to practice my skills and built you a rough script.

Thank goodness you had no REGULAR EXPRESSIONS to challenge me.

Below is the script and a sample run.

Hope you have Randal Schwartz's Learning Perl book. You can learn more
about all of these things with that fine tome. And I'm sure the 50 cents
or whatever he gets will help defray his legal defence fund.... Or does he
have to donate all of that to his toadish ex-employer? I forget. Anyway
you should have his book if nothing else and support Randal in his hour of
need -  

>In article <33070038.2DEE@zip.com.au>, womlake@zip.com.au wrote:

> Hello Perl Gurus,
> I'm just starting out in Perl and was after a script that displays a
> questionnaire on screen with say 10 multiple choice questions. After the
> questions are answered, results are displayed eg 7/10 correct as well as
> answers given to the incorrect responses.
> Does anyone know of a freebie I can get hold of, so I can fathom through
> the script and see how to do it?
> Thanks,
> Warren

-------- Here is the script and a sample run. I know there are several
better ways to do this, more clever filling of arrays and less use of
indices, etc.etc. ----

---- Note: The exercise of rounding percentages, reading questions in from
a flat file instead of hard coded into the script, among other things, has
been left to the student! ----

shellx 8% perl5
#There are more sophisticated ways to do this

#Of course you might keep the questions in a flat file and read them in to the a
rray use
#'open'  , 'while <INPUT>'  and 'chomp' to do that

@array_questions = ("Are we having fun yet? ", "Are you an alien?", "
What is the best site on the web?");
@array_answers = ("yes","yes", "The Readers Corner(www.autopen.com): Resource fo
r Mystery, Fantasy and Romance Readers");

#Note I do not predeclare $next, but you could do so to make sure you do not mak
e errors

foreach $question (@array_questions) {
     print "$question\n";
     $student_answers[$next] = <STDIN>;
     #print "your answer was $student_answers{$next}\n";
     $next++;

     }
$num_answers = @student_answers;
print "There are $num_answers answers \n";

$next = 0;#boy I easily got into a lot of trouble when I did not reinitilize thi
s guy

foreach $ans (@student_answers) {
        chomp($ans);
        #print "$ans\n";
        $correct = $array_answers[$next];

        #print "The correct answer is $correct. You answered $ans \n ";

        if ($ans eq $correct ) { print "Wow you got one right!\n";}
        else {
        print "The correct answer is $correct. You answered $ans ";
        print "Boy, you do not know much, do you?\n";
            $error_total++;
            }
        $next++;

     }

print "There were $num_answers questions.\n";
print "You made $error_total mistakes.\n";
$score = (($num_answers - $error_total)/$num_answers) * 100;
print "Your score is $score% \n";
if ($score > 800) { print "Good job\n";}
----------------- Sample Run ----------
Are we having fun yet?
yes
Are you an alien?
yes

What is the best site on the web?
The Readers Corner, That place with all the good stories and stuff
There are 3 answers
Wow you got one right!
Wow you got one right!
The correct answer is The Readers Corner(www.autopen.com): Resource for Mystery,
 Fantasy and Romance Readers. You answered The Readers Corner, That place with a
ll the good stories and stuff Boy, you do not know much, do you?
There were 3 questions.
You made 1 mistakes.
Your score is 66.6666666666667%
shellx 9%

-- 
        The Reader's Corner: Mystery, Romance, Fantasy 
     Short stories, excerpts, themes and resources 
        http://www.autopen.com/index.shtml 
     Subscribe to our free StoryBytes publication
Current Mermaids Issue at http://www.autopen.com/mermaids.shtml


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

Date: Sat, 22 Feb 1997 19:33:06 -0700
From: autopen@quake.net (Laurel Shimer)
Subject: Regular Expression - Always seems simple/I always fight 'em
Message-Id: <autopen-2202971933060001@l94.d22.quake.net>

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

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)

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.


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.

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?

Thank you.

Laurel Shimer

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
METHOD 2
22 is not a digit
METHOD 3
22 is a digit
METHOD 1
string is a digit
METHOD 2
string is not a digit
METHOD 3
string is a digit
shellx 17%

-- 
        The Reader's Corner: Mystery, Romance, Fantasy 
     Short stories, excerpts, themes and resources 
        http://www.autopen.com/index.shtml 
     Subscribe to our free StoryBytes publication
Current Mermaids Issue at http://www.autopen.com/mermaids.shtml


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

Date: 23 Feb 1997 06:37:40 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Regular Expression - Always seems simple/I always fight 'em
Message-Id: <slrn5gvp8l.41f.dave@fast.thomases.com>

On Sat, 22 Feb 1997 19:33:06 -0700, Laurel Shimer <autopen@quake.net> wrote:
> 
> 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"; }

In all three cases your regex isn't matching what you said you wanted.

You said you want to test if a string contains all digits.

Paraphrase that: every character in the string must be a digit.

What does /\d*/ match?  Well, \d matches a digit, and '*' modifies that to
say zero or more. But wait a minute. Anything will match zero or more digits. 

The rest have the same kind of problem.

Go back to the original statement of the problem. All the characters in the
string must be digits. Or, more pedantically, every character between the
first and last must be digits. I guess we should also say that there must be
at least one digit in the string. So

     $checkit =~  /^        # start of the string
                    \d+     # one or more digits (and only these
		   $        # until the end of the string
		  /x;
		  
'*' qualifies in regex can be tricky (and inefficient) things. Always
remember that they imply the preceding item can be optional.

Hope that helps

Dave.

-- 

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


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

Date: 23 Feb 1997 04:30:40 GMT
From: "Lee Johnson" <ljohnson@isys.ca>
Subject: Re: Solution for "Use of uninitialized value"?
Message-Id: <5eoh5g$508@nr1.ottawa.istar.net>



Paul Marquess <pmarquess@bfsec.bt.co.uk> wrote in article 

> Lee Johnson (ljohnson@isys.ca) wrote:
> : I've tried variations on this line including $date_command, by nothing
> : seems to work:
> 
> : $date =`$date+"%y%m%d"`; chop($date);
>           ^
> 
> Try this:
> 
> $date =`date +"%y%m%d"`; chop($date);
> 
> Paul
> 
Duh..."uninitialized value" no kiding...how could I have missed this one? 
I guess that will teach me to stay up 'till 4:00 A.M. working on a script
and then hastilly post something to the newsgroup when I can't figure it
out.  

Somebody please slap the newbie.

Anyway, thanks Paul {:-)


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

Date: 23 Feb 1997 04:31:10 GMT
From: "Lee Johnson" <ljohnson@isys.ca>
Subject: Re: Solution for "Use of uninitialized value"?
Message-Id: <5eoh6e$508@nr1.ottawa.istar.net>



Paul Marquess <pmarquess@bfsec.bt.co.uk> wrote in article 

> Lee Johnson (ljohnson@isys.ca) wrote:
> : I've tried variations on this line including $date_command, by nothing
> : seems to work:
> 
> : $date =`$date+"%y%m%d"`; chop($date);
>           ^
> 
> Try this:
> 
> $date =`date +"%y%m%d"`; chop($date);
> 
> Paul
> 
Duh..."uninitialized value" no kiding...how could I have missed this one? 
I guess that will teach me to stay up 'till 4:00 A.M. working on a script
and then hastilly post something to the newsgroup when I can't figure it
out.  

Somebody please slap the newbie.

Anyway, thanks Paul {:-)


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

Date: 23 Feb 1997 06:08:37 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: status print not printing until output
Message-Id: <slrn5gvni2.41f.dave@fast.thomases.com>

On 20 Feb 1997 22:10:46 GMT, Richard S. Guse <fxrsg@camelot> wrote:
> My program processes a file of usernames, doing checks on each one.  When it
> gets to a username that its checks flag as bad, it prints the useful
> information that I need to fix the problem.  I put a 'status' line in the
> program 'print ".";' to let me know it's dutifully going through the users,
> but it only prints the '.'s directly before it prints something somewhere
> else.  ie: it seems to be compiling wrong.  However, when I add the
> 'use diagnostics;' flag, (I of course use -w always), it works like it
> should.


By default, output is normally buffered (typically on a line by line basis
when interactive.) It is automatically flushed when you read, or when you
print a new line. Thus all your '.'s are sitting in a buffer, and only
getting flushed when you print your full line.

However, all is not lost. The magic variable $| can be set to 1 to enable
autoflushing, generating actual output every time you print:

   $| = 1;
   for my $i (1..5) {
      print ".";
      sleep(1);
    }
       
    print "\n";
       
Nowadays, you can also use the FileHandle module's autoflush method to do
the same thing.

Regards

Dave

-- 

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


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

Date: Sat, 22 Feb 1997 15:40:21 -0800
From: Larry Clapp <lclapp@intnet.net>
To: Gregory Goodwin <gm-goodwin@worldnet.dot.att.dot.net>
Subject: Re: The Disappearing DOS box and cmd32.exe
Message-Id: <330F83E5.5F6E@intnet.net>

[ Curtesy e-mail sent to author cited. ]

Gregory Goodwin wrote:
> 
> I've installed Perl5 on Win95 and associated .pl files with perl.exe.
> The problem though is that the DOS box disappears too fast to read.

Gregory,

I'm too new to Win95 to tell you how to do this mechanically, but
if you start a DOS window, right-click on the title bar and pull down
properties, there's a box labeled CLOSE ON EXIT.  If you arrange to
uncheck it in the window your Perl script runs it, it'll probably stay
open until you close it.

Hope this helps, and reply if I'm wrong!  :)

-- Larry



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

Date: 21 Feb 1997 19:54:42 GMT
From: tice@hunch.zk3.dec.com (Walter Tice USG)
Subject: Re: trunc arrays in subs
Message-Id: <5ekui2$1m0@zk2nws.zko.dec.com>

Hi, I'm an intermediate user.  I'm calling a simple
sub a few times in a row, inside the sub I'm just
getting counts on amount of each type of category
I'm looking for:

sub REPCOM {
    ($NAM,$PDES) = @_;
    open(N,$NDB) || die "Can't open $NDB\n";
    $RE=">$HM/report/open_qars_for_$NAM";
    open(R,$RE) || die "Can't open $RE\n";
    select(R);
    $i=0;
    while (<N>) {
        ($NUM, $COM, $STA, $SEV, $CAT, $DEN, $DFI, $VER, $ABS, $DIFCNT, $DES) = split(" ",$_,13);
        if ($DES !~ /$PDES/) { next;}
            @RCOM[$i]=$COM;
            $i++;
    }
    close(N);

    print "\n";
    for (@RCOM) {
         $count{$_}++;
    }
    for (sort keys %count) {
         $T1=length($_);
         if ($T1 < 8) {
             printf "%2s\t\t%d\n", $_, $count{$_};
         } else {
             printf "%2s\t%d\n", $_, $count{$_};
         }
    }
    write($RE);
    close (R);
} # end sub

#############

The problem is that @RCOM keeps collecting as I go, so by the time I get to my last
sub call it's full of all the date produced by the intervening calls.

Now, wait; I've tried:

@RCOM=();
@#RCOM=-1;

inside and outside of the sub.

I've also tried 'my' and 'local' on @RCOM in the sub.

All to no avail, the only way around so far is to FORK a call for each sub call
which is pretty silly... I'm sure it's something simple, so what is a way out?

Thanks
Walt


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

Date: Sun, 23 Feb 1997 04:01:53 GMT
From: tbw@netcom.com (Tom Burton-West)
Subject: Variable interpolation with s/// operator
Message-Id: <tbwE61F75.LKD@netcom.com>

I am trying to convert some unusual characters using a table in
a config file.  For in the example below, I want to convert from
hex 5F to hex 2D.  For ease of entering the table data I am not
escaping the hex characters (\x5F  \x2D).  Instead, I am constructing
the string representing the escaped characters in the subroutine.

For some reason, the variable interpolation works in the search
part of the s/search/replace/ but not in the replace part.

I would like to know why it doesn't work, and also what I can do
to get the routine to work, other than hard-coding the hex values.

Tom Burton-West
tbw-at-netcom.com
replace the -at- with you @ to send mail

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


$EMDASH_Table="5F   2D";

while (<>){
        chop;
        $Converted=&Convert_Em_Dash($_);

        print "$Converted\n";
}

#==========================================================================
sub Convert_Em_Dash{
        
        local($In_String)=@_;
        ($EM_In,$EM_Out)=split(/[ \t\n]+/,$EMDASH_Table);
        $EM_In="\\x" .$EM_In;           #convert to perl hex notation "\x00"

        $EM_Out="\\x" .$EM_Out;         #convert to perl hex notation "\x00"

#If line below is uncommented it works
#  $EM_Out="\x2d";
 
#Why does it work for $EM_In but not for $EM_Out?
        In_String=~s/$EM_In/$EM_Out/;
#

        $Return=$In_String;
}

-- 
                                             tbw@netcom.com


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

Date: 23 Feb 1997 02:30:52 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Win95 can't always do this! ( Was: Re: Perl on Windows 95)
Message-Id: <5eoa4s$3qs@fridge-nf0.shore.net>

Hank LeMieux (hanklem@ibm.net) wrote:

: 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

>From my experience w/95/NT - not true.

: 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.

I've also noticed that you need to submit form data to a file, then
tell BLAT to mail it.  Ick!

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


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

Date: 22 Feb 1997 23:27:04 -0700
From: ben <wildkat@primenet.com>
Subject: Windows95
Message-Id: <330FE183.5B24@primenet.com>

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
believe.  Can anyone tell me where I can get a Windows95 version with
all the bugs worked out so I won't have to update anything?  Or maybe a
DOS version of Perl?

Thanks for any help.


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

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

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