[7028] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 653 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 24 13:17:11 1997

Date: Tue, 24 Jun 97 10:00:30 -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, 24 Jun 1997     Volume: 8 Number: 653

Today's topics:
     Re: can one check external ports ? <esupu@warwick.ac.uk>
     Re: Checking a string for "@' and "." <chriswareham@dial.pipex.com>
     Checking an entered date <deanh@nospam.mail>
     Re: Checking an entered date <merlyn@stonehenge.com>
     Concurrency in Perl? <elliot@wellspring.com>
     Re: DB_File Locking (open) (Tim  Smith)
     Re: distributed objects in perl <merlyn@stonehenge.com>
     Re: Filehandles & data input --- A few Questions <friedman@uci.edu>
     Re: Generating random numbers fast (Steve Lamb)
     Re: get end of string (easy question) <flg@vhojd.skovde.se>
     Re: Get own IP (Magnus Bodin)
     Re: good online Perl Tutorial? <mattias.lonnqvist@uidesign.se>
     Re: Help with script (Clay Irving)
     Re: interprets as shell instead of perl (Bob Wilkinson)
     Module in perl ????? <e.lestrat@cadcentre.fr>
     NDBM on Win32 in Perl (Todd Hivnor)
     Re: Newbie : FAQ location ?? ...can u solve my problem? (Steve Lamb)
     Re: None <sfairey@adc.metrica.co.uk>
     Re: Perl (Binary) <rootbeer@teleport.com>
     perl and perl5 <esupu@warwick.ac.uk>
     Re: Perl Mail Interface smith.eric@b2.wpafb.af.mil
     Re: Q: an alternative to this use of "goto"? (Craig Scrivner)
     Re: Q: an alternative to this use of "goto"? (Lloyd Zusman)
     Re: Q: an alternative to this use of "goto"? <merlyn@stonehenge.com>
     Re: Q: an alternative to this use of "goto"? <merlyn@stonehenge.com>
     Re: Q: an alternative to this use of "goto"? <merlyn@stonehenge.com>
     Re: Random access files in PERL (Eric Bohlman)
     Re: reading a data file? (Clay Irving)
     Re: regex question (Eric Bohlman)
     Re: Script to verify email addresses? <merlyn@stonehenge.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 23 Jun 1997 02:31:38 +0100
From: mike mah <esupu@warwick.ac.uk>
To: tony@toners.com
Subject: Re: can one check external ports ?
Message-Id: <Pine.SOL.3.95.970623022912.1829A-100000@figroll>

On Thu, 19 Jun 1997, Tony Reeves wrote:

> 
> I have an assignment to check all our ip addresses for web servers. 
> is there an easy way to use perl to go out and check known IP addresses
> for ports 80, 8080, 81 and etc?
> 
	If you are writing cgi script, you can use 
	$ENV{'SERVER_PORT'}
	to check the port.

	Hope this helps.
	Let's strike for exellent.


Yours sincerely,
mike mah



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

Date: 24 Jun 1997 08:36:23 GMT
From: "Chris Wareham" <chriswareham@dial.pipex.com>
Subject: Re: Checking a string for "@' and "."
Message-Id: <01bc807a$0f771880$038182c1@TI_SGML_SUNDOG>



Dean Hollister <deanh@nospam.mail> wrote in article
<33ADE275.395B@nospam.mail>...
> Hello,
> 
> Can anyone point me to the required code to check whether or not a
> string has BOTH the "@" and "." characters in it?
> 
> Using Perl 5.
> 
> Regards,
> 
> d.
> 
> 
> -- 
> +--------------------------------------------------------+
> | Dean Hollister,           | deanh@iinet.net.au         |
> | Region Co-Ordinator,      | dean@odyssey.apana.org.au* |
> | APANA,                    |                            |
> | Western Australia.        | *finger A/C for DISCLAIMER | 
> +--------------------------------------------------------+
> ST:VOY Kess: "I wish people would stop talking to me as if
>               I'm still a child! I'm three years old now!"

Hi Dean

The regexp you want is;

if ($string_to_search =~ /[\@\.].*[\@\.]/g) {
    print "Found a match\n";
}

Hope this helps!

Best regards

Chris

chriswareham@dial.pipex.com
Product Application, Development and Research
Technical Indexes Ltd



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

