[14009] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1419 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 18 18:16:13 1999

Date: Thu, 18 Nov 1999 15:15:55 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <942966955-v9-i1419@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 18 Nov 1999     Volume: 9 Number: 1419

Today's topics:
        Even Numbers <sramsden@orbit-internet.net>
    Re: Even Numbers <gellyfish@gellyfish.com>
    Re: Even Numbers (Brett W. McCoy)
    Re: Even Numbers (Brett W. McCoy)
    Re: Even Numbers <sariq@texas.net>
    Re: Even Numbers <gellyfish@gellyfish.com>
    Re: Even Numbers <bivey@teamdev.com>
    Re: Even Numbers (Mark-Jason Dominus)
    Re: Even Numbers (Matthew Bafford)
    Re: Executeable into a Variable <gellyfish@gellyfish.com>
    Re: Executeable into a Variable (Eric Bohlman)
    Re: Executeable into a Variable (Mark-Jason Dominus)
    Re: Executeable into a Variable <mneubert@webdisk.de>
    Re: Executeable into a Variable <gellyfish@gellyfish.com>
    Re: FAQ 5.3: How do I count the number of lines in a fi (Csaba Raduly)
    Re: FAQ 5.3: How do I count the number of lines in a fi <rick.delaney@home.com>
    Re: FAQ 5.4: How do I make a temporary file name? j.h.klein@ieee.org
    Re: FAQ 5.4: How do I make a temporary file name? <rootbeer@redcat.com>
    Re: Fetch Dilbert. (Philip 'Yes, that's my address' Newton)
    Re: Fetch Dilbert. (Martien Verbruggen)
    Re: Fetch Dilbert. <kbandes@home.com>
    Re: Fetch Dilbert. <uri@sysarch.com>
        file descriptors already used when perl starts g0177325@my-deja.com
    Re: file descriptors already used when perl starts (Kragen Sitaker)
    Re: File Locking with a Pre-Forking Server (Anno Siegel)
        Find the work you love <annaatunderwoodgroup@my-deja.com>
    Re: generating error messages from string <rootbeer@redcat.com>
    Re: generating error messages from string (Kragen Sitaker)
    Re: Generating pi (Anno Siegel)
    Re: Generating pi (Peter J. Kernan)
    Re: Generating pi (Anno Siegel)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 18 Nov 1999 08:33:52 -0000
From: "Simon Ramsden" <sramsden@orbit-internet.net>
Subject: Even Numbers
Message-Id: <3833d31f.0@news.proweb.co.uk>

Hello,
I'm  a newbie trying to write a script that recognises even numbers. I'm
having to make if/ elsif statements for every number in the range that I
expect. I know this is the wrong way to do it, so can someone tell me how to
interpret an even number?
Thanks,
S. RAMSDEN




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

Date: 18 Nov 1999 10:41:02 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Even Numbers
Message-Id: <3833d7be_1@newsread3.dircon.co.uk>

Simon Ramsden <sramsden@orbit-internet.net> wrote:
> Hello,
> I'm  a newbie trying to write a script that recognises even numbers. I'm
> having to make if/ elsif statements for every number in the range that I
> expect. I know this is the wrong way to do it, so can someone tell me how to
> interpret an even number?

print "Even" unless ( $number % 2 );


/J\
-- 
"It's times like this I wish I had a penis" - Duckman


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

Date: Thu, 18 Nov 1999 14:37:00 GMT
From: bmccoy@foiservices.com (Brett W. McCoy)
Subject: Re: Even Numbers
Message-Id: <slrn8383sn.e6g.bmccoy@moebius.foiservices.com>

Also Sprach Simon Ramsden <sramsden@orbit-internet.net>:

>I'm  a newbie trying to write a script that recognises even numbers. I'm
>having to make if/ elsif statements for every number in the range that I
>expect. I know this is the wrong way to do it, so can someone tell me how to
>interpret an even number?

Use the modulus operator:

$is_even = $num %2 == 0 ? 'even' : 'odd';

-- 
Brett W. McCoy                             bmccoy@foiservices.com
Computer Operations Manager (Alpha Geek)   http://www.foiservices.com
FOI Services, Inc./DIOGENES                301-975-0110
---------------------------------------------------------------------------


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

Date: Thu, 18 Nov 1999 15:01:21 GMT
From: bmccoy@foiservices.com (Brett W. McCoy)
Subject: Re: Even Numbers
Message-Id: <slrn8385ab.e6g.bmccoy@moebius.foiservices.com>

Also Sprach Brett W. McCoy <bmccoy@foiservices.com>:

>Use the modulus operator:
>
>$is_even = $num %2 == 0 ? 'even' : 'odd';
                 ^^
There's supposed to be a space in there!

-- 
Brett W. McCoy                             bmccoy@foiservices.com
Computer Operations Manager (Alpha Geek)   http://www.foiservices.com
FOI Services, Inc./DIOGENES                301-975-0110
---------------------------------------------------------------------------


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

Date: Thu, 18 Nov 1999 08:49:34 -0600
From: Tom Briles <sariq@texas.net>
Subject: Re: Even Numbers
Message-Id: <383411FE.5C645C73@texas.net>

Jonathan Stowe wrote:
> 
> Simon Ramsden <sramsden@orbit-internet.net> wrote:
> > Hello,
> > I'm  a newbie trying to write a script that recognises even numbers. I'm
> > having to make if/ elsif statements for every number in the range that I
> > expect. I know this is the wrong way to do it, so can someone tell me how to
> > interpret an even number?
> 
> print "Even" unless ( $number % 2 );

Jonathan -

Since you did his homework, I hope you at least stole his lunch money...
:)

