[18640] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 808 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 1 03:05:51 2001

Date: Tue, 1 May 2001 00:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <988700707-v10-i808@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 1 May 2001     Volume: 10 Number: 808

Today's topics:
    Re: Another regexp question (Craig Berry)
    Re: AUTOLOAD Clarification (Sweth Chandramouli)
    Re: Chicago Perl Consultants Needed <uri@sysarch.com>
    Re: Chicago Perl Consultants Needed (Eric Bohlman)
        entries per page <troyr@vicnet.net.au>
    Re: GD/TrueType weirdness. <jim_spencer@intuit.com>
    Re: Good editor for perl <linuxos@ananzi.co.za>
        RE: How can I stop at the frist matching <antic@MailAndNews.com>
        RE: How can I stop at the frist matching <antic@MailAndNews.com>
        misleading taint error message with DBI? (William Herrera)
    Re: misleading taint error message with DBI? (Damian James)
    Re: one-line stderr, stdout redirection <uri@sysarch.com>
    Re: one-line stderr, stdout redirection (Randal L. Schwartz)
    Re: pointer/reference question (Garry Williams)
        R-E Perl Code <cave@pertus.com.pl>
    Re: Remove Adult Files with Perl (BUCK NAKED1)
    Re: simple problem (ugh) <krahnj@acm.org>
    Re: simple problem (ugh) <joe+usenet@sunstarsys.com>
    Re: simple problem (ugh) (Damian James)
    Re: simple problem (ugh) <krahnj@acm.org>
    Re: System Call within Daemon - TAKE 2 (Garry Williams)
    Re: System Call within Daemon - TAKE 2 <uri@sysarch.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 01 May 2001 06:03:22 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Another regexp question
Message-Id: <teskdao11cn54f@corp.supernews.com>

David H. Adler (dha@panix2.panix.com) wrote:
: In article <9bv4mi$fh7$1@news8.svr.pol.co.uk>, Ciaran McCreesh wrote:
: > 
: > And it's regex, not regexp :)
: 
: As much as I would like to agree with you, much usage is against us.  A
: number of modules on CPAN use Regexp,

Yes, but one must also bear in mind that 'regexp' has a silent 'p'.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Tue, 01 May 2001 05:07:35 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: AUTOLOAD Clarification
Message-Id: <rwrH6.56451$122.10738453@news1.rdc1.md.home.com>

In article <3aed9dc1$0$26606@wodc7nh0.news.uu.net>,
Jason Hurst <jasonh@colubs.com> wrote:
>From my understanding when you use autoload, perl first goes through all of
>@ISA THEN hits the autoload in your current module.  Does this mean that it
>stops there or will it continue to go through @ISA looking for autoloads?
	Yes.
	(As I understand it, Perl checks for predefined methods, 
followed by autoloaded methods, and for each of those checks, it looks, in
order, first to the current module, followed by a depth-first recursive
search through @ISA, followed by a check of UNIVERSAL.  So, to answer your
question more helpfully: "the latter", and try not to ask "or" questions of
people in the habit of thinking in Boolean, especially if you really mean
"xor".  :) )

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: Tue, 01 May 2001 04:21:12 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Chicago Perl Consultants Needed
Message-Id: <x7r8y9em2d.fsf@home.sysarch.com>

>>>>> "WWJDB" == W W J D Black <jdblack@black.metronet.com> writes:

  WWJDB> 
  WWJDB> Hash: SHA1

for this, you needed pgp signing?

  WWJDB> In article <9cjqj9$rs9@spamz.news.aol.com>, Jason C. Hill
  WWJDB> <jhill@technoslave.net> wrote:

  WWJDB> }Don't make me skin you alive for making these lame posts about
  WWJDB> potatoes!!!  }

  WWJDB> Didn't Dan Q. get in trouble for spelling taters like that?

no, he got in trouble for spelling the singular with a trailing e (the
plural does have an e). in fact he corrected a kid in a classroom and
added the e to the word on the blackboard while on camera. a classic
moment.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: 1 May 2001 05:23:36 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Chicago Perl Consultants Needed
Message-Id: <9clh8o$l94$1@bob.news.rcn.net>

Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "WWJDB" == W W J D Black <jdblack@black.metronet.com> writes:
>   WWJDB> Didn't Dan Q. get in trouble for spelling taters like that?

> no, he got in trouble for spelling the singular with a trailing e (the
> plural does have an e). in fact he corrected a kid in a classroom and
> added the e to the word on the blackboard while on camera. a classic
> moment.

