[12291] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5893 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 4 19:07:18 1999

Date: Fri, 4 Jun 99 16:02:32 -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           Fri, 4 Jun 1999     Volume: 8 Number: 5893

Today's topics:
        Perl and Scheduling Tasks <jalil@corp.home.net>
    Re: Perl and Scheduling Tasks <tchrist@mox.perl.com>
    Re: Perl Unicode/Multibyte Support (Ilya Zakharevich)
    Re: replacing a word in a flat file <rootbeer@redcat.com>
    Re: replacing a word in a flat file <tchrist@mox.perl.com>
    Re: s/a*/x/g behavior (Ilya Zakharevich)
    Re: Simple newbie question... <uri@sysarch.com>
    Re: Simple newbie question... (Mark Morley)
    Re: Simple newbie question... <rootbeer@redcat.com>
    Re: Simple newbie question... <rootbeer@redcat.com>
    Re: Simple newbie question... <magus@cs.cmu.edu>
    Re: Simple question about hashes (Michel Dalle)
        Thanks! the1bob@my-deja.com
        Thanks! the1bob@my-deja.com
        Unistall 1 of 2 perls on a server <marc@www.com>
    Re: Using Or to evaluate multiple values (Larry Rosler)
    Re: Using Or to evaluate multiple values <rootbeer@redcat.com>
    Re: XS: Overriding errno? <sugalskd@netserve.ous.edu>
    Re: You can earn $50,000 by learning programming skills gillwill2000@my-deja.com
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 04 Jun 1999 21:42:04 GMT
From: "Jalil Feghhi" <jalil@corp.home.net>
Subject: Perl and Scheduling Tasks
Message-Id: <928532524.424160@zeppelin.svr.home.net>

Is there any support for doing task scheduling in Perl for win32?

Thanks,

-Jalil





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

Date: 4 Jun 1999 16:29:09 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl and Scheduling Tasks
Message-Id: <37585335@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, "Jalil Feghhi" <jalil@corp.home.net> writes:
:Is there any support for doing task scheduling in Perl for win32?

Win32 has tasks?

--tom
-- 
Real programmers can write assembly code in any language.   :-)  
                --Larry Wall in  <8571@jpl-devvax.JPL.NASA.GOV>


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

Date: 4 Jun 1999 21:17:43 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl Unicode/Multibyte Support
Message-Id: <7j9fpn$ltq$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Kai Henningsen
<kaih=7ICqW50Hw-B@khms.westfalen.de>],
who wrote in article <7ICqW50Hw-B@khms.westfalen.de>:
> > > > > > There is no conversion of any kind.  Perl strings are just sequences
> > > > > > of small integers.  Without `use utf8' small means 0..255.  With
> > > > > > `use utf8' small means 0..2**36-1.  This is the only difference
> > > > > > (forgetting about speed and bugs).
> >
> > > 0..2^31-1 is really all UTF-8 is defined for (that is, the ISO 10646
> > > range).
> >
> > Who cares?  I was not discussing iso-shmiso, I was discussing Perl.
> 
> Nope. UTF-8 is firmly an ISO animal.

Again: who cares?  I was discussing Perl with C<use utf8>, not some
ISO standard.

Ilya


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

Date: Fri, 4 Jun 1999 14:05:51 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: replacing a word in a flat file
Message-Id: <Pine.GSO.4.02A.9906041404370.10794-100000@user2.teleport.com>

On Fri, 4 Jun 1999, Samir Jain wrote:

> Subject: replacing a word in a flat file

Section five of the FAQ talks about how to edit a text file line-by-line.
Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 4 Jun 1999 16:28:00 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: replacing a word in a flat file
Message-Id: <375852f0@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    Samir Jain <sjain@uswest.com> writes:
:Hi,
: This is my first program and i am stuck.. I have a flat file which
:looks like this
:
:usr1:passwd1
:usr2:passwd2
:usr3:passwd3
:
:I want to replace passwd1 with passwdx.


This is covered in three recipes in the Perl cookbook.  You can
ftp the stuff directly here:

    ftp://ftp.oreilly.com/published/oreilly/perl/cookbook/pcookexamples.tar.gz

Or you could read the perlfaq9 manpage on your very section.
Here's an excerpt you should read all of.

--tom


NAME
    perlfaq5 - Files and Formats ($Revision: 1.38 $, $Date:
    1999/05/23 16:08:30 $)

