[21752] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3956 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 11 18:05:56 2002

Date: Fri, 11 Oct 2002 15:05:10 -0700 (PDT)
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, 11 Oct 2002     Volume: 10 Number: 3956

Today's topics:
    Re: 96-column punched-card data <goldbb2@earthlink.net>
    Re: Bug/Programmer Error? ForkTest w/ Manager/Client wo <goldbb2@earthlink.net>
    Re: effect of "use <version>" on forward-compatibility? <vhg@byu.edu>
    Re: Fork question? <goldbb2@earthlink.net>
    Re: Getting off the ground (more newbie than newbie) (Richard Williams)
    Re: Hello World doesn't work in 5.8?? (milkfilk)
    Re: HTTP Command help....? <flavell@mail.cern.ch>
    Re: Is there a way <usenet@atrixnet.com>
    Re: Multiple Pings/Second <goldbb2@earthlink.net>
    Re: Multiple Pings/Second <binabik1@mail.com>
    Re: Net::FTP: Unexpected EOF on command channel <goldbb2@earthlink.net>
    Re: NEWBIE: Accessing FORM input with PERLSCRIPT <flavell@mail.cern.ch>
        Problems with MSIE in combination with MAC not showing  <jan@nospam.harf.nl>
        Regular Expressions Problem <david.bates2@ntlworld.com>
    Re: Regular Expressions Problem <jurgenex@hotmail.com>
        STDIN and choices on screen? (Tavish Muldoon)
    Re: STDIN and choices on screen? <jurgenex@hotmail.com>
    Re: STDOUT_TOP printing funny character <bongie@gmx.net>
    Re: STDOUT_TOP printing funny character <goldbb2@earthlink.net>
    Re: Switching from Python to Perl <goldbb2@earthlink.net>
    Re: undef == true? <s_grazzini@hotmail.com>
    Re: undef == true? <ddunham@redwood.taos.com>
    Re: undef == true? (Tad McClellan)
        Why is 'defined @x' deprecated? <heather710101@yahoo.com>
    Re: Why is 'defined @x' deprecated? <uri@stemsystems.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 11 Oct 2002 14:50:00 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: 96-column punched-card data
Message-Id: <3DA71D58.5B3039B@earthlink.net>