- Tom


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

Date: 18 Nov 1999 15:31:06 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Even Numbers
Message-Id: <38341bba_2@newsread3.dircon.co.uk>

Tom Briles <sariq@texas.net> wrote:
> Jonathan Stowe wrote:
>> 
>> Simon Ramsden <sramsden@orbit-internet.net> wrote:
>> > Hello,
>> > I'm  a newbie trying to write a script that recognises even numbers. I'm
>> > having to make if/ elsif statements for every number in the range that I
>> > expect. I know this is the wrong way to do it, so can someone tell me how to
>> > interpret an even number?
>> 
>> print "Even" unless ( $number % 2 );
> 
> Jonathan -
> 
> Since you did his homework, I hope you at least stole his lunch money...
> :)
> 

Nah I got him to arrange a date with his sister ...

/J\
-- 
"Virtual reality wouldn't be this wet" - Lucas, Seaquest DSV


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

Date: 18 Nov 1999 15:40:51 GMT
From: "William" <bivey@teamdev.com>
Subject: Re: Even Numbers
Message-Id: <01bf31db$8ee2f2a0$3527e1ce@bill.jump.net>

Jonathan Stowe <gellyfish@gellyfish.com> wrote in article
<38341bba_2@newsread3.dircon.co.uk>...
> Tom Briles <sariq@texas.net> wrote:
> > 
> > Jonathan -
> > 
> > Since you did his homework, I hope you at least stole his lunch
money...
> > :)
> > 
> 
> Nah I got him to arrange a date with his sister ...
> 
> /J\

That's pretty kinky...
Oh, you mean a date for YOU with his sister.
Never mind.
-Wm


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

Date: Thu, 18 Nov 1999 15:48:02 GMT
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Even Numbers
Message-Id: <811727$457$1@monet.op.net>

In article <slrn8385ab.e6g.bmccoy@moebius.foiservices.com>,
Brett W. McCoy <bmccoy@foiservices.com> wrote:
>Also Sprach Brett W. McCoy <bmccoy@foiservices.com>:
>
>>Use the modulus operator:
>>
>>$is_even = $num %2 == 0 ? 'even' : 'odd';
>                 ^^
>There's supposed to be a space in there!

Doesn't matter.


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

Date: Thu, 18 Nov 1999 22:30:07 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Even Numbers
Message-Id: <slrn838vbr.10h.*@dragons.duesouth.net>

On Thu, 18 Nov 1999 15:01:21 GMT, Brett W. McCoy) poured coffee onto a
keyboard, producing the following in comp.lang.perl.misc: 
: Also Sprach Brett W. McCoy <bmccoy@foiservices.com>:
: >$is_even = $num %2 == 0 ? 'even' : 'odd';
:                  ^^
: There's supposed to be a space in there!

Actually, that's exactly the same as:

   $is_even=$num%2==0?'even':'odd';

Or:

   $is_even
      = # 42
       $num % 2
           == 0
       ?   'even'
         : 'odd';

:-)
 
: Brett W. McCoy

--Matthew


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

Date: 18 Nov 1999 09:45:48 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Executeable into a Variable
Message-Id: <3833cacc_2@newsread3.dircon.co.uk>