DESCRIPTION
    This section deals with I/O and the "f" issues: filehandles,
    flushing, formats, and footers.

  How do I flush/unbuffer an output filehandle?  Why must I do this?

    The C standard I/O library (stdio) normally buffers characters
    sent to devices. This is done for efficiency reasons, so that
    there isn't a system call for each byte. Any time you use
    print() or write() in Perl, you go though this buffering.
    syswrite() circumvents stdio and buffering.

    In most stdio implementations, the type of output buffering and
    the size of the buffer varies according to the type of device.
    Disk files are block buffered, often with a buffer size of more
    than 2k. Pipes and sockets are often buffered with a buffer size
    between 1/2 and 2k. Serial devices (e.g. modems, terminals) are
    normally line-buffered, and stdio sends the entire line when it
    gets the newline.

    Perl does not support truly unbuffered output (except insofar as
    you can `syswrite(OUT, $char, 1)'). What it does instead support
    is "command buffering", in which a physical write is performed
    after every output command. This isn't as hard on your system as
    unbuffering, but does get the output where you want it when you
    want it.

    If you expect characters to get to your device when you print
    them there, you'll want to autoflush its handle. Use select()
    and the `$|' variable to control autoflushing (see the section
    on "$|" in the perlvar manpage and the "select" entry in the
    perlfunc manpage):

        $old_fh = select(OUTPUT_HANDLE);
        $| = 1;
        select($old_fh);

    Or using the traditional idiom:

        select((select(OUTPUT_HANDLE), $| = 1)[0]);

    Or if don't mind slowly loading several thousand lines of module
    code just because you're afraid of the `$|' variable:

        use FileHandle;
        open(DEV, "+</dev/tty");      # ceci n'est pas une pipe
        DEV->autoflush(1);

    or the newer IO::* modules:

        use IO::Handle;
        open(DEV, ">/dev/printer");   # but is this?
        DEV->autoflush(1);

    or even this:

        use IO::Socket;               # this one is kinda a pipe?
        $sock = IO::Socket::INET->new(PeerAddr => 'www.perl.com',
                                      PeerPort => 'http(80)',
                                      Proto    => 'tcp');
        die "$!" unless $sock;

        $sock->autoflush();
        print $sock "GET / HTTP/1.0" . "\015\012" x 2;
        $document = join('', <$sock>);
        print "DOC IS: $document\n";

    Note the bizarrely hardcoded carriage return and newline in
    their octal equivalents. This is the ONLY way (currently) to
    assure a proper flush on all platforms, including Macintosh.
    That's the way things work in network programming: you really
    should specify the exact bit pattern on the network line
    terminator. In practice, `"\n\n"' often works, but this is not
    portable.

    See the perlfaq9 manpage for other examples of fetching URLs
    over the web.

  How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?

    Those are operations of a text editor. Perl is not a text
    editor. Perl is a programming language. You have to decompose
    the problem into low-level calls to read, write, open, close,
    and seek.

    Although humans have an easy time thinking of a text file as
    being a sequence of lines that operates much like a stack of
    playing cards -- or punch cards -- computers usually see the
    text file as a sequence of bytes. In general, there's no direct
    way for Perl to seek to a particular line of a file, insert text
    into a file, or remove text from a file.

    (There are exceptions in special circumstances. You can add or
    remove at the very end of the file. Another is replacing a
    sequence of bytes with another sequence of the same length.
    Another is using the `$DB_RECNO' array bindings as documented in
    the DB_File manpage. Yet another is manipulating files with all
    lines the same length.)

    The general solution is to create a temporary copy of the text
    file with the changes you want, then copy that over the
    original. This assumes no locking.

        $old = $file;
        $new = "$file.tmp.$$";
        $bak = "$file.orig";

        open(OLD, "< $old")         or die "can't open $old: $!";
        open(NEW, "> $new")         or die "can't open $new: $!";

        # Correct typos, preserving case
        while (<OLD>) {
            s/\b(p)earl\b/${1}erl/i;
            (print NEW $_)          or die "can't write to $new: $!";
        }

        close(OLD)                  or die "can't close $old: $!";
        close(NEW)                  or die "can't close $new: $!";

        rename($old, $bak)          or die "can't rename $old to $bak: $!";
        rename($new, $old)          or die "can't rename $new to $old: $!";

    Perl can do this sort of thing for you automatically with the `-
    i' command-line switch or the closely-related `$^I' variable
    (see the perlrun manpage for more details). Note that `-i' may
    require a suffix on some non-Unix systems; see the platform-
    specific documentation that came with your port.

        # Renumber a series of tests from the command line
        perl -pi -e 's/(^\s+test\s+)\d+/ $1 . ++$count /e' t/op/taint.t

        # form a script
        local($^I, @ARGV) = ('.orig', glob("*.c"));
        while (<>) {
            if ($. == 1) {
                print "This line should appear at the top of each file\n";
            }
            s/\b(p)earl\b/${1}erl/i;        # Correct typos, preserving case
            print;
            close ARGV if eof;              # Reset $.
        }

    If you need to seek to an arbitrary line of a file that changes
    infrequently, you could build up an index of byte positions of
    where the line ends are in the file. If the file is large, an
    index of every tenth or hundredth line end would allow you to
    seek and read fairly efficiently. If the file is sorted, try the
    look.pl library (part of the standard perl distribution).

    In the unique case of deleting lines at the end of a file, you
    can use tell() and truncate(). The following code snippet
    deletes the last line of a file without making a copy or reading
    the whole file into memory:

            open (FH, "+< $file");
            while ( <FH> ) { $addr = tell(FH) unless eof(FH) }
            truncate(FH, $addr);

    Error checking is left as an exercise for the reader.

-- 
    "The C Programming Language --A language which combines the
    flexibility of assembly language with the power of assembly language."


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

Date: 4 Jun 1999 21:21:06 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: s/a*/x/g behavior
Message-Id: <7j9g02$lvh$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Uri Guttman 
<uri@sysarch.com>],
who wrote in article <x7n1yfahad.fsf@home.sysarch.com>:
>   JP> Do you know, (or anywhere else know) where it is documented that
>   JP> Perl will advance the pointer so that it doesn't infinitely
>   JP> replace the null string?  Is it in perlre or the Friedl book?  I'm
>   JP> not claiming it isn't documented, it just points out to me that I
>   JP> haven't read some section of the documentation thoroughly enough.
> 
> MRE page 249, bottom covers this very issue.

And it covers it wrong, if you run 5.005_*.

Ilya



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

Date: 04 Jun 1999 17:08:46 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Simple newbie question...
Message-Id: <x77lpjad29.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> [Posted and a courtesy copy mailed.]
  LR> In article <Pine.GSO.4.02A.9906041243560.10794-
  LR> 100000@user2.teleport.com> on Fri, 4 Jun 1999 12:44:08 -0700, Tom 
  LR> Phoenix <rootbeer@redcat.com> says...
  >> On 4 Jun 1999, Mark Morley wrote:
  >> 
  >> > So how can one distinguish between the string "0" and the number 0?

  LR> I thought that one really couldn't distinguish between them, because 
  LR> each is converted into the other in relevant contexts.

a more important question is, is it useful to know? since they are
converted to each other when needed, why should you care which form it
is in? as someone in p5p pointed out that the act of printing a variable
with a number in it does an implicit conversion to a string. so you
don't even have much control over what format a variable has.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 4 Jun 1999 21:34:25 GMT
From: mark@islandnet.com (Mark Morley)
Subject: Re: Simple newbie question...
Message-Id: <7j9gp1$sb2$1@news.islandnet.com>

Uri Guttman (uri@sysarch.com) wrote:

: a more important question is, is it useful to know? since they are
: converted to each other when needed, why should you care which form it
: is in? as someone in p5p pointed out that the act of printing a variable
: with a number in it does an implicit conversion to a string. so you
: don't even have much control over what format a variable has.

Ok, here's the scenario...  There is a function that is provided by
someone else that takes a string value and performs a lookup.  It returns
a string result or a 0 if it couldn't find anything.  Consider this code:

   if( ($value = lookup( $key )) == 0 ) {
      print "No value found for $key!";
   } else {
      print "Value = $value";
   }

This works as expected EXCEPT when the lookup function returns the string
"0", in which case it acts exactly as though it returned 0 (the number).
It doesn't make any difference if I use "eq" instead of "==".

Seems to me the only real solution is to change the lookup function to
indicate a failure via some other result code.

Mark


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

Date: Fri, 4 Jun 1999 14:53:41 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Simple newbie question...
Message-Id: <Pine.GSO.4.02A.9906041450210.10794-100000@user2.teleport.com>

On 4 Jun 1999, Uri Guttman wrote:

>   >> > So how can one distinguish between the string "0" and the number 0?

> a more important question is, is it useful to know? since they are
> converted to each other when needed, why should you care which form it
> is in?

Well, you could be writing a subroutine which pre-processes some
parameters before handing them off to syscall(), say. That's one of the
very few places where it matters to Perl whether something is a number or
a string.

> as someone in p5p pointed out that the act of printing a variable
> with a number in it does an implicit conversion to a string. so you
> don't even have much control over what format a variable has.

Or, at least, that could happen at one time. I can't find a way to make
that happen in recent versions of perl, although there are may well be
some hidden cases left in the core which silently and unexpectedly
stringify a variable. Finding them all and deciding which to classify as
bugs is left as an exercise. :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 4 Jun 1999 15:12:00 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Simple newbie question...
Message-Id: <Pine.GSO.4.02A.9906041455080.10794-100000@user2.teleport.com>

On Fri, 4 Jun 1999, Larry Rosler wrote:

> In article <Pine.GSO.4.02A.9906041243560.10794-
> 100000@user2.teleport.com> on Fri, 4 Jun 1999 12:44:08 -0700, Tom 
> Phoenix <rootbeer@redcat.com> says...
> > On 4 Jun 1999, Mark Morley wrote:
> > 
> > > So how can one distinguish between the string "0" and the number 0?
> > 
> > See the FAQ. Cheers!
> 
> Please be more explicit.  I couldn't find anything about this in the 
> FAQ.  perlfaq4:  "How do I determine whether a scalar is a 
> number/whole/integer/float?" doesn't respond to this question.

You're right; I'm not certain why I had thought that it did. This should
be in the FAQ.

> I thought that one really couldn't distinguish between them, because 
> each is converted into the other in relevant contexts.

Nearly always. Almost any program which relies on their difference should
be recoded. But in a few very rare cases you may need to know the
difference - such as in a parameter to syscall, or a bitmask. Here's the
(aesthetically pleasing!) way I use to distinguish a number from its
numeral in those rare cases.

    if ('00' & $value | '00') {
	print "Value $value seems to be a string.\n";
    } else {
	print "Value $value seems to be a number.\n";
    }

As Uri pointed out elsewhere in this thread, though, simply printing a
value could stringify it (in some versions of perl).

    $value = 3.14159;
    print "The value is '$value'.\n";
    # Now it may be either a string or a number!

Even if you avoid printing (or interpolating) a variable, there may be
other ways lurking in the core in which it could be silently and
unexpectedly stringified. So that's yet another reason that a program
relying upon this distinction should be recoded. Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 04 Jun 1999 18:14:30 -0400
From: Nat Lanza <magus@cs.cmu.edu>
Subject: Re: Simple newbie question...
Message-Id: <uocpv3bk3zt.fsf@evelake.pdl.cs.cmu.edu>

mark@islandnet.com (Mark Morley) writes:

> Ok, here's the scenario...  There is a function that is provided by
> someone else that takes a string value and performs a lookup.  It returns
> a string result or a 0 if it couldn't find anything.  Consider this code:

[ snipped ]

> Seems to me the only real solution is to change the lookup function to
> indicate a failure via some other result code.

This would be why we have 'undef'.

"Sometimes when I'm pounding screws in with my hammer I have trouble
telling if they're regular or phillips-head. Is there a smarter hammer?"


--nat

-- 
nat lanza --------------------- research programmer, parallel data lab, cmu scs
magus@cs.cmu.edu -------------------------------- http://www.cs.cmu.edu/~magus/
there are no whole truths; all truths are half-truths -- alfred north whitehead


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

Date: Fri, 04 Jun 1999 21:13:19 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Simple question about hashes
Message-Id: <7j9ffu$j5h$1@xenon.inbe.net>

In article <x7g147afee.fsf@home.sysarch.com>, Uri Guttman <uri@sysarch.com> wrote:
[snip]
>but as someone else posted it is better to use exists, as in the case
>where a key exists but has an undefined value, then defined will be
>false. exists never checks the value, just whethet the key is in the
>hash.

Oops, that's right !

In most of the scripts I use, I couldn't do anything with a key having an 
undefined value anyway, so I just skip the 'exists' part and check directly
for a 'defined'. Bad habit, I guess...

Michel.


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

Date: Fri, 04 Jun 1999 21:22:07 GMT
From: the1bob@my-deja.com
Subject: Thanks!
Message-Id: <7j9g1k$oa7$1@nnrp1.deja.com>

Thanks, folks.

 ...and Jenda, if you read this, please accept my apologies for the
gender mistake.

The program ran successfully ON THE FIRST RUN (from the command line)!
:-)  Of course it was almost totally cut-n-paste from the example.  Now
I have to create the front end form to accept user input.  Uploading
files will come later.

I assume I can simply use (use CGI qw(:standard)) to declare my
variables using:

my $useremail = param("USEREMAIL");
my $subject = param("SUBJECT");
 .....etc.....

 ...then substitute the addresses, subjects, etc with the variable
names.....and make the output formatted nicely.

Am I on the right track?  Any pitfalls/landmines to watch out for from a
first-time Mail-Sender user?

Again thanks for the really quick feedback.  Hope to share some
knowledge soon myself.  I worked with PERL in a UNIX web environment
four years ago and a LOT has changed.  What has REALLY ruined my skills
is that I've been forced to use FrontPage to do all page creation and
site management for the last two years.  *sigh*

Regards,

Bob

In article <7j8nhv$e3t$1@nnrp1.deja.com>,
  the1bob@my-deja.com wrote:
> Hello, all!
>
> I just successfully installed Jenda's Mail-Sender PM and can't wait to
> start testing it.  :-)
>
> I have, by default, MIME-Base64 installed as part of the ActivePerl
> distribution.  Mail-Sender also requires MIME-QuotedPrint.  Where can
I
> get that module?  It was not on her site or the ActiveState list.
> *sigh*
>
> Also.....do any of you have a good working model of the form interface
> that I can look at?
>
> The favor of a reply would be appreciated.
>
> TIA,
>
> Bob
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 04 Jun 1999 21:23:49 GMT
From: the1bob@my-deja.com
Subject: Thanks!
Message-Id: <7j9g4p$oau$1@nnrp1.deja.com>

Thanks, folks.

 ...and Jenda, if you read this, please accept my apologies for the
gender mistake.

The program ran successfully ON THE FIRST RUN (from the command line)!
:-)  Of course it was almost totally cut-n-paste from the example.  Now
I have to create the front end form to accept user input.  Uploading
files will come later.

I assume I can simply use (use CGI qw(:standard)) to declare my
variables using:

my $useremail = param("USEREMAIL");
my $subject = param("SUBJECT");
 .....etc.....

 ...then substitute the addresses, subjects, etc with the variable
names.....and make the output formatted nicely.

Am I on the right track?  Any pitfalls/landmines to watch out for from a
first-time Mail-Sender user?

Again thanks for the really quick feedback.  Hope to share some
knowledge soon myself.  I worked with PERL in a UNIX web environment
four years ago and a LOT has changed.  What has REALLY ruined my skills
is that I've been forced to use FrontPage to do all page creation and
site management for the last two years.  *sigh*

Regards,

Bob

In article <7j8nhv$e3t$1@nnrp1.deja.com>,
  the1bob@my-deja.com wrote:
> Hello, all!
>
> I just successfully installed Jenda's Mail-Sender PM and can't wait to
> start testing it.  :-)
>
> I have, by default, MIME-Base64 installed as part of the ActivePerl
> distribution.  Mail-Sender also requires MIME-QuotedPrint.  Where can
I
> get that module?  It was not on her site or the ActiveState list.
> *sigh*
>
> Also.....do any of you have a good working model of the form interface
> that I can look at?
>
> The favor of a reply would be appreciated.
>
> TIA,
>
> Bob
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Fri, 04 Jun 1999 13:48:25 -0700
From: Marc Northover <marc@www.com>
Subject: Unistall 1 of 2 perls on a server
Message-Id: <37583B99.7333F7A0@www.com>

Here is my scenario:
- installed 5.005_02 using basic installation (except I installed in
/usr/local/lib)
- upgraded RedHat to 5.2
- noticed perl-5.004m4-1.rpm was installed (in /usr/lib)

It looks like 
will I shoot myself in the foot if I unistall the rpm:
rpm -e --force perl-5.004m4-1.rpm (not sure if that is the exact
command)

Since the binaries, libraries, man pages are completely separate will
this cause any problems.

Marc


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

Date: Fri, 4 Jun 1999 13:58:13 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Using Or to evaluate multiple values
Message-Id: <MPG.11c1ddc088ed4958989b70@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7j97qo$l04$1@nnrp1.deja.com> on Fri, 04 Jun 1999 19:01:52 
GMT, jeff5491@my-deja.com <jeff5491@my-deja.com> says...
> I need to evaluate input from a search page and
> respond based on the user's input.
> 
> This works for a single city match.
> 
> elsif (($DATA{'city_text'} || $DATA{'city'}) eq
> "MOUNT EDEN")
> 	{
> 	print "Mount Eden Rocks!";
> 	}
> 
> There are cases where the print statement will be
> common for numerous cities.
> 
> This doesn't work for a multiple city match.
> 
> elsif (($DATA{'city_text'} || $DATA{'city'}) eq
> ("MOUNT EDEN" || "SUNOL"))
> 	{
> 	print "Cities in Alameda County Rock!";
> 	}
> 
> Is there an elegant way to list all the cities
> that apply to this print statement in one elsif
> statement?

perlfaq4:  "How can I tell whether a list or array contains a certain 
element?"


#!/usr/local/bin/perl -w
use strict;

my @cities = ( 'BERKELEY', 'MOUNT EDEN', 'OAKLAND', 'SUNOL' );
my %Alameda;
@Alameda{@cities} = (1) x @cities;

my %DATA = ( city => 'FOOBAR', city_text => 'SUNOL' );

if ($Alameda{$DATA{'city_text'} || $DATA{'city'}})
	{
	print "Cities in Alameda County Rock!";
	}


-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 4 Jun 1999 14:11:10 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Using Or to evaluate multiple values
Message-Id: <Pine.GSO.4.02A.9906041407560.10794-100000@user2.teleport.com>

On Fri, 4 Jun 1999 jeff5491@my-deja.com wrote:

> elsif (($DATA{'city_text'} || $DATA{'city'}) eq
> ("MOUNT EDEN" || "SUNOL"))

> Is there an elegant way to list all the cities that apply to this
> print statement in one elsif statement?

Here's a way which may or may not be elegant. Set up a hash called
%good_cities, then:

    if ($good_cities{ $DATA{city_text} or $DATA{city} }) {
	...

Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 4 Jun 1999 22:48:19 GMT
From: Dan Sugalski <sugalskd@netserve.ous.edu>
Subject: Re: XS: Overriding errno?
Message-Id: <7j9l3j$8pd$1@news.NERO.NET>

Elf Sternberg <elf@halcyon.com> wrote:

: 	I'd like to override the settings on errno so that I can set them
: myself.  Looking around inside the guts of mg.c, this doesn't seem
: possible.  Anyone get this to work?

How much control over errno do you want? If you just want to set it
occasionally in your XS code when an error happens, use the SETERRNO
macro. It takes two integers--the first is set into errno/$!, while the
second is stuck in $^E.

If you actually want to take complete control, you might be able to get
away with setting some magic on a generic scalar and then doing a 

	*! = \$magic_scalar;

but I'm not sure I'd count on that working.

					Dan


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

Date: Fri, 04 Jun 1999 21:45:17 GMT
From: gillwill2000@my-deja.com
Subject: Re: You can earn $50,000 by learning programming skills and applying yourself
Message-Id: <7j9hdb$oqc$1@nnrp1.deja.com>

Me too! - Another Success Story!

In 1995 I was a homeless derilict sleeping on the streets of San Jose,
CA. One day someone in a car drove by and tossed a Macintosh computer
and a JavaScript Tutorial out their window.

For two years I voraciously studied and visualized the intricate
concepts of JavaScript while using the Macintosh as a door-stop to my
cardboard home.

In 1997 I hitched a ride to Mountain View, CA to see an old friend. I
liked the place so much I decided to make it my new home. One day when
I was standing on a corner with my "I will write code for food!" sign,
an executive from Netscape Communications pulled over and gave me a
ride. We spoke extesively about JavaScript. The next thing I knew I was
hired as a programmer. . . and the rest is history!

My only question is: "Why stop at $50,000?" With my new stock options
from AOL, I'll be a millionaire in no time.

:-)



In article <7j75tb$2o2$1@news.laserlink.net>,
  "Dan Hinojosa" <dawndan@gateway.net> wrote:

>
> This is no joke!  I was pennyless in 1990, and then I learned C++ and
Java,
> and all of a sudden it all came together.  All of a sudden, I had
respect
> for myself, and I was making $50,000 and more.  The best part about
it, is
> that I didn't have to lower my dignity and annoy people with high IQs
that
> wouldn't fall this swindle anyway!
>
> Love,
> Digital Priest
>
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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