Date: Mon, 23 Jun 1997 10:46:13 +0800
From: Dean Hollister <deanh@nospam.mail>
Subject: Checking an entered date
Message-Id: <33ADE375.150B@nospam.mail>

Hello,

Can anyone point me to the relevant code to parse the information
supplied in a date (ie, date of birth) and check its validity, then
check if the person is over 18?

Would it be easier to have the form parse the information, ie, enter the
day, month and year in seperate boxes?

Using Perl 5.

Regards,

d.

-- 
+--------------------------------------------------------+
| Dean Hollister,           | deanh@iinet.net.au         |
| Region Co-Ordinator,      | dean@odyssey.apana.org.au* |
| APANA,                    |                            |
| Western Australia.        | *finger A/C for DISCLAIMER | 
+--------------------------------------------------------+
ST:VOY Kess: "I wish people would stop talking to me as if
              I'm still a child! I'm three years old now!"


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

Date: 22 Jun 1997 23:27:02 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: deanh@iinet.net.au
Subject: Re: Checking an entered date
Message-Id: <8cvi35rg09.fsf@gadget.cscaper.com>

>>>>> "Dean" == Dean Hollister <deanh@nospam.mail> writes:

Dean> Can anyone point me to the relevant code to parse the
Dean> information supplied in a date (ie, date of birth) and check its
Dean> validity, then check if the person is over 18?

Dean> Would it be easier to have the form parse the information, ie,
Dean> enter the day, month and year in seperate boxes?