Kevin <kevinh@inetplus.net> wrote:
> Question, I am new to Perl and am trying to move some of my bash
> scripts to perl. How can I execute a program or another script and put
> its output into a Variable?
> 

read the perlop manpage about `` (alias qx{} or backticks ) ...
while you are it read the rest of the perlop, perlsyn and perlfunc
manpages too

/J\
-- 
"The teenage masturbators of today are the television executives of
tomorrow" - Melissa Cabriolet, Drop the Dead Donkey


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

Date: 18 Nov 1999 10:12:46 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Executeable into a Variable
Message-Id: <810jeu$1ku$1@nntp1.atl.mindspring.net>

Kevin (kevinh@inetplus.net) wrote:
: Question, I am new to Perl and am trying to move some of my bash
: scripts to perl. How can I execute a program or another script and put
: its output into a Variable?

See the section on "quotes and quote-like operators" in perlop.



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

Date: Thu, 18 Nov 1999 14:11:18 GMT
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Executeable into a Variable
Message-Id: <8111db$2av$1@monet.op.net>

In article <3833b07a.308008317@news2.ase.com>,
Kevin <kevinh@inetplus.net> wrote:
>Question, I am new to Perl and am trying to move some of my bash
>scripts to perl. How can I execute a program or another script and put
>its output into a Variable?

The same way that you do it in bash.  Imagine that.


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

Date: Thu, 18 Nov 1999 16:59:44 +0100
From: "M. Neubert" <mneubert@webdisk.de>
Subject: Re: Executeable into a Variable
Message-Id: <s38as2jehsq39@corp.supernews.com>

My Question is the same, please help!

Kevin <kevinh@inetplus.net> schrieb in im Newsbeitrag:
3833b07a.308008317@news2.ase.com...
> Question, I am new to Perl and am trying to move some of my bash
> scripts to perl. How can I execute a program or another script and put
> its output into a Variable?
>
> Kevin




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

Date: 18 Nov 1999 16:44:49 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Executeable into a Variable
Message-Id: <38342d01_1@newsread3.dircon.co.uk>

M. Neubert <mneubert@webdisk.de> wrote:
> Kevin <kevinh@inetplus.net> schrieb in im Newsbeitrag:
> 3833b07a.308008317@news2.ase.com...
>> Question, I am new to Perl and am trying to move some of my bash
>> scripts to perl. How can I execute a program or another script and put
>> its output into a Variable?
> 
> My Question is the same, please help!
> 

My Answer is the same, read the manpage !

/J\
-- 
"The teenage masturbators of today are the television executives of
tomorrow" - Melissa Cabriolet, Drop the Dead Donkey


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

Date: 18 Nov 1999 10:25:23 GMT
From: csaba_r@my-deja.com (Csaba Raduly)
Subject: Re: FAQ 5.3: How do I count the number of lines in a file?
Message-Id: <8E826FA09quuxi@10.1.2.158>

lr@hpl.hp.com (Larry Rosler) wrote in 
<MPG.129cdcf4433be6f398a227@nntp.hpl.hp.com>:

>In article <38332C61.B89DB66C@cendes.com> on Wed, 17 Nov 1999 22:29:53 
>+0000, Jon Erickson <jerickson@cendes.com> says...
>> Tom Christiansen wrote:
>
>...
>
>> >   How do I count the number of lines in a file?
>
>...

perl -wne "}print $.;{" filename

Csaba (I think this is an Abigail sig too :-)
-- 
-----BEGIN GEEK CODE BLOCK----- 
Version 3.1
GCS/MU d- s:- a30 C++$ UL+ P+>+++ L++ E- W+ N++ o? K? w++>$ O++$ M-
V- PS PE Y PGP- t+ 5 X++ R* tv++ b++ DI+++ D++ G- e+++ h-- r-- !y+
-----END GEEK CODE BLOCK----- 

Csaba Raduly,    Software Developer (OS/2),    Sophos Anti-Virus
mailto:csaba.raduly@sophos.com            http://www.sophos.com/
US Support +1 888 SOPHOS 9            UK Support +44 1235 559933
Life is complex, with real and imaginary parts.


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

Date: Thu, 18 Nov 1999 13:16:08 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: FAQ 5.3: How do I count the number of lines in a file?
Message-Id: <3833FC35.326BDA3F@home.com>

[posted & mailed]

