[10504] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4096 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 28 19:06:41 1998

Date: Wed, 28 Oct 98 16:00:20 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 28 Oct 1998     Volume: 8 Number: 4096

Today's topics:
    Re: Checking for only numbers (Abigail)
    Re: Checking for uppercase (Martien Verbruggen)
    Re: Checking for uppercase <dgris@rand.dimensional.com>
    Re: Comparative modularization (was: Not to start a lan <achrist@easystreet.com>
        DBM Files <scott@reflector.net>
    Re: Does Text::ParseWords / &quotewords() suck (or is i (brian d foy)
    Re: eliminating duplicate lines (Craig Berry)
    Re: File Permissions on NT 4 using Perl 5.004 <george.kuetemeyer@mail.tju.edu>
    Re: Forcing perl to garbage collect (Tye McQueen)
    Re: IPC::Shareable problems jlafiotte@altern.org
        just attest ingnore please <derichards@multipro.com>
        leading spaces and pipes <marx@idiom.com>
    Re: More Serial Port Problems (Brand Hilton)
        Net::LDAPapi under nt? karl@f7.net
    Re: new to perl (maybe) (Larry Rosler)
    Re: Not to start a language war but.. <dheise@metronet.de>
    Re: Perl & Y2K - booby trap code (Martien Verbruggen)
    Re: Perl & Y2K - booby trap code (Larry Rosler)
        perl trinary operator oddity <jandrews@uic.edu>
    Re: perl trinary operator oddity (Larry Rosler)
    Re: problem with file test -e (Martien Verbruggen)
    Re: problem with file test -e (Larry Rosler)
    Re: Simple regular expression (HELP)..... (Patrick Timmins)
        sort numericaly and uniq like Korn shell nguyen.van@imvi.bls.com
    Re: sort numericaly and uniq like Korn shell (Brand Hilton)
        Trapping the output of a system call... <rbridal@bcl.net>
    Re: Trapping the output of a system call... <tupshin@tupshin.com>
    Re: Trapping the output of a system call... (Martien Verbruggen)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 28 Oct 1998 23:05:28 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Checking for only numbers
Message-Id: <7187vo$fq3$1@client3.news.psi.net>

Mike (support@counter.w-dt.com) wrote on MDCCCLXXXIV September MCMXCIII
in <URL:news:36375716.B5BF079F@counter.w-dt.com>:
++ How do you check to make sure they only enter numbers and not any other
++ characters?


FAQ.


Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: Wed, 28 Oct 1998 22:32:13 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Checking for uppercase
Message-Id: <NXMZ1.1$vh5.2652@nsw.nnrp.telstra.net>

In article <715su1$n37$1@us4.usit.net>,
	jspears@usit.net (Jason Spears) writes:

> I find a regex a little more readable than your example.  Mostly it's
> just personal preference, isn't it?

And a regexp is computationally a lot more expensive than a uc() and
an eq. 

Of course, if you need to test for many of these things, a
single regexp might become cheaper. I'd need to benchmark that to know
for certain.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Wed, 28 Oct 1998 23:00:59 GMT
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: Checking for uppercase
Message-Id: <m3btmwtiav.fsf@rand.dimensional.com>

mgjv@comdyn.com.au (Martien Verbruggen) writes:

> In article <715su1$n37$1@us4.usit.net>,
> 	jspears@usit.net (Jason Spears) writes:
> 
> > I find a regex a little more readable than your example.  Mostly it's
> > just personal preference, isn't it?
> 
> And a regexp is computationally a lot more expensive than a uc() and
> an eq. 

Yes, but optimizing for readability is frequently far more
important than optimizing for computational efficiency (cost
of cpu time compared to cost of programmer time).

dgris
-- 
Daniel Grisinger              dgris@rand.dimensional.com
Supporter of grumpiness where grumpiness is due on clpm.
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Wed, 28 Oct 1998 15:27:16 -0800
From: Al Christians <achrist@easystreet.com>
Subject: Re: Comparative modularization (was: Not to start a language war but..)
Message-Id: <3637A854.47C7F122@easystreet.com>

Larry Wall wrote:

> Odd how you can say something pertinent and impertinent simultaneously.  :-)
> 

Does Python have a fork?

A typical programmer's problem.  The psychological qualifications for
programming are severe, but so rarely enforced as to appear to be
disqualifications.       

Al


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

Date: 28 Oct 1998 23:43:17 GMT
From: "Scott Phillips" <scott@reflector.net>
Subject: DBM Files
Message-Id: <718a6l$np@bgtnsc03.worldnet.att.net>

    Can anyone point me in the direction of some good tutorials or programs
which utilize DBM.....A bunch of books mention them and give some limited
examples but I am looking for something that will help fill in the gaps.
TIA,
-Scott
http://www.interclubs.com/
http://www.reflector.net/





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

Date: Wed, 28 Oct 1998 17:55:59 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Does Text::ParseWords / &quotewords() suck (or is it me)?
Message-Id: <comdog-ya02408000R2810981755590001@news.panix.com>

In article <7181t5$ggk@access5.digex.net>, briang@access5.digex.net (Brian G.) posted:

> If it finds a mismatched quote or a random backslash it crashes with 
> 
>         Unmatched quote at ./program.pl line #
> 
> Is there some way to trap this error?

use eval {} and then check $@.

this doesn't lessen the suck factor though.

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 28 Oct 1998 22:11:01 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: eliminating duplicate lines
Message-Id: <7184pl$osm$1@marina.cinenet.net>

westi@leland.stanford.edu wrote:
: I am trying to open a webserverlog file and read in all the data to a new
: file The problem I'm having is eliminating all of the lines which are
: duplicates. If anyone could give me a few tips, I would really appreciate
: it.

All examples assume read from stdin, write to stdout.

Case 1: Remove adjacent identical lines.

  my $line = undef;

  while (<>) {
    unless ($line eq $_) {
      print;
      $line = $_;
    }
  }

Case 2: Remove all identical lines, for smallish files.

  my %seen;

  while (<>) {
    print unless $seen{$_}++;
  }

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      "Ripple in still water, when there is no pebble tossed,
       nor wind to blow..."


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

Date: Wed, 28 Oct 1998 17:50:18 -0500
From: George Kuetemeyer <george.kuetemeyer@mail.tju.edu>
Subject: Re: File Permissions on NT 4 using Perl 5.004
Message-Id: <36379FAA.42E02E44@mail.tju.edu>



R.G. wrote:

> Has anyone had any experience changing file permissions on an NT server
> using Perl?

Check out the documentation for: Win32::FileSecurity. It's got everything you
need to change file permissions.



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

Date: 28 Oct 1998 17:08:37 -0600
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: Forcing perl to garbage collect
Message-Id: <71885l$jug@fohnix.metronet.com>

) }[A complimentary Cc of this posting was sent to Michael J Gebis
) }<gebis@fee.ecn.purdue.edu>],
) }who wrote in article <712i4p$k14@mozo.cc.purdue.edu>:
) }> I also think that 1) you can't force perl to garbage collect without
) }> exiting

) ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
) }Perl does not collect garbage.  At all.  (Except primitive refcounting.)