Just how hard did you look for the answer?  The CPAN module list
(nicely indexed by Jon Orwant at http://www.perl.com/CPAN/CPAN.html)
contains the word "Date" something like 30 times.  If one of those
doesn't solve your problem, I'll give you my next month's salary.

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

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


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

Date: Mon, 23 Jun 1997 22:28:45 -0400
From: Elliot Mednick <elliot@wellspring.com>
Subject: Concurrency in Perl?
Message-Id: <33AF30DD.75B2@wellspring.com>

Hello,
I would like to be able to have a script (program, whatever) in which
there are multiple code streams running concurrently (conceptually),
each with its own separate stack, but sharing a common address space.  I
also need a way to synchronize them with wait/notify primitives or the
like.

I'm not sure what name to associate with this, because terms like
"threads", "processes", and "multitasking" have changed meaning and
become ambiguous.  

I don't need POSIX threads.  Only a way to seperate Perl's internal
stacks into seperate "processes".  But threads *may* gice me what I
need.

There used to be a way to compile Perl with "MULTIPLICITY".  That would
give me part of what I need, but that hasn't worked in a while, but I'm
a little behind an my most recent version of Perl is 5.002.

Thanks in advance!!
-- 
Elliot Mednick                                      P.O. Box 150
Wellspring Solutions, Inc.                          Sutton, MA.  01590
                                                    (508) 865-7271
<elliot@wellspring.com>                             (508) 865-1113 [fax]


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

Date: 24 Jun 1997 04:59:13 -0700
From: trs@azstarnet.com (Tim  Smith)
Subject: Re: DB_File Locking (open)
Message-Id: <5oocqh$bm0@web.azstarnet.com>

In article <M6+RsD.pOC@csh-newsserver.csh.rit.edu>,
Brian Mathis <gentry@csh.rit.edu> wrote:
>	open(DBFILE, "+<&=$fd");
>What Im confused about is the '=' sign in the open.

Read the perlfunc(1) man page entry for open again.  There's an entry
that says:

    qq(If you specify "<&=N", where N is a number, then Perl will ...)

Enjoy,

Tim



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

Date: 24 Jun 1997 08:10:30 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: German Cancio Melia <German.CancioMelia@cern.ch>
Subject: Re: distributed objects in perl
Message-Id: <8csoy882ah.fsf@gadget.cscaper.com>

>>>>> "German" == German Cancio Melia <German.CancioMelia@cern.ch> writes:

German> PS. I forgot to say that I cannot use Perl/Tk since the system has to
German> be 100% reliable.

There's no such thing.  What do you *really* mean?

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

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


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

Date: 23 Jun 1997 07:29:49 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: Filehandles & data input --- A few Questions
Message-Id: <5ol8ld$fcb@news.service.uci.edu>

[mailed, posted]

In article <33aeff93.98307271@news.mindspring.com>,  <topaz56@one.net> wrote:

<In all of the perl texts, it seems that the authors tend to gloss over
<file input unless it comes in on STDIN or as an environmental
<variable.

Really?  What texts did you look at? All of the ones I've seen have
extensive sections on file input, output, locking, etc.  Even
(especially) the >free< perl faq has a whole section devoted tothis
topic.

<Now, it seems pretty simple to take say the input from a textarea
<or a text file in general & dump it into an array, like below...
<
<open (DATAFILE, "$data") || die "Can't open $data\n";	 
<@data = <DATAFILE>;

[snip]

<undef $/; 
<$data =(<DATA>, datafile.txt);

Note that in the first (valid) code snippet you offered, the file is
opened before it is read.  Your second (invalid) snippet, however,
doesn't open anything. :-(

What you want is this:

my $file = '/path/to/datafile';
open DATA, $file or die "Can't open file $file: $!";
undef $/;
my $data = <DATA>;
close DATA or die "Can't close file $file: $!";

You might also like to go the object oriented route, especially if
you're going to be passing filehandles around to different functions:

use IO::File;
my $file = '/path/to/datafile';
my $fh   = new IO::File $file, 'r';
die "Can't open file $file: $!" unless defined $fh;
undef $/;
my $data = <$fh>;

Hope this helps.  (And do check out the faq section on files.  It's
quite thorough, despite what you say.)
-- 
Eric D. Friedman
friedman@uci.edu


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

Date: 24 Jun 1997 07:48:37 GMT
From: morpheus@calweb.com (Steve Lamb)
Subject: Re: Generating random numbers fast
Message-Id: <slrn5quuul.5eh.morpheus@web2.calweb.com>

MoNoLiTH+@CMU.EDU in <<snfeIJS00iWS0401U0@andrew.cmu.edu>> wrote:
>I want to find a quick way to generate decent random numbers fast.

Math:TruleyRandom

    On a 486DX4-100 it can seed the random generator in two seconds.  Not
sure what it'll do on a faster machine.


-- 
             Steve C. Lamb             | Opinions expressed by me are not my
    http://www.calweb.com/~morpheus    | employer's.  They hired me for my
                                       | skills and labor, not my opinions!
---------------------------------------+-------------------------------------


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

Date: 23 Jun 97 06:25:08 GMT
From: "Fredrik Lindberg" <flg@vhojd.skovde.se>
Subject: Re: get end of string (easy question)
Message-Id: <01bc7f9e$35e52020$e20f10c2@odens.di.vhojd.skovde.se>

Wesley Miaw <wesley@woais.com> wrote in article
<33ADFF75.6F6E@woais.com>...
> Using $IMAGE =~ /\/(.*?)$/i doesn't work because .* is greedy and
> matches the '/' character. It matches everything, as much as it can.

Yes .* is greedy but .*? is not. The problem with the original
posters regex was that it allowed the / to match at the beginning
of the string. 

That is m</(.*?)$> (i changed the delimiters to allow for more clearer
regex) says: match a /, followed by the minimum number of characters
until we reach the end.

Now for a URL like this:  http://www.women.com/guide/guide/gifs/nav.7.gif

It will match the first / right after http:, and then successfully slurp
up all characters until the end (greedy or not).

What we want is to actually use a greedy match until we find the
last /, and then capture the remaining string.

$IMAGE =~ m<.*/(.*)$>

This will slurp up the whole string, batcktrack to the last /
and the slurp up the rest of the string, capturing the data.

Hope this helps

/Fredrik


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

Date: Mon, 23 Jun 1997 06:08:46 GMT
From: Magnus.Bodin@tychonides.se (Magnus Bodin)
Subject: Re: Get own IP
Message-Id: <33b01297.346760665@news1.telenordia.se>

Alex `Taker` Pircher <pircher@informatik.tu-muenchen.de> wrote:
>How do I get my own IP?
>
>#$ip_number=pack("C4", 127, 0, 0, 1);
>#($name, $aliases, $type, $len, $addr) = gethostbyaddr ($ip_number, 2);
>
>that only give's me "localhost"
>
>THX 4 Help,
> Taker

arp -a

gives the ipconfig in unix as well as win95/NT

cheers

magnus


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

Date: Mon, 23 Jun 1997 14:10:18 +0200
From: Mattias Lvnnqvist <mattias.lonnqvist@uidesign.se>
Subject: Re: good online Perl Tutorial?
Message-Id: <33AE67AA.7934@uidesign.se>

Kenneth Kin Lum wrote:
> 
> Does some one know of a good online Perl Tutorial?

Try this:

http://agora.leeds.ac.uk/Perl/start.html

/Mattias


-- 
This was a message from Mattias Lonnqvist * mailto:malo@uidesign.se
http://www.uidesign.se/~malo * phone +46 - (0)13- 37 12 05
Unsolicited commercial email is subject to an archival fee of $400.
See <http://www.uidesign.se/~malo/mail.html> for more info.


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

Date: 24 Jun 1997 08:37:26 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Help with script
Message-Id: <5oof26$4vi@panix.com>

In <edb105.1.00156ECB@psu.edu> edb105@psu.edu (Eric Blessner) writes:

>Hello, I dont really know alot about perl but I do need help with a script.  
>Someone wrote this script for me and Im almost there but I would really 
>appreciate any help.

>Here is what I have.   The script pulls the data out of a flat file and loop 
>through until finished.   My problem is I dont know how to do a if else 
>statement.   

Like this:

  if ($var eq "yesterday") {
    print "too late!\n";
  } elsif ($var eq "next week") {
    print "too soon!\n";
  } else {
    print "Ahhh. Just right...\n";
  }
  
>I want the first if to run and just output the data.  If it does 
>not qualify I want it to run the next senerio.   Everytime I try it with the 
>if and else I get a server area.  Please help

What was the error? You had a "server" error -- Does this mean you were
running the Perl program on something like a Web server? If so, did the
program run without an error from the command line?   

-- 
Clay Irving                                        See the happy moron,
clay@panix.com                                     He doesn't give a damn,
http://www.panix.com/~clay                         I wish I were a moron,
                                                   My God! Perhaps I am!


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

Date: Mon, 23 Jun 1997 13:32:12 +0100
From: b.wilkinson@pindar.co.uk (Bob Wilkinson)
Subject: Re: interprets as shell instead of perl
Message-Id: <b.wilkinson-2306971332120001@ip57-york.pindar.co.uk>

In article <19970620205300.QAA13522@ladder01.news.aol.com>,
atarum76@aol.com (AtaruM76) wrote:

> I am having a problem, I have the following test cgi:
> 
> #!/usr/bin/perl
> 
> print "this is a test"
> exit (0);
> 
> and what is happening is that the os keeps trying to interpret it as a 
> shell script, and doesn't call perl!
> 
> That is the correct location of the perl program, I can't figure this out.
> Something must have broken when I wasn't looking.
> I am using redhat linux 3.0.3, and perl 5.
> Maybe this is a unix administration problem, but if someone knows, what
> is going on, please let me know. I do have root access, but I did not
> originally set this up.
> 
> thanks
> 
> Chris Buchholz
> chrisb@issoln.com

Hello,

      Typing 

which perl

and

/usr/bin/perl -e 'print "this is a test";'

at your prompt may give some clues.

Bob

-- 
Do what thou wilt shall be the whole of the law.


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

Date: Tue, 24 Jun 1997 18:03:32 +0200
From: Eric Le Strat <e.lestrat@cadcentre.fr>
Subject: Module in perl ?????
Message-Id: <33AFEFD4.383C@cadcentre.fr>

Hi !

i'm use perl since 3 days and i want make some module.
How make?


eric
e.lestrat@cadcentre.fr


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

Date: 24 Jun 1997 11:24:36 -0400
From: hivnor@shore.net (Todd Hivnor)
Subject: NDBM on Win32 in Perl
Message-Id: <5ooork$4qv@shell2.shore.net>

I'm trying to access an NDBM file under Windows NT from Perl (5.004_01). 
(So I can play with Netscape Server's User database)
But NDBM doesn't seem to be supported under Win32.
The NDBM install-time test was skipped, 
   and TIEHASH isn't found in the NDBM_File module.
Am I missing something ? 
There really is no NDBM support under Win32?


Todd Hivnor <hivnor at albany dot net>


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

Date: 24 Jun 1997 09:27:32 GMT
From: morpheus@calweb.com (Steve Lamb)
Subject: Re: Newbie : FAQ location ?? ...can u solve my problem?
Message-Id: <slrn5qv4o4.p89.morpheus@web2.calweb.com>

ajohnson@gpu.srv.ualberta.ca in <<339E2EDA.32216F11@gpu.srv.ualberta.ca>> wrote:
>you heard correctly...
>FAQ's can be found online at
>http://www.perl.com/perl/info/documentation.html
>if you don't already have them with your perl distribution.

Forbidden

You don't have permission to access /perl/info/documentation.html on this
server.

    You were saying?  Will the real perl faq please rise?

-- 
             Steve C. Lamb             | Opinions expressed by me are not my
    http://www.calweb.com/~morpheus    | employer's.  They hired me for my
                                       | skills and labor, not my opinions!
---------------------------------------+-------------------------------------


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

Date: Tue, 24 Jun 1997 11:39:00 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: William C Ralph <ralphwc@mail.auburn.edu>
Subject: Re: None
Message-Id: <33AFA3C4.1CFB@adc.metrica.co.uk>

William C Ralph wrote:
> 
> As suggested, I found the following subroutine in the faq for
> case-matching substitution:
> 
>    sub preserve_case($$)

> FUNCTION SNIPPED <

> Which is invoked by using:
>         $output =~ s/($find)/preserve_case($1, "$replace")/gie;

Have you tried adding a word boundary check?
i.e.
         $output =~ s/\b($find)\b/preserve_case($1, "$replace")/gie;

Simon


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

Date: Tue, 24 Jun 1997 09:56:51 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Marc Boumedine <mboumedi@anubis.ccm.itesm.mx>
Subject: Re: Perl (Binary)
Message-Id: <Pine.GSO.3.96.970624095506.3042G-100000@kelly.teleport.com>

On Mon, 23 Jun 1997, Marc Boumedine wrote:

> I would like to know if it exists binary version of Perlk for the SunOs?

(I think you mean Perl.) Yes, there is. Everybody who uses SunOS has one. 
You can get your own by compiling it from the 5.004 source, available from
your nearby CPAN site. When you compile it yourself, you can be sure that
it's set up properly for your machine's configuration. Hope this helps! 

    http://www.perl.com/CPAN/

-- 
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: Tue, 24 Jun 1997 03:41:44 +0100
From: mike mah <esupu@warwick.ac.uk>
Subject: perl and perl5
Message-Id: <Pine.SOL.3.95.970624033916.8330F-100000@crocus>

hi perl gurus,
	I wonder whether there is different between
	#!/usr/local/bin/perl   and
	#!/usr/local/bin/perl5  
	will the same version of perl call?


--
Yours sincerely,
Mike Mah
First year computer systems engineering student.
University of Warwick
http://www.warwick.ac.uk/~esupu
 



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

Date: Tue, 24 Jun 1997 09:13:44 -0600
From: smith.eric@b2.wpafb.af.mil
Subject: Re: Perl Mail Interface
Message-Id: <867160713.15862@dejanews.com>

In article <33A96F78.A51@southernenergy.com>,
  michael.east@southernenergy.com wrote:
>
> Does anyone know of a Perl script that will interface form mail with
> Microsoft Exchange on a NT server???
>
> Mike
>
> michael.east@southernenergy.com
Per your posting on the newsgroup.

I found a very flexible and powerful script for SMTP mail on NT that does
not require an external mail program.  The script I used is Eric Weinke's
"Form2Mail" http://www.liquidsilver.com/scripts.  It uses a "sendmail"
subroutine to send SMTP.  It should require little or no modification (In
my case, I had to comment-out a couple of statements that put ther
sender's "realname" in front of the "from" address).

I used this script, with minor modifications, with IIS 3.0 on NT4.0.  The
mail was sent to MS Exchange SMTP Host (In our case, since the Exchange
server was behind a firewall, the IP of the firewall was the "SMTP
host").

There are also several external mail programs that could be used with
existing Unix scripts.	However, some of these have a slightly different
syntax than Unix mailers.  "WindMail" (http:www.geocel.com/windmail/) is
supposed to be a good one (I haven't tried it).

Good luck,

- Eric

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


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

Date: Sun, 22 Jun 1997 20:29:23 -0700
From: scrivner@gps.caltech.edu (Craig Scrivner)
Subject: Re: Q: an alternative to this use of "goto"?
Message-Id: <scrivner-2206972029230001@seismo-emac07.gps.caltech.edu>

In article <33AD87AF.1C103AF8@sober.com>, Jason Moore <jmoore@sober.com> wrote:

> I would like to know if 
> there is a non-goto way of achieving the same thing. 

> If you need to back up a step (usually to tell the user to
> redo something)

In fact, you already have the answer.  The 'redo' command (see also 'next'
and 'last' commands) will do what you want.  The only hitch is that the
command has to work within a block, defined by curly brackets.  So...

START: {
  if (...) {
    ...
  }
  elsif (...) {
    ...
    redo START;
  }
}


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

Date: 23 Jun 1997 05:43:51 GMT
From: asfast@asfast.com (Lloyd Zusman)
Subject: Re: Q: an alternative to this use of "goto"?
Message-Id: <slrn5qs35c.bk0.asfast@ljz.asfast.net>

On Sun, 22 Jun 1997 20:29:23 -0700, Craig Scrivner <scrivner@gps.caltech.edu> wrote:
> In article <33AD87AF.1C103AF8@sober.com>, Jason Moore <jmoore@sober.com> wrote:
> 
> > I would like to know if 
> > there is a non-goto way of achieving the same thing. 
> 
> > If you need to back up a step (usually to tell the user to
> > redo something)
> 
> In fact, you already have the answer.  The 'redo' command (see also 'next'
> and 'last' commands) will do what you want.  The only hitch is that the
> command has to work within a block, defined by curly brackets.  So...
> 
> START: {
>   if (...) {
>     ...
>   }
>   elsif (...) {
>     ...
>     redo START;
>   }
> }

But aside from spelling "goto" as "redo" and requiring an extra level
of braces, how does this example differ from using "goto"?

The "goto" statement first fell into disfavor many years ago as part
of the philosophy of "modular programming". The above construct would
be considered just as undesirable by the proponents of modular
programming as the following construct.

  START:
    if (...) {
      ...
    }
    elsif (...) {
      ...
      goto START;
    }

The extra level braces and the the word "redo" instead of "goto" do
not change the basic flaw in this construct from the point of view of
those who strictly adhere to the philosophy of modular programming.

Here is one of several ways that these strict adherents of modular
programming would write the above construct:

    for (;;) {
      if (...) {
        ...
	last;
      }
      elsif (...) {
        ...
      }
      else {
        last;
      }
    }

And here's another variation that would be acceptable to the strict
modular programming crowd:

    $looping = 1;
    while ($looping) {
      $looping = 0;
      if (...) {
        ...
      }
      elsif (...) {
        ...
	$looping = 1;
      }
    }

There are other variations, as well.

The don't-ever-ever-ever-use-"goto"-no-matter-what movement has lost
some of its dogmatic fervor over the past decade, and people are a bit
more relaxed and practical about this issue nowadays.  Today's
acceptability of the "redo" construct is evidence of this.

Therefore, it's my opinion that if you really want to use that "redo"
construct, you might as well just leave off the extra braces and spell
"redo" as "goto".


-- 
 Lloyd Zusman
 ljz@asfast.com


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

Date: 22 Jun 1997 23:13:17 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Jason Moore <jmoore@sober.com>
Subject: Re: Q: an alternative to this use of "goto"?
Message-Id: <8c205tsv7m.fsf@gadget.cscaper.com>

>>>>> "Jason" == Jason Moore <jmoore@sober.com> writes:

Jason> I've always heard that the function "goto" is outdated,
Jason> and considered bad form since it makes code difficult to 
Jason> maintain and usually isn't necessary.

It's also amazingly slow.  Perhaps not an issue here, but
using Perl's "goto" is exceedingly discouraged.

Jason>   I have found a use of
Jason> "goto" which I find quite handy, and I would like to know if 
Jason> there is a non-goto way of achieving the same thing. 

Of course.  There always is.  Turing machines don't have a "goto". :-)

Jason> I find "goto" particularly useful in CGI scripts* which
Jason> always seem to consist of a big CASE or if/elsif/else 
Jason> statement.  If you need to back up a step (usually to tell the user to
Jason> redo something), I use something like the following:

Jason> START:                                  ## a label to "goto"

Jason> if ($param_action eq "")                ## first time through
Jason> {
Jason>         &print_status;                  ## prints any status
Jason>                                         ## messages, if there are any.
Jason>                                         ## if this is there
Jason>                                         ## first time through 
Jason>                                         ## then there shouldn't 
Jason>                                         ## be any messages.

Jason>         &print_form;                    ## prints HTML form

Jason> }
Jason> elsif ($param_action eq "edit")         ## form submitted
Jason> {       

Jason>         if(&error_check_form)           ## checks for errors in
Jason>         {                               ## user input.
Jason>                                         ## Puts messages in
Jason>                 $param_action = "";     ## @status.
Jason>                 goto("START");          ## <<< COOL!
Jason>         }
 
Jason>         &process_form; 
Jason>         &print_results;
Jason> }

Yeah.  Bleh.  I'd write that like this:

	if ($param_action eq "edit" and not &error_check_form) {
		&process_form;
		&print_results;
	} else {
		&print_status;
		&print_form;
	}

Much simpler.  If you wanna put the first ahead of the second, just
invert and apply Morgan's laws:

	if ($param_action ne "edit" or &error_check_form) {
		&print_status;
		&print_form;
	} else {
		&process_form;
		&print_results;
	}

And if that was too tough, just use "unless" and keep the old
expression:

	unless ($param_action eq "edit" and not &error_check_form) {
		&print_status;
		&print_form;
	} else {
		&process_form;
		&print_results;
	}

Of course, I'd probably be more positive here by changing &error_check_form
to &have_valid_form, and write that as:

	unless ($param_action eq "edit" and &have_valid_form) {
		&print_status;
		&print_form;
	} else {
		&process_form;
		&print_results;
	}

But I'd probably switch "unless" to "if" before I did that.

Jason> Is there a better way?  (BTW - I used to achieve the same 
Jason> effect with a redirection, but besides having to worry about 
Jason> whether to send a Content-Type or a Location header, it 
Jason> involved an extra HTTP request, and an extra loading of the 
Jason> perl interpreter.  "goto" is much more elegant than this.)

I see nothing elegant about a "goto" here.

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

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


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

Date: 24 Jun 1997 08:08:18 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: ljz@asfast.com (Lloyd Zusman)
Subject: Re: Q: an alternative to this use of "goto"?
Message-Id: <8cvi3482e5.fsf@gadget.cscaper.com>

>>>>> "Lloyd" == Lloyd Zusman <asfast@asfast.com> writes:

Lloyd> Of course.  But in the subset of cases where "redo" and "goto" are
Lloyd> equivalent, there is nothing wrong with "goto" ... or at least nothing
Lloyd> worse about it than using the equivalent "redo" construct.

 ... except speed, which has already been pointed out elsewhere in this
thread.  A "goto" is implemented by a *linear* search of all opcodes
from beginning to end looking for the goto target.  As the program
gets bigger, performance gets *much* worse.  "redo" is implemented
rather trivially, because the block-start is known, and even outer
contexts are on the runtime stack for "redo LABEL".  Much faster.

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

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


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

Date: 24 Jun 1997 08:05:20 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: mike@stok.co.uk (Mike Stok)
Subject: Re: Q: an alternative to this use of "goto"?
Message-Id: <8cyb8082j3.fsf@gadget.cscaper.com>

>>>>> "Mike" == Mike Stok <mike@stok.co.uk> writes:

>> redo will be implemented in the compiler and future versions of Perl; the
>> future of goto is much more in doubt. Hope this helps!

Mike> One would hope that the useful

Mike>   goto &func;

Mike> doesn't get axed by some "everything can be done with loops and
Mike> conditionals" bigot.

Nope.  "goto &func" is not a goto.  It's deep voodoo
necessary-access-to-Perl-innards magic.  The tools that use it are now
firmly entrenched in the community, so no chance it would go away.

Note: if you don't know what this does, DON'T BOTHER LEARNING.  It's
for Autoload handlers, and if you don't know what that is, don't
bother with that either. :-)

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

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


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

Date: Tue, 24 Jun 1997 07:28:02 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Random access files in PERL
Message-Id: <ebohlmanEC9rEq.IvF@netcom.com>

Don Botten (donb@wcnet.org) wrote:
: I want to read and write to Random access files.  For example, I want to
: be able to change only one record of a file, or goto a particular spot
: to read some data.  I have a few of Sams books on perl but cannot find
: anything on random access files.

: Can anyone point me in the right direction?

seek() and tell() are your friends.



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

Date: 23 Jun 1997 22:25:48 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: reading a data file?
Message-Id: <5onb7c$fva@panix.com>

In <33AEDBD9.8CDFF235@mindless.com> Brandon <weekend_warrior@mindless.com> writes:

>Hi I'm looking to make this script of mine a little more bareable.
>I have tried, for days, to make this into a data file called by the
>script. No luck!
>What I need the script to do is read a data file with the information of
>the users in a format like:
>1234 = someone@somewhere.com
>4321 = someonelse@somewhere.com
>or
>1234
>someone@somewhere.com
>4321
>someonelse@somewhere.com
>and return only the email address as $id depending on the input.
>Is this possible?
>I have the script working but it is going to have MANY users and I don't
>like the idea of the main script being edited every time a user is
>added.
>Pleas help...any suggestions woudl be great!
>Here is what the section in question looks like now.
># Snippet of code needed to be changed #
>sub check_id {
>        if ($CONFIG{'recipient'} eq '1234') {
>                $id = 'info@cois.on.ca';
>        }
>        if ($CONFIG{'recipient'} eq '4321') {
>                $id = 'support@cois.on.ca';
>        }
>        else {
>                &error('bad_id');
>        }

>} 
># end of snippet #

Why don't you put the id and Email address in a hash like you did for
$CONFIG{'recipient'} -- For example:

  #!/usr/local/bin/perl5.003 -w
  
  while (<DATA>) {
    chomp;
    s/\s//g;                       # get rid of the spaces in the data
    ($userid, $email) = split /=/; # split on the '=' sign
    $user{$userid} = $email;       # put the data in a hash
  }
  
  print "$user{'1234'}\n";         # print a specific user by the key
  
  __DATA__
  1234 = someone@somewhere.com
  4321 = someonelse@somewhere.com
  
This program prints:

  someone@somewhere.com

You could even do something like:

  #!/usr/local/bin/perl5.003 -w
  
  $CONFIG{'recipient'} = "1234";
  
  while (<DATA>) {
    chomp;
    s/\s//g;
    ($userid, $email) = split /=/;
    $user{$userid} = $email;
  }
  
  print "$user{$CONFIG{'recipient'}}\n";
  
  __DATA__
  1234 = someone@somewhere.com
  4321 = someonelse@somewhere.com

HTH,

-- 
Clay Irving                                        See the happy moron,
clay@panix.com                                     He doesn't give a damn,
http://www.panix.com/~clay                         I wish I were a moron,
                                                   My God! Perhaps I am!


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

Date: Tue, 24 Jun 1997 07:32:44 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: regex question
Message-Id: <ebohlmanEC9rMK.J77@netcom.com>

Dan Pfefferkorn (danp@salaam.Eng.Sun.COM) wrote:
: Consider the following snippet:

: $pattern = '$test';
: while(<>) {
:   print "yes\n" if (/$pattern/);
: }

[snip]

: How can I do a pattern match where the pattern is quoted, i.e., where it
: will match correctly if I type $test in stdin?

Look up the \Q metacharacter and the quotemeta() function; they're 
intended to solve exacly this problem.



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

Date: 22 Jun 1997 23:57:16 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Magnus.Bodin@tychonides.se (Magnus Bodin)
Subject: Re: Script to verify email addresses?
Message-Id: <8c91013iyb.fsf@gadget.cscaper.com>

>>>>> "Magnus" == Magnus Bodin <Magnus.Bodin@tychonides.se> writes:

Magnus> Here it is at deja:

Magnus> http://xp8.dejanews.com/getdoc.xp?recnum=%3c5e2aqo$3km$1@csnews.cs.colorado.edu%3e&server=db97p1&CONTEXT=866979817.18459&hitnum=2

Dejanews query URLs automatically become useless after two hours.  So
this URL is useless.

But if you look in the Perl FAQ, you'll see:

    http://www.perl.com/CPAN/authors/Tom_Christiansen/scripts/ckaddr.gz

under a heading surprisingly titled:

  How do I check a valid email address?

Check the Perl FAQ first.  Always.  First.

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

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


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

Date: 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 653
*************************************

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