Which would have gone virtually unnoticed except that a large part of 
Quayle's political shtick was having the "courage" to point out and 
criticize other people's shortcomings ("poverty is primarily a poverty of 
values", etc.).  Those who proclaim their righteousness in holding others 
to high standards have to reasonably expect that the bar is going to be 
placed well into the sky when it comes to evaluating their own behavior.



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

Date: Tue, 1 May 2001 16:29:26 +1000
From: "Troy Boy" <troyr@vicnet.net.au>
Subject: entries per page
Message-Id: <cMsH6.3229$VM5.104771@ozemail.com.au>

Hi there..
I was wondering if there was a perl cgi module that could seperate rows in a
hash per page..

For example..say i had 40 rows in my hash array..and i wanted it to show the
first 10....then click on a hyperlink to retrieve the next 10 etc.

Is there a module for that around the place

Thanks in advance

--
----------------------------------------------------------------
Troy Rasiah
Melbourne, Aus




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

Date: Mon, 30 Apr 2001 17:31:53 -0700
From: Jim Spencer <jim_spencer@intuit.com>
Subject: Re: GD/TrueType weirdness.
Message-Id: <3AEE03F9.DCF93885@intuit.com>

Dan,
If it makes you feel any better, I have the exact same problem...I was feeling pretty excited
when I saw your solution, but it looks like that doesn't really work.  Aargh.  I guess we'll
either have to compile from the source or wait for ActiveState to straighten this out.

Jim Spencer



Dan Harding wrote:

> > I dont think so... I cant say for sure in windoze what version of GD.pm is installed, but
> > I do know that in unix the default version is not compiled with truetype support.  So
> > chances are great that you need to rebuild the GD library to support truetype.  Sadly,
> > I can tell you exactly how to do this in unix, but I have no clue in windows.
> >
> > You can verify this by using the can_do_ttf() method included in the GD::Text module, but
> > I am 99.9% sure this is the problem.
> >
> > The docs in GD::Text will tell you about this as well.
>
> TrueType support is indeed turned on. can_do_ttf returns true.
>
> It's bizarre. It's obviously finding the .ttf file (or the procedure
> would break).
> The $image->stringTTF() routine is "printing" the correct number of
> characters, just
> boxes....
>
> AUGH!



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

Date: Tue, 1 May 2001 09:02:41 +0200
From: Daneel van Tonder <linuxos@ananzi.co.za>
Subject: Re: Good editor for perl
Message-Id: <9cln3k$95a$1@ctb-nnrp1.saix.net>

Aaron Gross wrote:

You could also us GNU Emacs for win32.

> Ultraedit!
> 
> Makes your perl code pretty in colors, plus does other stuff like html. :)
> "Super-Simon" <simon@super-simon.com> wrote in message
> news:9c1csm$loh$1@news1.xs4all.nl...
>> Hi all,
>>
>> I'm searching for a good, fast editor with syntax highlighting for perl
>> (CGI) for use under Windows 2000 / Windows 98 (I use windowz only for
>> editing scripts, scripts runs on Linux-server). It has to be free (I'm a
>> poor student ;-)
>>
>> Grtz,
>>
>> Super-Simon
>>
>>
> 
> 
> 



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

Date: Tue, 1 May 2001 01:51:49 -0400
From: Ann Tica <antic@MailAndNews.com>
Subject: RE: How can I stop at the frist matching
Message-Id: <3B157EF2@MailAndNews.com>

Thanks heaps.
Antic
>===== Original Message From Bart Lateur <bart.lateur@skynet.be> =====
>Ann Tica wrote:
>
>>I have a variable $var
>>and I want to extract "8.1.0" from the line if the line starts with
>>name[789]
>>My codes return "7.2.3" ?!
>
>>name8 line2 sls sl sl sls 8.1.0.2 slsl 7.2.3.1 ddd
>
>>$var =~ /^(.*)(name[789].* )([789]\.\d\.\d)/m;
>>print "$3\n";
>
>Make the .* right after "name[789]" non-greedy, by adding a question
>mark:
>
>$var =~ /^(.*)(name[789].*? )([789]\.\d\.\d)/m;
>
>--
>	Bart.

------------------------------------------------------------
 Get your FREE web-based e-mail and newsgroup access at:
                http://MailAndNews.com

 Create a new mailbox, or access your existing IMAP4 or
 POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------



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

Date: Tue, 1 May 2001 01:52:46 -0400
From: Ann Tica <antic@MailAndNews.com>
Subject: RE: How can I stop at the frist matching
Message-Id: <3B1581A7@MailAndNews.com>