gebis@fee.ecn.purdue.edu (Michael J Gebis) writes:
) I was talking about whatever the man page was talking about when it
) said to me:
) 
)      When an interpreter thread finally shuts down (usually when
)      your program exits), then a rather costly but complete
)      mark-and-sweep style of garbage collection is performed, and
)      everything allocated by that thread gets destroyed.  
) 
) That actually sounds like perl does collect garbage using something
) other than primitive refcounting.

Refering to "global destruction" as a form of "garbage collection"
is a bit of a stretch in my book.  Refering to reference counting
as "garbage collection" is also a stretch to me.

So F<perlobj.pod> talking about "Perl's two-phase garbage
collection" isn't my favorite turn of phrase.

I'm curious how many of the Perl porters agree with
F<perlobj.pod>'s assertion that Perl will get "real" garbage
collection in the future.  I get the feeling this was a
controverisal statement since the author feels the need to
tell us that the lack of "real" garbage collection is not
to be considered a feature.

I think there are several steps to be taken to reduce Perl's
memory consumption before resorting to periodically searching
for circular references that could be freed (which is what I
think of first when I hear "garbage collection").  Freeing large
buffers associated with lexicals and temporaries would be a
good first step.
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: Wed, 28 Oct 1998 21:39:01 GMT
From: jlafiotte@altern.org
Subject: Re: IPC::Shareable problems
Message-Id: <7182tl$ftv$1@nnrp1.dejanews.com>

same here...

In article <ecl67d5tzey.fsf@ws011.dp.intel.com>,
  bkeelerx@iwa.dp.intel.com (Bruce J. Keeler) wrote:
>
> I have had no luck with IPC::Shareable.  None.
>
> It won't pass its regression tests.  It always gets stuck on the last test,
> number 14.  It either hangs forever, or issues a message along the lines:
>
>     IPC::Shareable::FETCH: semctl returned false:
>          Invalid argument at test.pl line 231

I have a similar problem. It won't pass the tests: always stops at number 13
in my case.

I think there is something wrong... Since we are two people with this same
problem, I don't think we are paranoid :)

j. lafiotte











>
> I've tried several combinations of Perl 5.004, 5.004_04 5.005_02 on
> SunOS 4, HP-UX 10.20, Red Hat Linux 5.1 (kernel 2.0.34).
>
> I've tried versions 0.28, 0.29 and 0.30 of IPC::Shareable.
>
> I've only tried Storable 0.6@3, as that's all that's on CPAN.
>
> I've written to Ben Sugars, and gotten no response.
>
> I've searched Dejanews.  Nada.
>
> I am I the only one experiencing these problems?  Have I gone crazy?
>
> Please help!
>
> Thanks,
> Bruce
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 28 Oct 1998 16:20:36 -0600
From: Dennis <derichards@multipro.com>
Subject: just attest ingnore please
Message-Id: <363798B4.1CFBAE39@multipro.com>

test


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

Date: Wed, 28 Oct 1998 17:48:40 -0600
From: "Marcus J. Foody" <marx@idiom.com>
Subject: leading spaces and pipes
Message-Id: <3637AD58.7D72@idiom.com>

Hello, I have a field that has a pipe symbol as its first character I
would like to get rid of the nasty pipe symbol.  The field that is given
me problems is $prefix

Here is what I have:

@field2 = split(/\|/,$prefix);

This takes out the pipe for me but leaves me with a space in front of
the field as a result.

I would like to delete or truncate that space entirely.

If anyone has any ideas on how to first delete the leading pipe symbol,
then delete the leading space left over. 

thank you
marcus


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

Date: 28 Oct 1998 22:05:34 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: More Serial Port Problems
Message-Id: <7184fe$bh13@mercury.adc.com>

In article <7181ht$e0c$1@nnrp1.dejanews.com>,  <scott@jtsmith.com> wrote:
>Well, I posted a previous question on this, and got a few replies, but none
>of them seemed to really do the trick for me... I'll post the exact code
>here, and if I'm doing something obviously wrong, let me know...
>
>-----
>
>sysopen(DEV, "/dev/ttyS1", O_RDWR|O_NOCTTY) || &access_error;
>
>$oldh = select(DEV);
>$| = 1;
>select($oldh);
>
>print DEV "$fun|$morefun|\r\n";
>
>while (<DEV>) {
> last if ($_ =~ /\!/);
> print "$_";
> }
>
>close(DEV);
>
>-----
>
>
>What happens:
>
>It successfully opens the serial port, and prints that line to the port.  A
>DOS-based program on the other side of the port reads that line in, and prints
>out a response that ends with a !.  When this script sees that !, it quits out
>of the while loop and closes the port.
>
>That part is working OK.  However, it seems that the while (DEV) loop is
>echoing eveything it receives back through the com port.  I thought the
>autoflushing of the filehandle would fix this, but it doesn't, apparently.

I seriously doubt that Perl is doing this.  Check the parameters on
your serial port and/or modem on the remote machine and make sure you
don't have local echo turned on.

>Is there a way to keep it from echoing?  Also, is there a better way to code
>this so the program doesn't freeze up on the while() loop if the serial port
>is frozen up?

Look at the entry for "alarm" in perlfunc.  There's a code snippet
there for exactly that.

-- 
 _____ 
|///  |   Brand Hilton  bhilton@adc.com
|  ADC|   ADC Telecommunications, ATM Transport Division
|_____|   Richardson, Texas


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

Date: 28 Oct 1998 17:12:48 -0500
From: karl@f7.net
Subject: Net::LDAPapi under nt?
Message-Id: <vxyg1c8l4in.fsf@suite.deas.harvard.edu>

I'm in a group that is trying to get the Net::LDAPapi module working
under NT.  We've been stuck getting variations of this error:

Can't load 'e:\perl\5.00502\lib/auto/Net/LDAPapi/LDAPapi.dll' for module
Net::LDAPapi: load_file:The specified module could not be found at
e:\perl\5.00502\lib/MSWin32-x86-object/DynaLoader.pm line 168.