Joe Kline wrote:
> 
> Rick Delaney wrote:
> >
> > > > ex.   system("wc -l", $filename);
> > >
> <SNIP>
> >
> > That's not so strange.  What I'd like to know is which OS has a "wc -l"
> > command.
> 
> Well, Irix does, as I would imagine and Un*x (or Uni*x-like OS) worth
> it's salt.

I don't have Irix, but I've tried `man "wc -l"` on 3 different Un*ces
and came up blank on each.  And it seems it doesn't exist on any of
Sam's machines either.  Hmm.

perldoc -f system

to see why the above example doesn't do what you expect.

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Thu, 18 Nov 1999 10:19:37 GMT
From: j.h.klein@ieee.org
Subject: Re: FAQ 5.4: How do I make a temporary file name?
Message-Id: <810jrp$eu7$1@nnrp1.deja.com>

Apparently the following short program follows the FAQ recommendations:
#!/usr/local/bin/perl5 -w
# Written by Joshua

use POSIX;
use POSIX qw(tmpnam); # Make sure
use POSIX qw(setsid); # Just to check

$sess_id = POSIX::setsid();
print "<$sess_id>\n"; # This one works

$tmpfile = POSIX::tmpnam();
$tmpfil2 = tmpnam();
print	"$tmpfile\n";
print	"$tmpfil2\n";

1;

I added "setsid" in order to check that POSIX is there, and it is.
The result I get is that $tmpfile and $tmpfil2 are undefined!
To make sure, I tried to use the function under C, and it works.
Any hint?

Thanks,

Joshua


In article <38272fe5@cs.colorado.edu>,
  perlfaq-suggestions@perl.com (Tom and Gnat) wrote:
> (This excerpt from perlfaq5 - Files and Formats
>     ($Revision: 1.38 $, $Date: 1999/05/23 16:08:30 $)
> part of the standard set of documentation included with every
> valid Perl distribution, like the one on your system.
> See also http://language.perl.com/newdocs/pod/perlfaq5.html
> if your negligent system adminstrator has been remiss in his duties.)
>
>   How do I make a temporary file name?
>
>     Use the `new_tmpfile' class method from the IO::File module to get
>     a filehandle opened for reading and writing. Use this if you don't
>     need to know the file's name.
>
>         use IO::File;
>         $fh = IO::File->new_tmpfile()
>             or die "Unable to make new temporary file: $!";
>
>     Or you can use the `tmpnam' function from the POSIX module to get
a
>     filename that you then open yourself. Use this if you do need to
>     know the file's name.
>
>         use Fcntl;
>         use POSIX qw(tmpnam);
>
>         # try new temporary filenames until we get one that didn't
already
>         # exist;  the check should be unnecessary, but you can't be
too careful
>         do { $name = tmpnam() }
>             until sysopen(FH, $name, O_RDWR|O_CREAT|O_EXCL);
>
>         # install atexit-style handler so that when we exit or die,
>         # we automatically delete this temporary file
>         END { unlink($name) or die "Couldn't unlink $name : $!" }
>
>         # now go on to use the file ...
>
>     If you're committed to doing this by hand, use the process ID
>     and/or the current time-value. If you need to have many temporary
>     files in one process, use a counter:
>
>         BEGIN {
>             use Fcntl;
>             my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMP} || $ENV
{TEMP};
>             my $base_name = sprintf("%s/%d-%d-0000", $temp_dir, $$,
time());
>             sub temp_file {
>                 local *FH;
>                 my $count = 0;
>                 until (defined(fileno(FH)) || $count++ > 100) {
>                     $base_name =~ s/-(\d+)$/"-" . (1 + $1)/e;
>                     sysopen(FH, $base_name, O_WRONLY|O_EXCL|O_CREAT);
>                 }
>                 if (defined(fileno(FH))
>                     return (*FH, $base_name);
>                 } else {
>                     return ();
>                 }
>             }
>         }
>
> --
> To hold a pen is to be at war.                          --Voltaire
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 18 Nov 1999 09:15:15 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: FAQ 5.4: How do I make a temporary file name?
Message-Id: <Pine.GSO.4.10.9911180914200.16575-100000@user2.teleport.com>

On Thu, 18 Nov 1999 j.h.klein@ieee.org wrote:

> The result I get is that $tmpfile and $tmpfil2 are undefined!
> To make sure, I tried to use the function under C, and it works.