Thanks.

>===== Original Message From Ren Maddox <ren@tivoli.com> =====
>On Mon, 30 Apr 2001, bart.lateur@skynet.be wrote:
>
>> Ann Tica wrote:
>>
>>>I have a variable $var
>>>and I want to extract "8.1.0" from the line if the line starts with
>>>name[789]
>>>My codes return "7.2.3" ?!
>>
>>>name8 line2 sls sl sl sls 8.1.0.2 slsl 7.2.3.1 ddd
>>
>>>$var =~ /^(.*)(name[789].* )([789]\.\d\.\d)/m;
>>>print "$3\n";
>>
>> Make the .* right after "name[789]" non-greedy, by adding a question
>> mark:
>>
>> $var =~ /^(.*)(name[789].*? )([789]\.\d\.\d)/m;
>
>And keep in mind that since you have a ".*" at the beginning, multiple
>occurrences of "name[789]" on the line will also cause a similar
>problem.  Plus, you're forcing the regex engine to do a lot of
>(probably unnecessary) backtracking.
>
>Above, you say "if the line starts with name[789]".  If that is really
>the condition, then you probably don't need the "(.*)" on the front at
>all.
>
>--
>Ren Maddox
>ren@tivoli.com

------------------------------------------------------------
 Get your FREE web-based e-mail and newsgroup access at:
                http://MailAndNews.com

 Create a new mailbox, or access your existing IMAP4 or
 POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------



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

Date: Tue, 01 May 2001 05:06:16 GMT
From: posting.account@lynxview.com (William Herrera)
Subject: misleading taint error message with DBI?
Message-Id: <3aee4444.57748845@west.usenetserver.com>

Why, when I use potentially tainted environment variables in building an
otherwise valid query with DBD::CSV, do I get the bizarre and misleading error
below:

DBD::CSV::Statement=HASH(0x1c9bf18) is not a valid SQL::Statement object 

instead of the usual "Insecure dependency in ... while running with -T switch "
error?

I realize that Real Perl Programmers always avoid tainting arguments :), 
but I still think that the above DBI error message is so vague as to be a bug.

---
The above from: address is spamblocked. Use wherrera (at) lynxview (dot) com for the reply address.



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

Date: 1 May 2001 06:31:32 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: misleading taint error message with DBI?
Message-Id: <slrn9esluf.1d2.damian@puma.qimr.edu.au>

William Herrera chose Tue, 01 May 2001 05:06:16 GMT to say this:
>Why, when I use potentially tainted environment variables in building an
>otherwise valid query with DBD::CSV, do I get the bizarre and misleading error
>below:
>
>DBD::CSV::Statement=HASH(0x1c9bf18) is not a valid SQL::Statement object 
>
>instead of the usual "Insecure dependency in ... while running with -T switch "
>error?
>

Err, you have a reason to believe this has something to do with taint
checking? Looks pretty straightforward to me -- somewhere, somehow you have
a typo that is including a reference to a hash in your sql statement,
rather than some value in that hash. Or there's a typo with some DBD::CSV
object (that happens to be implemented as a hashref). Either way, it looks
like a syntax error to me. I'd say, double check your code.

NB:
    my $blah = { blah => 'blah' };
    print "$blah->{blah}\n";
    print "$blah\n";

>I realize that Real Perl Programmers always avoid tainting arguments :),
>but I still think that the above DBI error message is so vague as to be a
bug.
>

Okay, you recognise it's a DBI error, not a tainting one. I still don't get
why you think it's a taint-related error.

HTH,

Cheers,
Damian
-- 
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...


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

Date: Tue, 01 May 2001 04:16:56 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: one-line stderr, stdout redirection
Message-Id: <x7u235em9i.fsf@home.sysarch.com>

>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:

>>>>> "Anno" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
  Anno> I seem to remember (and books have a way to be where you aren't), that
  Anno> APP discusses this at one point.  File descriptors below some kernel
  Anno> constant (something about the maximum system file descriptor) are
  Anno> more stable (in probably just this sense).  And no, I couldn't possibly
  Anno> be more vague.

  RLS> Sure you could.

  RLS> "File Descriptors are used in some way, maybe for this, I'm not sure."

  RLS> {grin}

  RLS> But while I'm not sure what piece of documentation ensures it,
  RLS> I'm very sure that I know somehow that STDIN is always fileno 0,
  RLS> STDOUT always 1, and STDERR 2.  Even when reopened as such.

not exactly.

perl -le 'close STDIN; open FOO, "/dev/null"; open STDIN, "/dev/tty"; print fileno( \*FOO ), " ", fileno( \*STDIN )'
0 3

perl -MIO::Socket -le 'close STDIN; open FOO, "/dev/null";*STDIN = IO::Socket::INET->new( "localhost:8080" ); print fileno( \*FOO ), " ", fileno( \*STDIN )'
0 3

the rule is simpler. a new file descriptor (file or socket) uses the
lowest available integer in the fd table in the process.

this is from open(2) on solaris:

	The  open() function returns a file descriptor for the named
	file that is the lowest file descriptor not  currently  open
	for  that  process.


that behavior has been in unix for a long time and is depended upon.

when you fork/exec, you do reopens so that the new proc gets its std
handles to be the desired handles/sockets. this works only if you
haven't messed with the parent's handles and you shouldn't do that by
name but only by fd number to be safe.

also this connects with another thread on why a socket stays open across
a for/exec. the dup(2) call says:

	The new file descriptor is set to remain  open  across  exec
	functions (see fcntl(2)).

	The file descriptor returned is the lowest one available.


so a typical fork/exec/ in a shell does dups to copy the new handles
(either the parents, pipes, sockets, or redirected files) into
stdin/stdout/stderr for the child and they stay open after the exec
while all other handles will get closed (unless you clear the close on
exec flag).

hmm, open(2)  says the fd's it returns have close on exec
cleared. someone in the shell does this. in bash i found code that sets
the close on exec flag for all fds > 2.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: 30 Apr 2001 22:00:15 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: one-line stderr, stdout redirection
Message-Id: <m1snip64v4.fsf@halfdome.holdit.com>

>>>>> "Uri" == Uri Guttman <uri@sysarch.com> writes:

RLS> But while I'm not sure what piece of documentation ensures it,
RLS> I'm very sure that I know somehow that STDIN is always fileno 0,
RLS> STDOUT always 1, and STDERR 2.  Even when reopened as such.

Uri> not exactly.

Uri> perl -le 'close STDIN; open FOO, "/dev/null"; open STDIN, "/dev/tty"; print fileno( \*FOO ), " ", fileno( \*STDIN )'
Uri> 0 3

You cheated.  You closed STDIN, so it no longer has its magical bit in
the stash.

I'm talking about "reopening STDIN".  There's some special code
that ensures that open STDIN forces no loss of fileno 0.

Uri> the rule is simpler. a new file descriptor (file or socket) uses the
Uri> lowest available integer in the fd table in the process.

Uh, I know that.  And there's some code in Perl specifically to use
that rule to ensure that open STDERR works and open STDIN works and so
on.

Uri> that behavior has been in unix for a long time and is depended upon.

In Unix, yes.  And Perl does specific things, unless you deliberately
thwart them, which you did.

The most interesting problem is:

        open STDERR, ">>foo" or die "..."

which still works because foo is actually opened on a temp descriptor,
and if it succeeds, fd-2 is closed, and the temp fd is duped to fd-2.

There's special code in there to do that, I'm told.  No I haven't
seen it with my own eyes.  It just does "the right thing".

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Tue, 01 May 2001 04:05:02 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: pointer/reference question
Message-Id: <slrn9esdfe.ci3.garry@zfw.zvolve.net>

On 30 Apr 2001 18:26:37 +0100, nobull@mail.com <nobull@mail.com> wrote:
> garry@ifr.zvolve.net (Garry Williams) writes:
> 
>> On Sat, 21 Apr 2001 23:11:46 -0500, xris <xris@dont.send.spam> wrote:
>> 
>> > In article <9btbef$e2r$1@mamenchi.zrz.TU-Berlin.DE>,
> 
>> > My main concern is that I'll forget the extra $ to dereference something 
>> > and it'll cost me hours of bug testing to find the typo.  :)
>> 
>>   use warnings;
>>   use strict;
>> 
>> Program without fear.  
> 
> Bogus!  I always wear a seat-belt but this this does not mean that I
> expect it to protect me in a side-impact or that I drive without fear
> (or at least due caution).

Okay, I could have included a smiley.  :-)  

> xris is talking about doing something like: $foo{$bar} when he meant
> to write $foo{$$bar}.  In this case warnings and strict are usually no
> help because the implicit stringification of a reference does not
> yeild a warning.

Hmmm.  I'm not sure how you got that from his posts, but I agree it
wouldn't yield a warning.  I imagine it would not take "hours of bug
testing" to track down, either.  Also the more common $bar instead of
$$bar in most other contexts will result in a fatal error.