So it seems that although the module is found, it can't be loaded.
This is from a  use Net::LDAPapi;  statement in the Perl source.

The variations are just according to the filenames and versions:
- We've tried several different versions of perl, including
  5.005_02 from activestate.com and 5.004_04 from perl.com.
- We've been working with the netscape 3.0b1 ldap sdk, since all the doc
  we've seen says not to bother with the netscape 1.0 or umich sdk's.
- And of course we've tried all the LDAPapi's we can lay our hands on,
  most recently version 1.40 from
  http://www.linc-dev.com/Files/netldapapi-140-winnt.zip.  We also tried
  the new Mozilla:LDAP to no avail.  Graham Barr's pure-perl ldap module
  isn't really an option, since we have a lot of code using LDAPapi already.

If anyone can point us in the right direction, it would be greatly
appreciated.  Please reply by email if possible (and post if you like).

TIA,
karl@f7.net


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

Date: Wed, 28 Oct 1998 13:47:01 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: new to perl (maybe)
Message-Id: <MPG.10a130b5bfdcaeac989844@nntp.hpl.hp.com>

In article <363781b1.24225059@news.urbanet.ch> on Wed, 28 Oct 1998 
21:10:27 GMT, pub @ alma . ch (M.) <pub @ alma . ch (M.)> says...
 ... 
> Lacking functionality is mainly fork() and alarm(), as far as I have
> been concerned. It hasn't really bothered me so far. (And there are
> workarounds)

Please be more specific about the workarounds.  I haven't seen any 
posted here.

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


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

Date: 28 Oct 1998 22:23:27 GMT
From: "Dirk Heise" <dheise@metronet.de>
Subject: Re: Not to start a language war but..
Message-Id: <01be02bf$c70a4260$LocalHost@dreadzone>

Abigail wrote:
> Klaus Schilling (Klaus.Schilling@home.ivm.de) wrote on MDCCCLXXXIII
> September MCMXCIII in <URL:news:87vhl671tf.fsf@ivm.de>:
> ++ 
> ++ 
> ++ Would python or perl change severely if one replaced ref-counting with
a real
> ++ gc like Boehm's?
> 
> 
> No.

Wrong. It would change severely as the destructors of Python
objects would be called at moments you can't manipulate
directly. Maybe you can when you have much knowledge
about the gc strategy, but usually, such strategies should
be hidden from the programmer and not be part of a 
public interface.

It can be worked around, but it would change the
behaviour of existing code, maybe severely.

Dirk



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

Date: Wed, 28 Oct 1998 21:52:48 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <QmMZ1.9$ag5.91022@nsw.nnrp.telstra.net>

In article <71695c$f0a@fohnix.metronet.com>,
	tye@fohnix.metronet.com (Tye McQueen) writes:
> Russ Allbery <rra@stanford.edu> writes:
> ) 
> ) [...] Perl and C's handling of years
> ) is illogical *in the context of human handling of years in dates*.  Ilya's
> ) certainly correct from the theoretical perspective that any given start of
> ) epoch is as good as any other, [...]
> 
> And the epoch for Unix dates is 1970 so if the motivation for
> $year-1900 was _not_ the near-sighted desire to easilly have
> 2-digit years for the next few decades, then the choice would
> have been $year-1970 instead.

The epoch for unix dates or dos machines has no relevance on the
definition of the tm_year member of the tm struct in the C standard.
The C standard is (or tries to be) platform independent. I don't know
the rationale behind that definition, but maybe you can find something
about it in the original documentation that defines it.

> $year-1900 was chosen to make it easier to write code that
> wouldn't work past Y2K.  It is still possible to write

I doubt it. Perl's localtime just probably copied the C localtime
stuff, more or less verbatim. And unless you can tell me that the C
standard explicitly mentiones that this choice was made for those
reasons, I doubt very much that that was it.

I'd really like to see some good article on the rationale behind this,
if there was any, but until I have seen it, I don't think I'll make
any assumptions. Perl has this defintion, because C had it, and it was
'natural' to just copy it. Why C uses this definition is unknown to
me.

Of course, most of us agree that it would have been better, had the
tm_year member been defined as 'years since 0', but that would still
have given us problems for BC years.

> What, was tm_year originally of type C<char>?  Then we could
> get to year 127, I mean 2027, which is about as far as we
> need to go in Unix anyway.