Sounds as if your perl binary (or your POSIX extension, or something else)
is miscompiled or misinstalled. Be sure that 'make test' works before
installing. Cheers!

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



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

Date: Thu, 18 Nov 1999 20:45:25 GMT
From: nospam.newton@gmx.li (Philip 'Yes, that's my address' Newton)
Subject: Re: Fetch Dilbert.
Message-Id: <38346210.436580276@news.nikoma.de>

On 18 Nov 1999 11:34:26 GMT, mgjv@wobbie.heliotrope.home (Martien
Verbruggen) wrote:

>On Thu, 18 Nov 1999 05:41:52 GMT,
>	Philip 'Yes, that's my address' Newton <nospam.newton@gmx.li> wrote:
>> On 16 Nov 1999 15:55:24 -0600, abigail@delanet.com (Abigail) wrote:
>> 
>> >perldoc@my-deja.com (perldoc@my-deja.com) wrote on MMCCLXVIII September
>> >MCMXCIII in <URL:news:80s6u1$b23$1@nnrp1.deja.com>:
>> >[] In article <slrn832jjg.cvu.abigail@alexandra.delanet.com>,
>> >[]   abigail@delanet.com wrote:
>> >[] 
>> >[] > #!/opt/perl/bin/perl -w
>> >[] 
>> >[] The "opt" smells of Sun.  I could be wrong.
>> >
>> >You are wrong.
>> 
>> HP-UX, then? (What we have at work, and Perl lives happily in
>> /opt/perl/bin/perl, as well as in /usr/contrib/bin/perl, though the
>> latter is 4.036...)
>
>I'm on Linux, at home, and have an /opt there. /opt is not OS specific,
>although some OS's have adopted it as a default, just one of those
>philosophical things that all Unix admins always keep arguing about.
>
>Most systems I have any say over have an /opt.

Well, yes -- but putting Perl into /opt (by default, or for other
reasons) reminded me of HP-UX. Linux puts it into /usr/local by
default, IIRC.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>


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

Date: 18 Nov 1999 11:34:26 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: Fetch Dilbert.
Message-Id: <slrn837p31.1qp.mgjv@wobbie.heliotrope.home>

On Thu, 18 Nov 1999 05:41:52 GMT,
	Philip 'Yes, that's my address' Newton <nospam.newton@gmx.li> wrote:
> On 16 Nov 1999 15:55:24 -0600, abigail@delanet.com (Abigail) wrote:
> 
> >perldoc@my-deja.com (perldoc@my-deja.com) wrote on MMCCLXVIII September
> >MCMXCIII in <URL:news:80s6u1$b23$1@nnrp1.deja.com>:
> >[] In article <slrn832jjg.cvu.abigail@alexandra.delanet.com>,
> >[]   abigail@delanet.com wrote:
> >[] 
> >[] > #!/opt/perl/bin/perl -w
> >[] 
> >[] The "opt" smells of Sun.  I could be wrong.
> >
> >You are wrong.
> 
> HP-UX, then? (What we have at work, and Perl lives happily in
> /opt/perl/bin/perl, as well as in /usr/contrib/bin/perl, though the
> latter is 4.036...)

I'm on Linux, at home, and have an /opt there. /opt is not OS specific,
although some OS's have adopted it as a default, just one of those
philosophical things that all Unix admins always keep arguing about.

Most systems I have any say over have an /opt.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Can't say that it is, 'cause it
Commercial Dynamics Pty. Ltd.   | ain't.
NSW, Australia                  | 


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

Date: Thu, 18 Nov 1999 08:53:34 -0500
From: Kenneth Bandes <kbandes@home.com>
Subject: Re: Fetch Dilbert.
Message-Id: <383404DE.C5F965E3@home.com>

perldoc@my-deja.com wrote:
> OK, I'll take the troll.
> 
> Newbies beware - curmudgeonly old Unix cranky-pants like
> Abigail won't even begin to consider ...
[further abuse, invective, and fatuous bravado]
> Awww, eat my shorts.

hmmm ... another case of Code Rage ...

Ken Bandes


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

Date: 18 Nov 1999 16:55:31 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Fetch Dilbert.
Message-Id: <x766yzsbvw.fsf@home.sysarch.com>

>>>>> "P'tmaN" == Philip 'Yes, that's my address' Newton <nospam.newton@gmx.li> writes:

  P'tmaN> Well, yes -- but putting Perl into /opt (by default, or for other
  P'tmaN> reasons) reminded me of HP-UX. Linux puts it into /usr/local by
  P'tmaN> default, IIRC.

i use solaris and i always install open source into /usr/local. most are
defaulted to that dir which makes life much easier. in fact i find it
annoying that linux/bsd* ship with perl in /usr/bin and it maybe an old
or even broken (red hat) version. so you have to have /usr/local/bin in
front of /usr/bin in PATH and MANPATH, etc. more pains in the butt. i
think they should only put the core unix programs and libs in /usr and
the third party (how do you define 3rd party in that world? :-) programs
should go into /usr/local.

i never liked having /opt. i have it only for solaris specific patches
and packages. i never put anything else in there. same with /usr. other
than under local i never touch it so it is only sun stuff (except for
some minor symlinks and X stuff).

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 18 Nov 1999 20:37:40 GMT
From: g0177325@my-deja.com
Subject: file descriptors already used when perl starts
Message-Id: <811o2k$ata$1@nnrp1.deja.com>

Can anyone explain the following:

  perl -e 'open A, ">&2"; open B, ">&2"; print fileno A, fileno B'
  37

So, file descriptors 4,5,6 are somehow in use.  Why?

John.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 18 Nov 1999 22:52:25 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: file descriptors already used when perl starts
Message-Id: <Jq%Y3.26153$YI2.1175631@typ11.nn.bcandid.com>

In article <811o2k$ata$1@nnrp1.deja.com>,  <g0177325@my-deja.com> wrote:
>Can anyone explain the following:
>  perl -e 'open A, ">&2"; open B, ">&2"; print fileno A, fileno B'
>  37
>
>So, file descriptors 4,5,6 are somehow in use.  Why?

Doesn't happen on my Perl; is it possible you're running in a debugger?
-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: 18 Nov 1999 10:06:35 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: File Locking with a Pre-Forking Server
Message-Id: <810j3b$448$1@lublin.zrz.tu-berlin.de>

 <nkaiser@my-deja.com> wrote in comp.lang.perl.misc:
>In the Perl Cookbook example 17.12, Tom mentions that you need to use
>file locking ot ensure only one child can call accept at any particular
>moment (I'm using Solaris).
>
>What is the syntax for this? What do I want to flock? The socket?

Don't throw in fancy terms if you don't know what they mean.  The
syntax is that of flock, which is that of a two-argument function
(or prefix operator).  In other words, your question has *nothing*
to do with syntax.

>Here's my child accept code:
>
>while (accept(CLIENT,SERVER)) {
>  # do I put a flock CLIENT,2 here?
>}
>
>Thanks....

No.  As the Cookbook states, under Solaris you don't want more
than one child to attempt an accept() on the same socket.  Locking
the newly created CLIENT after the fact won't help you.

If anything, you want an exclusive lock on SERVER before accept(),
which you release immediately after, but you may want to create
a plain file for the purpose of locking.

Anno


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

Date: Thu, 18 Nov 1999 14:46:49 GMT
From: Anna <annaatunderwoodgroup@my-deja.com>
Subject: Find the work you love
Message-Id: <8113go$pta$1@nnrp1.deja.com>

Have you been giving thought to exploring your career options?  In this
rapidly evolving marketplace I would like to work with you as you make
your next change.

My name is Anna and I work with a Technical Recruitment Agency that
focuses on Information Technology Placements directly with Companies in
and around North Carolina.  We develop our network on a referral basis
and if you know of anyone who may also be considering a new path feel
free to forward on this information.

If you would like to find out more please reply with what your career
interests/aspirations are and the best way for me to contact you
directly.



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 18 Nov 1999 13:22:26 -0800
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: generating error messages from string
Message-Id: <Pine.GSO.4.10.9911181311560.16575-100000@user2.teleport.com>

On 18 Nov 1999, Sam Steingold wrote:

> sub parse_error {
>   my ($pref,$str) = @_;
>   my $pos = pos($_[1]);

Uh, oh. While this isn't necessarily _wrong_ wrong, it's generally a bad
idea to "covertly" pass data to a sub. Here, you seem to be giving the
secret parameter $pos, in addition to the obvious parameters. (And why
didn't you just use pos($str)?)  If the $pos is important, have the caller
include that as an additional parameter.

>   my $len = length($_[1]);

Maybe length $str would be more readable.

>   if ($len + length($pref) < 75) { die $pref,"\"",$str,"\":",$pos,"\n"; }

Maybe that die should use the string qq{$pref"$str":$pos\n} ?

Cheers!

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



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

Date: Thu, 18 Nov 1999 21:57:26 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: generating error messages from string
Message-Id: <aD_Y3.26084$YI2.1167658@typ11.nn.bcandid.com>

In article <ubt8rd2t5.fsf@ksp.com>, Sam Steingold  <sds@goems.com> wrote:
>suppose I want to print an error message that there is something wrong
>in string $string at position $position.
>if $string is "short", I can just print it, but if it's long, I have to
>extract the relevant fragment &c, something along the lines of
>  if ($len + length($pref) < 75) { die $pref,"\"",$str,"\":",$pos,"\n"; }
>    my $start = ($pos > 10 ? $pos-10 : 0);
>    die $pref,":\n",substr($str,$start,40),"\n"," " x ($pos-$start),"^\n";
>
>does perl provide stock functionality for this?

Hmm, you could perhaps do /(.{0,10}\G.{0,30})/.  E.g.
#!/usr/bin/perl -w
use strict;
$_ = "x" . "fibble " x 50 . "blorg glook" . "ZAM " x 20;
my $match = /blorg/g;
$match = /(.{0,10}\G.{0,30})/g or die "shoot!\n";
printf "Found it here: ($1)\n";

Unfortunately, this doesn't work.  The m//g starts at \G, so it can't
match the .{0,10} to anything, and \G doesn't work without /g.

You could perhaps extract a substring and do a match on it:
#!/usr/bin/perl -w
use strict;
$_ = "x" . "fibble " x 50 . "blorg glook" . "ZAM " x 20;
my $match = /blorg/g;
$match = substr($_, 0, 30 + pos) =~ /(.{0,40})$/ or die "shoot!\n";
printf "Found it here: ($1)\n";


-- 
<kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>


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

Date: 18 Nov 1999 09:13:09 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Generating pi
Message-Id: <810fv5$41u$1@lublin.zrz.tu-berlin.de>

Peter J. Kernan <pete@theory2.phys.cwru.edu> wrote in comp.lang.perl.misc:
>On 16 Nov 1999 18:11:06 GMT, Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>.=You need to refresh your probability concept.  Probability being 0
>.=does not mean that the even is not possible.  ;-)
>.=
>
>  that makes sense for a uniform continuous distribution , but not for a
>finite discrete one. or are you saying that the probability of randomly
>generating the pi sequence with a truly random digit generator, given
>infinite time, is zero (obviously) but possible? i would believe it if
>it could be shown that the pi sequence terminated. but i recall, from
>8th grade, that it does not. therefore you must have another meaning in
>mind.

When each number generated is an elementary event we have a discrete
distribution.  When the *sequence* of numbers generated is treated as
a single event we are dealing with a continuous distribution.

Anno


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

Date: 18 Nov 1999 16:49:54 GMT
From: pete@theory2.phys.cwru.edu (Peter J. Kernan)
Subject: Re: Generating pi
Message-Id: <slrn838bhi.dvm.pete@theory2.phys.cwru.edu>

On 18 Nov 1999 09:13:09 -0000, \
  Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
 .=
 .=When each number generated is an elementary event we have a discrete
 .=distribution.  When the *sequence* of numbers generated is treated as
 .=a single event we are dealing with a continuous distribution.
 .=

true for infinite sequences.  or are you speaking of a generator which
randomly stops after a possibly infinite time?

-- 
  Pete


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

Date: 18 Nov 1999 17:13:04 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Generating pi
Message-Id: <811c30$4qg$1@lublin.zrz.tu-berlin.de>

Peter J. Kernan <pete@theory2.phys.cwru.edu> wrote in comp.lang.perl.misc:
>On 18 Nov 1999 09:13:09 -0000, \
>  Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>.=
>.=When each number generated is an elementary event we have a discrete
>.=distribution.  When the *sequence* of numbers generated is treated as
>.=a single event we are dealing with a continuous distribution.
>.=
>
>true for infinite sequences.  or are you speaking of a generator which
>randomly stops after a possibly infinite time?

How do you stop after infinite time?

Actually I was thinking of infinite sequences, yes.  Those correspond
to the reals in cardinality.  Generating finite but unbounded sequences
(which is probably what you mean) would result in a countably infinite
set of events.  I can't muster enough measure theory to decide if
events of zero probability are possible in that setting, though I
tend to think that they are.

Anno


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

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

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 1419
**************************************


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