Michele Dondi wrote:
> 
> On Tue, 08 Oct 2002 18:35:18 -0400, Benjamin Goldberg
> <goldbb2@earthlink.net> wrote:
> 
> >This line:
> >   print +(split //)[TRANSLATE];
> >Could be written more verbosely as:
> >   @temp = split //, $_;
> >   @reordered = @temp[TRANSLATE];
> >   print @reordered;
> 
> Why are the two forms equivalent? More precisely why does one need the
> '+'? (and omitting it generates an error).

When perl parses list operators according to the rule, "if it looks like
a function call, treat it as a function call."  If the first
nonwhitespace after a list operator is a left parenthesis, then that
paren marks the beginning of the arguments for that operator, and the
corresponding right paren marks the end of the arguments for the
operator.  That is:

   print (split //)[TRANSLATE];

Is treated similarly to:

   ( print(split //) )[TRANSLATE];

(Except if there *were* that extra set of parens, it wouldn't be a
syntax error, but would be a list slice on the return value of the print
function).

Interposing the + causes it to be treated as:

   print( (split //)[TRANSLATE] );

> Note: of course I'm aware of the fact that I could put the argument to
> print in parentheses...

The + serves the same purpose as the parens, except that it's one
character, not two.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Fri, 11 Oct 2002 15:39:38 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Bug/Programmer Error? ForkTest w/ Manager/Client works linux fails on Windows
Message-Id: <3DA728FA.4BFB35F4@earthlink.net>

rtm wrote:
[snip]
> This example code always gets stuck when run under windows.  I am
> running perl 5.6.1 from activestate and the cygwin version as well.
> Under Windows ME it gets stuck at the select call.  Under NT it does
> not terminate correctly.

The select function may *only* be used with nonbuffered IO.  Do not ever
follow a select call with <> or readline() or read().  Only follow a
select call with sysread().  *Sometimes*, following select with <> won't
cause problems, but eventually you will run into a situation where (at
the C level) it reads more than one just the one line into the
stdio/perlio buffer, and then only returns one line, leaving some data
stuck inside the buffer, invisible to the select() function, eventually
causing select to block (indicating that there's nothing to be read from
the underlying filedescriptor), even though there's data available in
the stdio/perlio buffer.

Furthermore, for each time that select() indicates that a handle is
readable, you should only sysread() from that handle *once and only
once*, and if you don't get a full line, store the data you got into
your own buffer, and go back to your select loop (or rather, continue
looping over the other sockets which are readable, process them, then go
back to the select() thing).

Some examples for proper use of select and multiple filehandles can be
found with:
   http://groups.google.com/groups?q=author:goldberg+io-select


I can't comment on why it might not terminate correctly on NT, except to
say that you should perform your waitpid()s as soon after the children
exit as possible (usually, by performing just after you get EOF when
reading from it's socket).

Or, if you don't plan on using the children's exit statuses, use the
double-fork technique to reap your children right away.

for my $child ( .... ) {
   fork and wait, next;
   fork and exit;
   ... child stuff here ...
   exit;
}

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Fri, 11 Oct 2002 15:37:44 -0600
From: Vaughn Gardner <vhg@byu.edu>
Subject: Re: effect of "use <version>" on forward-compatibility?
Message-Id: <3DA744A8.600@byu.edu>

> On Tue, 8 Oct 2002 17:56:43 -0500,
> 	Tad McClellan <tadmc@augustmail.com> wrote:
> 
>>Vaughn Gardner <vhg@byu.edu> wrote:
>>
>>>(we have versions as old as 
>>>4.0.1.8 with code running against them).
>>
>>
>>That is not a Perl version number. I think you mean v4.036.

Here's what it said about itself:

$ /usr/contrib/bin/perl -v

This is perl, version 4.0

$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36

Copyright (c) 1989, 1990, 1991, Larry Wall

Perl may be copied only under the terms of either the Artistic License 
or the GNU General Public License, which may be found in the Perl 4.0 
source kit.

If this isn't a valid build ID, maybe I have bigger problems than I 
thought :)



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

Date: Fri, 11 Oct 2002 15:42:47 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Fork question?
Message-Id: <3DA729B7.29CB012F@earthlink.net>

paul wrote:
> 
> Thanks guys,
> 
> You have certainly given me much food for thought. Benjamin - thanks
> for the code - that could very well save my hairline from receding for
> a day or 2 :)
> 
> I have another quick question if anyone has an opinion. I may have to
> send and receive many, many emails (possibly 100,000) for a period of
> one month. It is for a web application and definitely not spam. The
> previous application I mentioned sends SMS so this is a seperate app.
> I have sent mail on a few occassions with Perl (libnet stuff, etc) but
> wandered if anyone had any opinions on piping this amount of mail out
> through SMPP (and receiving via pop3?).

For sending large amounts of mail, use Mail::Bulkmail.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Fri, 11 Oct 2002 18:10:10 +0000 (UTC)
From: rdwillia@hgmp.mrc.ac.uk (Richard Williams)
Subject: Re: Getting off the ground (more newbie than newbie)
Message-Id: <ao7462$pqk$1@niobium.hgmp.mrc.ac.uk>

In article <3da5b5d0$1@news.microsoft.com>,
Jürgen Exner <jurgenex@hotmail.com> wrote:
>judywellsnow wrote:

>> I can run basic scripts that don't communicate with the
>> client (I'm using the current Activatestate release in Win98).
>
>So your real question is: "How can I test CGI scripts written in Perl
>without using a web server?" rather then "Getting off the ground(more newbie
>than newbie)".

This may be an interesting alternative to ActivePerl for your application:

http://www.indigostar.com/indigoperl.htm

It's a Perl distribution packaged together with an Apache webserver, and 
shouldn't require much configuration to do what you want.


Richard.



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

Date: 11 Oct 2002 13:50:26 -0700
From: milkfilk@yahoo.com (milkfilk)
Subject: Re: Hello World doesn't work in 5.8??
Message-Id: <90d82e70.0210111250.73de6abf@posting.google.com>

Different day, the problem goes away.

---------------------------------------------------
[milkfilk@computer /tmp]$ perl -e 'print "hi\n";'
hi
[milkfilk@computer /tmp]$ perl -e 'print "hi";'
hi[milkfilk@computer /tmp]$
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thanks to all, though it turned out to be a fluke.

Great suggestions, I've seen C do this when you don't send the
endline.  Makes starting out / learning REAL fun.  :P

I've made an appointment with my therapist.  He does good things.  He
can make the bad interpreter stop.


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

Date: Fri, 11 Oct 2002 20:02:42 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: HTTP Command help....?
Message-Id: <Pine.LNX.4.40.0210111953550.2114-100000@lxplus071.cern.ch>

On Oct 11, AB inscribed on the eternal scroll:

> the problem is, that when I enter the above url/command into a browser it
> returns results.

[...]

Are you pehaps looking for the HTTP response status of 204 ?

RFC2616 documents the HTTP protocol: look it up.  There used to be
problems with status 204 , but as far as I know, browsers generally
support it properly nowadays.

> keep in mind I am a noob without a programming background.

 ...if so, then you probably want to find the
comp.infosystems.www.authoring.cgi group.  Because you don't seem to
have a Perl language issue, so your question was really out of place
here.  Perlfaq9 says just a little bit about the CGI
http://www.perldoc.com/perl5.8.0/pod/perlfaq9.html

- but with a real CGI FAQ you would (if I've understood your question
right) already have the answer before now:
http://www.htmlhelp.org/faq/cgifaq.3.html#14
 "Can I run a CGI script without returning a new page to the browser?"




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

Date: Fri, 11 Oct 2002 14:54:13 -0500
From: Tommy Butler <usenet@atrixnet.com>
To: AGoodGuyGoneBad <agoodguygonebad@aol.com>
Subject: Re: Is there a way
Message-Id: <3DA72C65.90609@atrixnet.com>

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

=pod

    AUTHOR
       Tommy Butler <tommy @ atrixnet.com>
       phone: (817)-468-7716
       6711 Forest Park Dr
       Arlington, TX
            76001-8403

    COPYRIGHT   Tommy Butler. All rights reserved
    LISCENCE    This software is free, use/distribute under the GNU GPL.
    BUGS TO     Tommy Butler <perlmod @ atrixnet.com>

    INSTALLATION (2 easy steps)

    1. Place this script in your cgi bin directory.

    2. Change permissions on this script to 755 on linux/unix systems
       by using your FTP client software, or from a command line shell
       by typing the following command after entering the directory where
       this script is located:
          chmod -v 755 [ script name ]

    NOTE- You can find more free Perl code at The ooOPps Open Source
          Code Library  <URL: http://ooopps.sourceforge.net/pub/>

=cut

++$|;

use CGI qw( header param );

my($token) = qr/\Q%%%\E(.*?)\Q%%%\E/;
my($form)  = &form();

if (param('reset')) {

    $form =~ s/$token//g;
}
else {

    $form =~ s/$token/param($1)||''/ge;
}

print(header, $form);


sub form { <<__HTML__ }
<?xml version="1.0" encoding='ISO-8859-1'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html
  xmlns="http://www.w3.org/1999/xhtml"
  xml:lang="en"
  lang="en">
    <head>
       <title>Simple Perl CGI Form</title>
       <meta
        http-equiv="Content-Type"
        content="text/html; charset=ISO-8859-1" />
       <style
        type="text/css"
        xml:space="preserve">
          <!--

             HTML  {
                color: #000000; background-color: #FFFFFF;
                font-family: Verdana, sans-serif; font-size: 10pt;
             }

          -->
       </style>
    </head>
    <body>
       <div class="copy">
          <div>&#160;</div>
          <div>
             <h2>Welcome %%%NAME%%%</h2>
             <div>&#160;</div>
             <div style="padding: 0 0 0 20px;">
                <form method="POST">
                <table
                 cellspacing="1"
                 cellpadding="2"
                 border="0">
                   <tr>
                      <td
                       width="200"
                       class="small">Your Name &#160;</td>
                      <td><input
                       type="text"
                       name="NAME"
                       value="%%%NAME%%%"
                       size="25" /></td>
                   </tr>
                   <tr>
                      <td
                       width="200"
                       class="small">Your Favorite Fruit &#160;</td>
                      <td><input
                       type="text"
                       name="FRUIT"
                       value="%%%FRUIT%%%"
                       size="25" /></td>
                   </tr>
                   <tr>
                      <td
                       width="200"
                       class="small">Your Favorite Color &#160;</td>
                      <td><input
                       type="text"
                       name="COLOR"
                       value="%%%COLOR%%%"
                       size="25" /></td>
                   </tr>
                   <tr>
                      <td
                       width="200"
                       class="small">Your Favorite Animal &#160;</td>
                      <td><input
                       type="text"
                       name="ANIMAL"
                       value="%%%ANIMAL%%%"
                       size="25" /></td>
                   </tr>
                   <tr>
                      <td
                       width="200"
                       class="small">Your Favorite Website &#160;</td>
                      <td><input
                       type="text"
                       name="WEBSITE"
                       value="%%%WEBSITE%%%"
                       size="25" /></td>
                   </tr>
                </table>
                <br />
                <input
                 type="submit"
                 name="submit"
                 value="submit form" /> &#160;
                <input
                 type="submit"
                 name="reset"
                 value="reset form" />
                </form>
             </div>
          </div>
          <p>&#160;</p>
       </div>
    </body>
</html>
__HTML__



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

Date: Fri, 11 Oct 2002 14:54:46 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Multiple Pings/Second
Message-Id: <3DA71E76.7379B46@earthlink.net>

Damian James wrote:
> 
> On Fri, 11 Oct 2002 00:37:14 -0400, Benjamin Goldberg said:
> >...
> >On windows 95, if you run two perl scripts, one after another, and no
> >other processes start/die in between, it's quite likely that the pid
> >will be reused from one process to the next.  If you type:
> >   perl -e "print $$"
> >twice in a row, it will print the same number, twice in a row.
> 
> For no particular reason, I tried this verbatim in bash on cygwin on
> win2k. Of course, the double quotes mean $$ was interpolated in the
> shell before perl saw it. So obviously it was always the same.

On windows 95, (to be precise, on the command.com that comes with win95)
the dollar sign is not what's used to make the shell interpolate
environment variables -- the % character is.

> >How harmful is that?
[snip]
> ... so I guess it depends on what you're paranoid about.

Your example shows that on other OS's, process-ids aren't reused as they
are on windows95.  In other words, it means just about nothing.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Fri, 11 Oct 2002 16:57:37 -0500
From: "Kevin Vaughn" <binabik1@mail.com>
Subject: Re: Multiple Pings/Second
Message-Id: <uqeibkhe4rsr94@corp.supernews.com>

Somehow I have a feeling like this code would greatly help me out... if I
understood it.  I guess I'll have to break out the Perl book and start
learning =)

Thank all of you for your responses.  I wasn't expecting much, and I got a
lot.  Maybe I can get better at this stuff and repay you one of these days.

-Kevin

>
> Ok, revised code:
>
>    my $socket = ...;
>    my @hosts = ...; # 4 byte ip addresses.
>
>    my %hosts = map {; pack_sockaddr_in(0, $_) => $_ } @hosts;
>
>    my @checksums;
>    vec( my $svec = "", fileno($socket), 1 ) = 1;
>    my $expire = 30 + time;
>    my ($lastsent, $sentinel, $wvec) = scalar(each %hosts);
>    while( (my $seq = $expire - time) >= 0 ) {
>       my ($msg) = @{$checksums[$seq] ||= do {
>          $sentinel = $lastsent;
>          $wvec = $svec;
>
>          # code, subcode, checksum, pid, seq, [data ommited]
>          my $msg = pack("C2S3", 8, 0, 0, $$ & 0xFFFF, $seq);
>          my $chk = unpack("%32S*", $msg);
>          # $chk += ord(substr( $msg, -1 )) if length($msg) % 2;
>          $chk = ($chk & 0xFFFF) + ($chk >> 16) for 1..2;
>          $chk = 0xFFFF & ~$chk;
>          $msg = pack("C2S3", 8, 0, $chk, $$ & 0xFFFF, $seq);
>          [ $msg, $chk ];
>       }};
>
>       my $rvec = $svec;
>       (my ($n), $t) = select($rvec, $wvec, '', 0.5);
>       die "select failed: $!" if !defined($n) or $n < 0;
>       next if $n == 0; # timeout.
>
>       if( $wvec =~ tr/^\0// ) {
>          my $ip; $ip ||= each %hosts for 1..2;
>          send( $s, $msg, 0, $lastsent = $ip ) or die;
>          $wvec = "" if $ip eq $sentinel;
>       }
>
>       $rvec =~ tr/^\0// or next;
>
>       my $responder = recv( $s, my ($resp), 8, 0 )
>          or die "Error in recv: $!"; # shouldn't happen.
>
>       my ($port, $ip) = unpack_sockaddr_in($responder);
>       die "Expected port to be zero" if $port;
>       my ($rtype, undef, $rchk, $rpid, $rseq) =
>          unpack("C2S3", $resp);
>       # make sure this is a valid packet:
>       $rtype == 0 and $rpid == ($$ & 0xFFFF)
>          and defined $checksums[$rseq]
>          and $rchk == $checksums[$rseq][1] or next;
>
>       # remove this host from the %hosts hash, and
>       # if wasn't previously there, ignore the packet.
>       delete $hosts{$responder} or next;
>
>       # print out the fact that we've discovered
>       # that the host is alive.
>       print inet_ntoa($ip) . " is alive\n";
>
>       last unless %hosts;
>    } # end while(1)
>
>    print inet_ntoa($_)." is down\n" for values %hosts;
>
> [untested]
>
> The use of $sentinel and $lastsent is to ensure that the whole list is
> sent no more than once per second, and that the next time we start
> sending, we begin where we left off.




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

Date: Fri, 11 Oct 2002 15:01:15 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Net::FTP: Unexpected EOF on command channel
Message-Id: <3DA71FFB.62ED3DB7@earthlink.net>

jend wrote:
[snip problem with ftp disconnecting early]
> this is very interesting, yes our network has have some issues lately
> and i think its very possible that somehow there some network hiccup
> that just breaks the connetion, but i think either way, i will just
> use a 'rety' method if it fails..  thanks..

Don't *just* retry ... instead, try starting the download from where you
left off.  So if you download all but the last couple of bytes, then
just get those last couple of bytes.  Net::FTP supports this through the
third argument to the get method.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Fri, 11 Oct 2002 22:52:44 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: NEWBIE: Accessing FORM input with PERLSCRIPT
Message-Id: <Pine.LNX.4.40.0210112226450.2114-100000@lxplus071.cern.ch>

On Oct 10, Tennant inscribed on the eternal scroll:

> <flavell@mail.cern.ch> wrote:

> >Don't multipost.  I've x-posted to the other group where I found this
> >question had been posted separately, and set f'ups back to c.l.p.misc
> >
> Apologies, couldn't see from the archives which was the most suitable
> of the two groups to post a query of this nature...

But that wasn't the key point of my grumble.  (Although you didn't
seem to have anything in your query that was specific to Perl modules,
to be honest).

> header, I'm new to Perl and hence also extremely new to these
> newsgroups.

OK, let's try to clarify:

if and when it's appropriate to post the same article to more than one
newsgroup, you should post a single copy to all of the chosen groups
at the same time (so-called cross-post, sometimes abbreviated to
x-post) and not post a separate copy to each (so-called "multipost").
For extra bonus points, you should (if you can) suggest a single one
of the groups on the Followup-to: line so that discussion can then
focus on that group.

Just how you go about specifying these things is different from one
usenet-news client to another, so you'd need to check its
documentation to make sure.

> But if the answer everytime there is a stumbling block in PerlScript
> is to switch to an emulated server, what is the point of PerlScript
> existing in the first place?

It's a fair question, I must admit.  I can only remark that it doesn't
seem to be a topic area which comes up here too often, relatively
speaking.  Maybe one of the other contributors can offer a better
suggestion?

> $name=$window->document->MyForm->name->{'value'}
>
> However, my "stupid mistake" was to use a write() command to send a
> progress update to the console...hence my current window no longer
> contained the field I was trying to read.

That's excellent that you have not only found an answer but also
contributed it to the record.  If only more folks would do that!

I'm sorry that I wasn't able to help further on the substantive
question.

Good luck



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

Date: Fri, 11 Oct 2002 21:24:20 +0200
From: "Jan" <jan@nospam.harf.nl>
Subject: Problems with MSIE in combination with MAC not showing Perl generated HTML
Message-Id: <3da72578$0$11215$1b62eedf@news.euronet.nl>

Dear experts,

On a WinNT machine I'm running a webserver which runs a very simple script:

print "Content-type text/html\nPragma: no-cache\n\n";

print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
\"http://www.w3.org/TR/html4/loose.dtd\">\n";

print "<HTML><HEAD><TITLE>Testing forms</TITLE>\n";
print "</HEAD><BODY>\n";
print "Blablabla\n";

print "</BODY></HTML>\n";

This script when run produces a fine output on every browsers on every
operating system, except MSIE for the MAC, be it OSX or the previous
version. You can run this script at:
http://80.60.28.57/top1000/secure/cgi-bin/formtest.pl to see that it
normally should work.

We are totally in the dark why it doesn't show any output on the MAC. After
typing in the address in the location bar, the cursors starts turning for a
second or two and nothing happens..... We've tried everything up to now.
Clearing cache, renaming files, shutting down and restarting MSIE, but to no
avail.

Anybody anything?

Thanks for your help,

Jan





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

Date: Fri, 11 Oct 2002 21:21:33 +0100
From: "DMB" <david.bates2@ntlworld.com>
Subject: Regular Expressions Problem
Message-Id: <RoGp9.1657$w1.232618@newsfep1-win.server.ntli.net>

I'm just learning perl and I have a problem. I want to write a regular
expression that insists that the number of left brackets in the pattern
matches exactly the number of right brackets. So (he(llo wo)rld) would match
but (he(llo wo)rld wouldn't. This sounds pretty simple but from whats in the
book I was reading I can't think how to do it which is why I've been trying
for the last half an hour or so. How can it be done? Thanks.




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

Date: Fri, 11 Oct 2002 13:32:24 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Regular Expressions Problem
Message-Id: <3da73559@news.microsoft.com>

DMB wrote:
> I'm just learning perl and I have a problem. I want to write a regular
> expression that insists that the number of left brackets in the
> pattern matches exactly the number of right brackets. So (he(llo
> wo)rld) would match but (he(llo wo)rld wouldn't. This sounds pretty
> simple but from whats in the book I was reading I can't think how to
> do it which is why I've been trying for the last half an hour or so.
> How can it be done?

It cannot be done because the language needed to describe nested brackets is
not regular any more.
Please see "perldoc -q balanced" for further details.

jue




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

Date: 11 Oct 2002 13:53:07 -0700
From: tmuldoon@spliced.com (Tavish Muldoon)
Subject: STDIN and choices on screen?
Message-Id: <e2470f35.0210111253.5204902c@posting.google.com>

Hello,

I have a screen and I want to prompt the users for 1 of 3 choices.

Let's say I have a screen that says:

Choose 1 of the 3 options:
1=Turkey
2=Steak
3=Apple

Choose one:

What would be a good method to code this?

Is there a perl CASE statement or am I doing a bunch of if-then statemetents?


i.e.

$choice=<STDIN>;
if ($choice="1") {
   $choice="Turkey";
}
else choice="2"...etx



Ultimately I am going to have many choices (10-20).

Any suggestions on how to tackle this efficiently?

Thanks,

Tmuld.


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

Date: Fri, 11 Oct 2002 14:11:28 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: STDIN and choices on screen?
Message-Id: <3da73e81$1@news.microsoft.com>

Tavish Muldoon wrote:
> I have a screen and I want to prompt the users for 1 of 3 choices.
> Let's say I have a screen that says:

What do you mean with "screen"?

> Choose 1 of the 3 options:
> 1=Turkey
> 2=Steak
> 3=Apple
>
> Choose one:
>
> What would be a good method to code this?

Untested, just to give you an idea:

@choices = ('Turkey', 'Steak', 'Apple');
my $i = 1;
for (@choices) {
    print "$i=$_\n";
    $i++;
}
my $selected = <>;
$choice = $choices[$selected-1];
#error handling left as an excercise

> Is there a perl CASE statement or am I doing a bunch of if-then
> statemetents?

Please see "perldoc -q case":
  How do I create a switch or case statement?

jue




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

Date: Fri, 11 Oct 2002 20:12:46 +0200
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: STDOUT_TOP printing funny character
Message-Id: <3226308.9Q6RAg9g3N@nyoga.dubu.de>

aaron smith wrote:

> Hi, the following code prints an ankh before "media [id]". I've also
> tried a blank line first and it prints the ankh on the blank line.

This ankh or "female symbol" is a DOS character representation of the FF 
(form feed) character, ASCII code 12(dec).  It is supposed to appear at 
the beginning of every new page formatted by 'write'.

,----[ perlform(1) ]
| "The string output before each top of page (except the first) is 
| stored in $^L ($FORMAT_FORM­FEED)."
`----

,----[ perlvar(1) ]
| IO::Handle->format_formfeed EXPR
| $FORMAT_FORMFEED
| $^L     What formats output as a form feed.  Default is \f.
`----

  Apparently, you're not directing the output to a printer where you 
should see a real form feed.  (This should also work on an ANSI aware 
DOS box, but I don't have a DOS/Win box to verify that.)

> How can I get rid of the extra character?

Setting $^L to something different from \f might help.

See perlform(1), the 'write' entry in perlfunc(1) and perlvar(1).

Ciao,
        Harald
-- 
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
"I believe we are on an irreversible trend toward more freedom and
democracy - but that could change."
                -- George W. Bush Jr.


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

Date: Fri, 11 Oct 2002 16:00:14 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: STDOUT_TOP printing funny character
Message-Id: <3DA72DCE.1C7CED81@earthlink.net>

aaron smith wrote:
> 
> Hi, the following code prints an ankh before "media [id]". I've also
> tried a blank line first and it prints the ankh on the blank line. How
> can I get rid of the extra character?
[snip]

Try doing:
   $^F = "=" x 69 . "\n";
or:
   $^F = `cls`;

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: Fri, 11 Oct 2002 16:22:37 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Switching from Python to Perl
Message-Id: <3DA7330D.3F4DC602@earthlink.net>

Kondwani Spike Mkandawire wrote:
> Thomas Guettler wrote:
> > Hi!
> >
> > There are a lot of people who switched from
> > perl to python. Is there anyone who switched
> > from python to perl?
> 
> I'm trying to switch to Perl from Python...
> Still in the process of learning though...
> I was told by someone with great experience in
> both that because Python is still young there
> will be a lot of deprecation as the language is
> continuously updated and as bugs are being fixed.
> However Perl is 15 or so years old and has
> already undergone a lot of fixes and updates
> hence I was told ought to be more stable...

Although I have no clue how stable Python is, or how much deprecation is
taking place, I can say that perl, particularly 5.6.1, is quite stable.

Perl 5.8.0 hasn't been out for long, so I can't comment much about it
except to say that it handles unicode, and multiple input and output
encodings, far better than prior perls did.

-- 
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
 ."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]


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

Date: 11 Oct 2002 12:35:42 -0600
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: undef == true?
Message-Id: <3da719fe@news.mhogaming.com>

peter <peter@nospam.calweb.com> wrote:
> I've encountered several cases where an undefined var or a var assigned 
> the value undef evaluated true or compared as true.  Does anyone know 
> the reason behind this?  I find it plain annoying.
> 

Can you give an example?

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

Date: Fri, 11 Oct 2002 18:34:23 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: undef == true?
Message-Id: <PQEp9.3326$EV5.282396686@newssvr13.news.prodigy.com>

peter <peter@nospam.calweb.com> wrote:
> I've encountered several cases where an undefined var or a var assigned 
> the value undef evaluated true or compared as true.  Does anyone know 
> the reason behind this?  I find it plain annoying.

Could you mean a var assigned the string "undef" instead? 

Could you construct a small script that shows an undefined value that
compares as true?  Without an example, I'd have to say that it doesn't
happen.

-- 
Darren Dunham                                           ddunham@taos.com
Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: Fri, 11 Oct 2002 15:33:13 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: undef == true?
Message-Id: <slrnaqedc9.3gg.tadmc@magna.augustmail.com>

peter <peter@nospam.calweb.com> wrote:

> I've encountered several cases 


Can we see even one of those cases?

We cannot fix code that we have not seen.


> where an undefined var or a var assigned 
> the value undef evaluated true or compared as true.  


If the code is similar to what's in your Subject,
then it is _supposed_ to evaluate to true, since zero
_is_ numerically equal to zero.


> Does anyone know 
> the reason behind this?  


Yes, and perl itself will tell you, but only if you ask to be told.

You should always enable warnings when developing Perl code...


> I find it plain annoying.


 ...unless you like to be annoyed by common mistakes.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 11 Oct 2002 20:59:12 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: Why is 'defined @x' deprecated?
Message-Id: <ao7e30$i94$1@reader1.panix.com>



If I use an expression like "if(defined @x)" Perl issues a warning:

  defined(@array) is deprecated at foo.pl line 99.
          (Maybe you should just omit the defined()?)

The advice the warning gives (omitting defined()) is not useful in
this case, since I want to distinguish between cases in which @x has
not been assigned to and cases where @x happens to have zero elements.
Omitting defined() would lose this distinction.  Is there another
(non-deprecated) way of doing what I want to do without using
defined()?

Thanks,

h



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

Date: Fri, 11 Oct 2002 21:04:29 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Why is 'defined @x' deprecated?
Message-Id: <x7u1jsk7qa.fsf@mail.sysarch.com>

>>>>> "DW" == Da Witch <heather710101@yahoo.com> writes:

  DW> If I use an expression like "if(defined @x)" Perl issues a
  DW> warning:

  DW>   defined(@array) is deprecated at foo.pl line 99.  (Maybe you
  DW> should just omit the defined()?)

  DW> The advice the warning gives (omitting defined()) is not useful in
  DW> this case, since I want to distinguish between cases in which @x
  DW> has not been assigned to and cases where @x happens to have zero
  DW> elements.  Omitting defined() would lose this distinction.  Is
  DW> there another (non-deprecated) way of doing what I want to do
  DW> without using defined()?

why do you want to know that difference? defined only reports whether
the aggregate has ever had some memory allocated for data. it is not
useful since that is below the hood from the rest of perl. if you
explain your need for this info and the code around it, i am sure there
is a better way to do it.

the biggest reason it is bad is that it leads newbies to think defined
on an aggregate will tell you if it has any elements in it which as you
seem to know is wrong. this is now deprecated for that reason as no one
should want to use defined for the allocation reason.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.

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 V10 Issue 3956
***************************************


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