Again: Unix has nothing to do with this definition. And as far as I
know, tm_year was always an int.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Wed, 28 Oct 1998 15:28:25 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <MPG.10a148746fb84072989845@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <QmMZ1.9$ag5.91022@nsw.nnrp.telstra.net> on Wed, 28 Oct 1998 
21:52:48 GMT, Martien Verbruggen <mgjv@comdyn.com.au> says...
 ... 
> The epoch for unix dates or dos machines has no relevance on the
> definition of the tm_year member of the tm struct in the C standard.
> The C standard is (or tries to be) platform independent. I don't know
> the rationale behind that definition, but maybe you can find something
> about it in the original documentation that defines it.
> 
> > $year-1900 was chosen to make it easier to write code that
> > wouldn't work past Y2K.  It is still possible to write
> 
> I doubt it. Perl's localtime just probably copied the C localtime
> stuff, more or less verbatim. And unless you can tell me that the C
> standard explicitly mentiones that this choice was made for those
> reasons, I doubt very much that that was it.
> 
> I'd really like to see some good article on the rationale behind this,
> if there was any, but until I have seen it, I don't think I'll make
> any assumptions. Perl has this defintion, because C had it, and it was
> 'natural' to just copy it. Why C uses this definition is unknown to
> me.

You inspired me to paw through a carton of old papers in search of 
documentation of 'struct tm'.  The earliest one I have found so far is 
in a document I co-authored dated October 11, 1978, called "Standard C 
Library for GCOS" (which was the OS for the GE/Honeywell mainframes).  
How's that for "two decades ago", Mark-Jason Dominus?

>From the abstract:  "Much of the Library is compatible with the 
corresponding UNIX and TSO libraries."  But I haven't yet located that 
documentation, which would be definitive.

The description of 'struct tm' in <time.h> is exactly as we know it, 
with these exceptions:

The range of 'tm_sec' is (correctly) 0 to 59, instead of the 60 or 61 
that was sneaked into the C Standard later by 'clever' people.

The range of 'tm_mon' is 0 to 11,  overwritten in ink to 1 to 12, and 
commented again in ink back to 0 to 11, with the following marginal 
notes in three different inks (all in my handwriting):  Check on UNIX & 
fix if wrong! ... It is 0-11 on Research! [That is the original PDP-11 
implementation.] ... AND on USG!! [That is the production UNIX 
implementation, maybe on Western Electric 3B hardware.]

The description of 'tm_year' is 'year - 1900' and there is no comment.

FWIW, there is also no comment on any of these values in the "Rationale 
for American National Standard for Information Systems -- Programming 
Language -- C" that accompanied the ANSI/ISO C Standard.

In the Standard itself, the example for the 'mktime' function may be 
very enlightening:

What day of the week is July 4, 2001?

 ...
time_str.tm_year = 2001 - 1900;
time_str.tm_mon  = 7 - 1;
 ...

It is no coincidence that a Y2K-relevant example was chosen, in the 
1980's.  We were fully aware that the value would attain three digits.

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


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

Date: Wed, 28 Oct 1998 17:03:32 -0600
From: "John R. Andrews" <jandrews@uic.edu>
Subject: perl trinary operator oddity
Message-Id: <Pine.A41.3.96.981028165306.109868A-100000@tigger.cc.uic.edu>


According to the Programming Perl (version 5 2nd edition) page 91,
The trinary conditional operator should evaluate exactly one of the 
conditional operand expressions. So one would expect the following 
set of commands to print the value "2" twice. In fact, it prints 3 and 2.
This does not seem consistant with the definition of the operator. 
But I could even see it printing 3 twice, but not 3 and 2.
Am I missing something simple?

Here's the program distilled way down from my real application:

$n = 1;
print "True: ", (1 ? $n+=1 : $n+=1),"\n";
$n = 1;
print "False: ",(0 ? $n+=1 : $n+=1),"\n";
 



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

Date: Wed, 28 Oct 1998 15:53:31 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: perl trinary operator oddity
Message-Id: <MPG.10a14e521bfff31989847@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <Pine.A41.3.96.981028165306.109868A-100000@tigger.cc.uic.edu> 
on Wed, 28 Oct 1998 17:03:32 -0600, John R. Andrews <jandrews@uic.edu> 
says...
> 
> According to the Programming Perl (version 5 2nd edition) page 91,
> The trinary conditional operator should evaluate exactly one of the 
> conditional operand expressions. So one would expect the following 
> set of commands to print the value "2" twice. In fact, it prints 3 and 2.
> This does not seem consistant with the definition of the operator. 
> But I could even see it printing 3 twice, but not 3 and 2.
> Am I missing something simple?
> 
> Here's the program distilled way down from my real application:
> 
> $n = 1;
> print "True: ", (1 ? $n+=1 : $n+=1),"\n";
> $n = 1;
> print "False: ",(0 ? $n+=1 : $n+=1),"\n";