-- 
Garry Williams


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

Date: Tue, 01 May 2001 08:03:03 +0200
From: Mirek Rewak <cave@pertus.com.pl>
Subject: R-E Perl Code
Message-Id: <t2kset4k4p2obkcvkrvqjf29r8hjvc8s23@4ax.com>

Hi,
Is there a tool for reverse-engeneeing Perl code? I know that there is
an add-in for WithClass but it don't work in WithClass 2000 (it seems
that it was build for version 99 but there is only 2000 to download).
I would prefer tool for Rational Rose but I didn't found.

Pozdrowienia
Mirek Rewak
cave@pertus.com.pl


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

Date: Mon, 30 Apr 2001 23:54:32 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Remove Adult Files with Perl
Message-Id: <13383-3AEE4188-268@storefull-245.iap.bryant.webtv.net>

Sorry, Tad... I usually DO look first. I just can't find things at
Googley-goo as well as I could at deja.  --Dennis



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

Date: Tue, 01 May 2001 04:08:58 GMT
From: John W Krahn <krahnj@acm.org>
Subject: Re: simple problem (ugh)
Message-Id: <3AEE36E5.9C568E97@acm.org>

Keith G wrote:
> 
> Anyone see what the problem is with this? No
> matter what the value of $answer (be it "y", "n"
> or "d"), the script prints out YND. Doesn't a
> pair of ='s compare a pair of scalars? Help!
> 
> .....
> # begin code snip
> $answer=param("poll");
> 
> if ($answer == "y") {print "Y";}
> if ($answer == "n") {print "N";}
> if ($answer == "d") {print "D";}

if    ( lc( substr( $answer, 0, 1 ) ) eq 'y' ) { print 'Y' }
elsif ( lc( substr( $answer, 0, 1 ) ) eq 'n' ) { print 'N' }
elsif ( lc( substr( $answer, 0, 1 ) ) eq 'd' ) { print 'D' }

# or

if    ( $answer =~ /^y/i ) { print 'Y' }
elsif ( $answer =~ /^n/i ) { print 'N' }
elsif ( $answer =~ /^d/i ) { print 'D' }


John


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

Date: 01 May 2001 01:54:29 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: simple problem (ugh)
Message-Id: <m3pudtzka2.fsf@mumonkan.sunstarsys.com>

John W Krahn <krahnj@acm.org> writes:

> if    ( lc( substr( $answer, 0, 1 ) ) eq 'y' ) { print 'Y' }
> elsif ( lc( substr( $answer, 0, 1 ) ) eq 'n' ) { print 'N' }
> elsif ( lc( substr( $answer, 0, 1 ) ) eq 'd' ) { print 'D' }

Here's another way to write that using a dispatch table:

  sub switch {
    local $_ = shift;
    &{ shift()->{$_} || return };
  }

  switch lc(substr $answer, 0, 1)  => 
    {
        y => sub { print "Y" },
        n => sub { print "N" }, 
        d => sub { print "D" },
        q => sub { print "\u$_"},       # $_ = lc substr $answer,0,1 
        p => sub { print shift },       # prints $extra_args[0]
    },
    @extra_args;

-- 
Joe Schaefer    "The only thing necessary for the triumph of evil is for good
                                     men to do nothing."
                                               -- Edmund Burke


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

Date: 1 May 2001 06:12:34 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: simple problem (ugh)
Message-Id: <slrn9eskqt.1d2.damian@puma.qimr.edu.au>

[
	please don't quote the entire article to which you are responding
	responding style has been adjusted
]

Keith G chose Mon, 30 Apr 2001 23:34:34 -0400 to say this:
>"Bob Walton" <bwalton@rochester.rr.com> wrote in message news:3AEE2900.A0FE0FF1@rochester.rr.com...
>> Keith G wrote:
>> > ...
>> > $answer=param("poll");
>> >
>> > if ($answer == "y") {print "Y";}
>> > if ($answer == "n") {print "N";}
>> > if ($answer == "d") {print "D";}
>> >
>> ...
>> You want to use the "eq" operator to do a string compare, as in:
>>
>>   if ($answer eq "y") {print "Y";}
>> ...
>
>thanks everyone - this fixes my headache!

As has been pointed out, you could help yourself by using the -w command
line switch to enable warnings, and the 'strict' pragma to assist in the
detection of errors like this one. 

#!/path/to/perl -w
use strict;

You might also want to consider a different approach:

print uc( param('poll') );

or more generally (if you are doing something other than changing to
uppercase), use a lookup table:

my %lookup = (
	y	=> 'Y',
	n	=> 'N'
	d	=> 'D'
);
print $lookup{ param('poll') };

HTH,

Cheers,
Damian
-- 
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...


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

Date: Tue, 01 May 2001 06:36:26 GMT
From: John W Krahn <krahnj@acm.org>
Subject: Re: simple problem (ugh)
Message-Id: <3AEE5977.98906E9F@acm.org>

Joe Schaefer wrote:
> 
> John W Krahn <krahnj@acm.org> writes:
> 
> > if    ( lc( substr( $answer, 0, 1 ) ) eq 'y' ) { print 'Y' }
> > elsif ( lc( substr( $answer, 0, 1 ) ) eq 'n' ) { print 'N' }
> > elsif ( lc( substr( $answer, 0, 1 ) ) eq 'd' ) { print 'D' }
> 
> Here's another way to write that using a dispatch table:

There's _always_ another way to do it (what _is_ that acronym?)


>   sub switch {
>     local $_ = shift;
>     &{ shift()->{$_} || return };
>   }
> 
>   switch lc(substr $answer, 0, 1)  =>
>     {
>         y => sub { print "Y" },
>         n => sub { print "N" },
>         d => sub { print "D" },
>         q => sub { print "\u$_"},       # $_ = lc substr $answer,0,1
>         p => sub { print shift },       # prints $extra_args[0]
>     },
>     @extra_args;


use Switch;

switch ( lc( substr $answer, 0, 1 ) ) {

    case 'y' { print "Y" }
    case 'n' { print "N" }
    case 'd' { print "D" }
    else     { print "wrong answer, try again." }
}


And you don't have all those commas getting in the way. :-)


John


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

Date: Tue, 01 May 2001 04:31:41 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: System Call within Daemon - TAKE 2
Message-Id: <slrn9esf1d.cid.garry@zfw.zvolve.net>

On Tue, 01 May 2001 03:37:07 GMT, Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
> 
>  AS> According to Michael Vera  <mxvera@qwest.com>:
> 
>  >> What I need to do is simply fork and exec a system call withOUT the
>  >> child inheriting ownership of the socket.
> 
>  AS> Close the socket in the child.  It's a good habit to close un-needed
>  AS> filehandles of any sort after a fork.
> 
> in general during an exec only stdin/stdout/stderr stay open. there is a
> flag on fidle descriptors called close on exec (see fctnl(2)) which is
> usually set on new descriptors except those three. so an exec normally
> closes all others. the problem probably lies elsewhere.

Okay, maybe it's a standard file that the OP is concerned with.  In
that case he has to dup it to save it and reopen it on /dev/null
before exec'ing and restore it in the parent to continue using it.
(perlopentut describes dup'ing.)  

I seem to remember the close-on-exec flag being documented in Perl
somewhere, but I can't find a reference now.  Maybe it was Camel 1 or
2...

-- 
Garry Williams


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

Date: Tue, 01 May 2001 04:43:21 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: System Call within Daemon - TAKE 2
Message-Id: <x7n18xel1g.fsf@home.sysarch.com>

>>>>> "GW" == Garry Williams <garry@ifr.zvolve.net> writes:

  GW> I seem to remember the close-on-exec flag being documented in Perl
  GW> somewhere, but I can't find a reference now.  Maybe it was Camel 1 or
  GW> 2...

grep exec *.pod | grep close

from perlfunc:

open:

NOTE: On any operation that may do a fork, any unflushed buffers remain
unflushed in both processes, which means you may need to set C<$|> to
avoid duplicate output.  On systems that support a close-on-exec flag on
files, the flag will be set for the newly opened file descriptor as
determined by the value of $^F.  See L<perlvar/$^F>.


pipe:

On systems that support a close-on-exec flag on files, the flag will be set
for the newly opened file descriptors as determined by the value of $^F.
See L<perlvar/$^F


from perlvar:

 $^F     The maximum system file descriptor, ordinarily 2.
             System file descriptors are passed to exec()ed
             processes, while higher file descriptors are not.
             Also, during an open(), system file descriptors are
             preserved even if the open() fails.  (Ordinary file
             descriptors are closed before the open() is
             attempted.)  Note that the close-on-exec status of a
             file descriptor will be decided according to the
             value of $^F when the open() or pipe() was called,
             not the time of the exec().


that last part answers the question i had on why fds > 2 were closed on
exec.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

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


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