Try parenthesising correctly.  What you have written parses thus:

  $n = 1;
  print "True: ", ((1 ? $n+=1 : $n) +=1),"\n";
  $n = 1;
  print "False: ",((0 ? $n+=1 : $n) +=1),"\n";

When you parenthesize it correctly, the problem goes away:

  $n = 1;
  print "True: ", (1 ? $n+=1 : ($n+=1)),"\n";
  $n = 1;
  print "False: ",(0 ? $n+=1 : ($n+=1)),"\n";

I personally would also parenthesize the first consequent, but that is 
now the default.

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


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

Date: Wed, 28 Oct 1998 22:01:14 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: problem with file test -e
Message-Id: <KuMZ1.11$ag5.91022@nsw.nnrp.telstra.net>

In article <717suu$jfa$1@cnn.cc.biu.ac.il>,
	"Avshi Avital" <avitala@macs.biu.ac.il> writes:

> a "race condition" ?
> pardon my ignorence, but WTH is that?

When you attempt to grab a resource exclusively and don't do this in
an atomic manner (meaning in one single operation), but instead using
two or more operations, you run the risk that a second process might
come along and do the same thing while you are still meddling along.

An example:

A process needs exclusive use of a file. It does this by checking
whether another 'lockfile' exists. If it does, it waits until it
doesn't exist anymore. If it doesn't, it creates the lockfile, and
then proceeds to write to the file it needed access to.

This 'locking' method takes a few calls.

1	Check the lock file
	(loop until it doesn't exist)
2	Create the lock file
3	Write to destination file

If another process comes along, and does the same thing, you can get a
race condition:

- process A performs 1
- process B performs 1

	Both processes decide that there is no lock file, so both decide
	they can proceed

- process A creates the lock file
- process B creates the lock file
- process A writes to destination
- process B writes to destination

This can become very ugly. 

Grabbing exclusive use of resources always, always has to be done
using some atomic operation.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Wed, 28 Oct 1998 15:41:48 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: problem with file test -e
Message-Id: <MPG.10a14b97ff825e72989846@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and a copy mailed.]

In article <KuMZ1.11$ag5.91022@nsw.nnrp.telstra.net> on Wed, 28 Oct 1998 
22:01:14 GMT, Martien Verbruggen <mgjv@comdyn.com.au> says...
 ...
> Grabbing exclusive use of resources always, always has to be done
> using some atomic operation.

"always, always" is going too far.  In an application I wrote for an 
environment in which atomic locking was not readily available (M$ VC++), 
I used the sequential acquisition of *two* locks (directories, not 
files, following a suggestion by Tom Christiansen) before accessing the 
critical resource.

With one lock the (CGI) program had been failing catastrophically on 
about one in 10**4 invocations.  I estimate that it will now fail in 
about one in 10**8 invocations.  Needless to say, this hasn't happened 
yet.  But Murphy's Law may get me, and I will go to *three* locks, and 
take my chances on one in 10**12!

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


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

Date: Wed, 28 Oct 1998 22:38:44 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: Simple regular expression (HELP).....
Message-Id: <7186dl$l3b$1@nnrp1.dejanews.com>

In article <717v8g$abv$1@nnrp1.dejanews.com>,
  amatot@my-dejanews.com wrote:

> Could someone help me with this. I'm sure it's easy, but I can't get it to
> work. All I won't to do is create a regular expression that searchs a string
> for the first occurance of a double quote (") or the end of line (which ever
> comes first) and substitutes everything up to but not including the double
> quote or new line. Can one expression cover both case? For example:
>
> string1 = @(#)this is a string"; /* comment */
> string2 = @(#)this is another string   /* comment */
> string3 = @(#)%Z% %M%
>
> If strings 1 and 2 where given to the reqular expression (using string 3 as
> the replacement string) you would get:
>
> string1 = @(#)%Z% %M%"; /* comment */
> string2 = @(#)%Z% %M%

$string3 = "@(#)\%Z% \%M%";
while(<DATA>) { /.*?(".*)/ ? print "$string3$1\n" : print "$string3\n"; }

__DATA__
@(#)this is a string"; /* comment */
@(#)this is another string   /* comment */
etc etc

Patrick Timmins
$monger{Omaha}[0]

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 28 Oct 1998 22:01:52 GMT
From: nguyen.van@imvi.bls.com
Subject: sort numericaly and uniq like Korn shell
Message-Id: <71848g$htu$1@nnrp1.dejanews.com>

Hi guys,

I have a file with the following format:

______________________________________________________________________

Netscape_4.06
Netscape_4.06
Netscape_4.06
Netscape_4.06
Netscape_4.0
Netscape_4.06
Netscape_4.06
Netscape_4.0
Netscape_4.04
Netscape_4.04
Netscape_4.05
Netscape_4.0
Netscape_2.0
Netscape_4.04
Netscape_4.06
Netscape_4.0
Netscape_2.0
Netscape_4.06
Netscape_2.0
Netscape_4.01
_______________________________________________________________________

I want to sort it numerically and do a "uniq -c" like korn shell to know
munber of occurences (i.e how many times Netscape_4.06 occur). However, I
want to output should be like this:

Netscape_4.06 13 where "13" is munber of occurences. your help is apprecited.

Thanks
Van Nguyen

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 28 Oct 1998 23:09:45 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: sort numericaly and uniq like Korn shell
Message-Id: <71887p$bh14@mercury.adc.com>

In article <71848g$htu$1@nnrp1.dejanews.com>,  <nguyen.van@imvi.bls.com> wrote:
>Hi guys,
>
>I have a file with the following format:
>
>______________________________________________________________________
>
>Netscape_4.06
>Netscape_4.06
>Netscape_4.06
>Netscape_4.06
>Netscape_4.0
>Netscape_4.06
>Netscape_4.06
>Netscape_4.0
>Netscape_4.04
>Netscape_4.04
>Netscape_4.05
>Netscape_4.0
>Netscape_2.0
>Netscape_4.04
>Netscape_4.06
>Netscape_4.0
>Netscape_2.0
>Netscape_4.06
>Netscape_2.0
>Netscape_4.01
>_______________________________________________________________________
>
>I want to sort it numerically and do a "uniq -c" like korn shell to know
>munber of occurences (i.e how many times Netscape_4.06 occur). However, I
>want to output should be like this:
>
>Netscape_4.06 13 where "13" is munber of occurences. your help is apprecited.


chomp, $counts{$_}++ while(<>);

print(map "$_ $counts{$_}\n", sort keys %counts);

-- 
 _____ 
|///  |   Brand Hilton  bhilton@adc.com
|  ADC|   ADC Telecommunications, ATM Transport Division
|_____|   Richardson, Texas


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

Date: Wed, 28 Oct 1998 15:59:36 -0600
From: Rob Bridal <rbridal@bcl.net>
Subject: Trapping the output of a system call...
Message-Id: <363793C8.9B624A5C@bcl.net>

Hello,

i know I should already know this, but I can't find it anywhere.  I
checked the PerlDocs and searched the newsgroup.  I need a way to trap
the output of a system call, such as a whois.  I know system() and
exec() won't work for trapping it.

Thank you in advance,
Rob Bridal


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

Date: 28 Oct 1998 14:50:09 PST
From: "Tupshin Harper" <tupshin@tupshin.com>
Subject: Re: Trapping the output of a system call...
Message-Id: <newscache$lf7k1f$4mg@debian>

$result=`sys_command`;




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

Date: Wed, 28 Oct 1998 22:59:34 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Trapping the output of a system call...
Message-Id: <qlNZ1.5$vh5.2652@nsw.nnrp.telstra.net>

In article <363793C8.9B624A5C@bcl.net>,
	Rob Bridal <rbridal@bcl.net> writes:
> Hello,
> 
> i know I should already know this, but I can't find it anywhere.  I
> checked the PerlDocs and searched the newsgroup.  I need a way to trap
> the output of a system call, such as a whois.  I know system() and
> exec() won't work for trapping it.

I suppose that with 'trap' you mean that you want to get hold of the
stuff that whois outputs? it's in the manual. It's in the section for
system().

# perldoc -f system
[snip]
This is I<NOT> what you want to use to capture
the output from a command, for that you should use merely backticks or
qx//, as described in L<perlop/"`STRING`">.
[snip]

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

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


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 4096
**************************************

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