[10506] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4098 Volume: 8

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

Date: Wed, 28 Oct 98 18:01:33 -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: 4098

Today's topics:
        Perl Programming Workshop <dmurray@dgesolutions.com>
    Re: perl trinary operator oddity <dgris@rand.dimensional.com>
    Re: perl trinary operator oddity <ljz@asfast.com>
    Re: perl trinary operator oddity <r28629@email.sps.mot.com>
    Re: perl trinary operator oddity <tchrist@mox.perl.com>
    Re: problem with file test -e (Martien Verbruggen)
    Re: psychology of language choice (was Re: language war <jorendorff@ixl.com>
        Python fun <jorendorff@ixl.com>
    Re: Re: Off the beaten path (Justin Wilde)
    Re: sort numericaly and uniq like Korn shell <murrayb@vansel.alcatel.com>
    Re: The point of curly braces <jorendorff@ixl.com>
        Vroman's ref: any updates to it? (David Combs)
        Win32 Question:  Regsvr32 via Perl <mfcoyle@bellatlantic.net>
        Win95 - Building Perl Modules using Microsoft VC++ Comp <r.r@att.net>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Thu, 29 Oct 1998 00:06:18 GMT
From: "Deborah Murray" <dmurray@dgesolutions.com>
Subject: Perl Programming Workshop
Message-Id: <01be02cf$f0e04cf0$d198c9d0@debhome>

UniForum Technology Training Institute presents:

Accelerated Perl Programming 
January 28-29, 1999
San Jose, CA

Call: 1-800-333-8649 to register.  Seating is limited to 15.

This hands-on technical training is accomplishment-oriented providing
attendees with real-life examples.  The workshop teaches the foundations of
Perl programming through a series of case studies and practical examples. 
Upon completion of the workshop, attendees will be able to write Perl
programs of their own.

Attendees will construct a realistic data processing package for a
business.  The essential components of the language are introduced as they
are used for data management, entry, and reporting.

Who Should Attend:
This course is for programmers who want to add Perl to their repertory of
languages. System and network administrators, application programmers,
authors of Web forms and advanced Web applications, Web masters, Web
developers and
planners, and client-server developers.   Experience programming in other
languages is assumed.
    
Workshop Objectives:
It teaches these essential Perl skills: 
write and run Perl scripts, on Unix or NT perform I/O use Perl's control
structures
process a variety of data and file types use Perl's built-in variables
and operators
write object-oriented Perl code handle errors, generate messages,
terminate gracefully 
use Perl's debugger 
 
For more information, visit
http://www.uniforum.org/web/education/perlworkshop.html



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

Date: Thu, 29 Oct 1998 00:02:10 GMT
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: perl trinary operator oddity
Message-Id: <m34ssotfgw.fsf@rand.dimensional.com>

"John R. Andrews" <jandrews@uic.edu> writes:

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

?: is an lvalue.  Those are equivalent to-

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

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: 28 Oct 1998 19:12:40 -500
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: perl trinary operator oddity
Message-Id: <ltemrskyyv.fsf@asfast.com>

"John R. Andrews" <jandrews@uic.edu> writes:

> [ ... ] 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";

This has to do with operator precedence.  If you try this one, you'll
get the results you expect:

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

In the past 29 years, I have programmed in quite a few different
languages, some of which have subtly or not-so-subtly different rules
of operator precedence.  Instead of trying to keep these various
precedence systems straight in my mind, I tend to make liberal use
(some would say over-use) of parentheses.  This allows me to ensure
that operations are performed the way *I* want them to be performed,
even if in many cases my parentheses are redundant.

Another advantage of this is that future programmers who have to
maintain my code, and who might be less experienced at a given
language than I am, will have an easier time understanding my intent.

I guess what I'm trying to say here is this: it's my opinion that when
there's doubt, it's best to err on the side of caution and use too
many parentheses.  And if your Perl code starts looking too much like
Lisp for your taste, you can always make intelligent use of spaces to
make your parenthesized statements more readable.


-- 
 Lloyd Zusman   ljz@asfast.com
 perl -le '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
 $t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
 $x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x"'


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

Date: Wed, 28 Oct 1998 18:19:22 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: perl trinary operator oddity
Message-Id: <3637B48A.E7C8EA90@email.sps.mot.com>

John R. Andrews wrote:
> 
> 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";
> 

Problem is that you ran into the precedence issue with ?: and +=
operators. Try these:

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

and both should print '2'.

Obviously reading just page 91 isn't enough, you should read page 76 too
;)

-tk


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

Date: 29 Oct 1998 00:25:40 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: perl trinary operator oddity
Message-Id: <718cm4$75m$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, "John R. Andrews" <jandrews@uic.edu> writes:
:$n = 1;
:print "True: ", (1 ? $n+=1 : $n+=1),"\n";
:$n = 1;
:print "False: ",(0 ? $n+=1 : $n+=1),"\n";


    % man perlop

      ....

       Because this operator produces an assignable result, using
       assignments without parentheses will get you in trouble.
       For example, this:

           $a % 2 ? $a += 10 : $a += 2

       Really means this:

           (($a % 2) ? ($a += 10) : $a) += 2

       Rather than this:

           ($a % 2) ? ($a += 10) : ($a += 2)

--tom
-- 
    "No, I'm not going to explain it. If you can't figure it out, 
     you didn't want to know anyway..." --Larry Wall 


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

Date: Thu, 29 Oct 1998 00:10:30 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: problem with file test -e
Message-Id: <WnOZ1.13$vh5.59288@nsw.nnrp.telstra.net>

In article <MPG.10a14b97ff825e72989846@nntp.hpl.hp.com>,
	lr@hpl.hp.com (Larry Rosler) writes:
> [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 

Hehe, ok, maybe I should qualify that a bit more:

Always, always use an atomic operation to lock a resource if you need
to be 100% sure that it will not result in a race condition.

As you mention, one can come up with schemes that make it unlikely to
the nth degree that something nasty occurs, and in many cases that may
just be enough.

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 19:17:23 -0800
From: Jason Orendorff <jorendorff@ixl.com>
Subject: Re: psychology of language choice (was Re: language war ...)
Message-Id: <3637DE43.1DFE6AF8@ixl.com>

> nice arrays of hashes and many subs in one file. it even uses (gasp!)
> globals since i have to share many values across sub calls. i would hate
> to do this in a language that forced OO like java and python. perl lets
> me do OO or procedural and even mix the two (i call OO modules). that is
> flexibility to me.

This is utterly, utterly wrong (thank goodness!)

Python does *not* force OO, any more than Perl does.  Python likes
procedural code.  It likes global variables, too.[*]

The default in Python is for variables to be local, but you can change
the value of a global variable simply by declaring it:

  z = 0  #global z
  def showz():  print "z is:", z   #see the global z
  def f(x):  global z;  z=z+x      #change the global z

-- 
Jason

[*] Interestingly, neither Perl nor Python has "true" global
variables (anymore) in the same sense as C has 'em.


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

Date: Wed, 28 Oct 1998 19:42:41 -0800
From: Jason Orendorff <jorendorff@ixl.com>
Subject: Python fun
Message-Id: <3637E431.C8FDD0EE@ixl.com>

> > Is map2 a recent addition to the perl language or a user defined
> > function?
> 
> It's one that I could write in Perl.  That's the point.

Well, you *could* do it, but it might not be pretty.  You'd have to
use either references or typeglobs, I think.  Hopefully references.

In Tcl, ML, Python, or Lisp, you'll find it's much more fun.  Sorry
to say it, 'cos I like Perl too... but it's true.

> Although, it looks like it iterates once over all the vectors, in parallel.
> What if you wanted to iterate over the cartesian product?
> That's what I had in mind, but it could have been anything.

  def map_cartesian_product_2(fn, list1, list2):
      vals = []
      for item in list1:
          for item2 in list2:
              vals.append(fn(item, item2))
      return vals

-- 
jason


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

Date: Wed, 28 Oct 1998 16:47:51 -0700
From: jwilde@openskies.com (Justin Wilde)
Subject: Re: Re: Off the beaten path
Message-Id: <3637AD27.920B819B@openskies.com>

> I have seen this problem solved using JavaScript
and
> disabling the button once it has been pressed.
[snip]
> A cookie is another possibility, assuming that
the
> user has them turned on...
>
> I think that a temporary file that stores some
> information about the user may be the best
approach.
[snip]
>
> Good luck!
> Brent

Thanks Brent, for the suggestions.  This is moving
more
towards a CGI-related issue than I had hoped it
would.
But the issue's been presented and I'd imagine
others
have had this or similar problems.

I have considered using Javascript on another
"middle-man" script (which handles purchasing) to
populate hidden fields then automatically forward
to the
final script as soon as the database responds.  It
still
doesn't solve the problem though, because now the
'back' button will cause that script to be run
again.

Is it truly possible that Perl does not provide a
way to
move data through another script, unnoticed by the

browser history?  I am not familiar with enough of
Perl's
functions to come up with a Perl-based solution.

        Justin






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

Date: 28 Oct 1998 15:36:09 -0800
From: Brad Murray <murrayb@vansel.alcatel.com>
Subject: Re: sort numericaly and uniq like Korn shell
Message-Id: <uemrsmf86.fsf@vansel.alcatel.com>

nguyen.van@imvi.bls.com writes:

> 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.

# replace DATA stuff with your own file handling or STDIN

while (<DATA>) {
  chomp;
  $count{$_}++;
}

foreach (keys %count) {
  print "$_ $count{$_}\n";
}

__DATA__
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

-- 
-o- Brad Murray                  "Most programs aren't released;
-o- Alcatel Canada                they are allowed to escape."
-o- Software Analyst                        Jeff DelPapa


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

Date: Wed, 28 Oct 1998 18:27:11 -0800
From: Jason Orendorff <jorendorff@ixl.com>
Subject: Re: The point of curly braces
Message-Id: <3637D27F.54FBF707@ixl.com>

> > Python continues lines if you have a (, [, or { that's still open
> > at the end of the line.  If that's not enough you can use \ to
> > continue lines, just like C.
>
> Just like C?  C is rather much like perl in this regard...  Aren't
> \-continuations only necessary in a multi-line #define?

Yep.  You occasionally see them inside long string constants, too.

Perl is almost as free-form as C, but I'm not sure.  It seems to me I
recall reading about one or two places where a newline before a left
parenthesis can change the meaning of a statement... nothing terribly
important, as I recall, just odd.  ;-)

Anyway, the practice is almost as rare in Python.  Typically, if you're
writing something long enough to need multiple lines, it's already got
some parentheses or brackets somewhere.

-- 
Jason
PythonMonger['Memphis'][0]


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

Date: Thu, 29 Oct 1998 01:34:12 GMT
From: dkcombs@netcom.com (David Combs)
Subject: Vroman's ref: any updates to it?
Message-Id: <dkcombsF1KF11.3qA@netcom.com>

Are there any updates that we can download
for Vroman's "perl 5 desktop reference"?

Like errata and additions (mostly additions, I'd
imagine)?

Thanks!



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

Date: Wed, 28 Oct 1998 19:11:25 -0500
From: "Mike Coyle" <mfcoyle@bellatlantic.net>
Subject: Win32 Question:  Regsvr32 via Perl
Message-Id: <718c13$1kt@world1.bellatlantic.net>

Is it possible to programatically register a .dll or .ocx via Perl, so that
you can monitor the success of the operation?  By running "system('regsvr32
/s' . $dll_name) ", I cannot be sure that it completed successfully.  I
cannot have the confirmation dialog box appear on the desktop (hence the
/s.)

Thanks,
    Mike




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

Date: 29 Oct 1998 00:45:40 GMT
From: "Rath" <r.r@att.net>
Subject: Win95 - Building Perl Modules using Microsoft VC++ Compiler
Message-Id: <718drk$dat@bgtnsc02.worldnet.att.net>

Hello Guys,
    I am quite keen on Building / Installing PERL
modules from Source.   I tried using DMAKE
provided by GURUSAMY SARATHY's
WIN32 set   or
Just trying to run Makefile from Microsoft's
VISUAL STUDIO.

    Can any one give me few pointers, Sites
etc... to try some more....

Thanks in Advance
Rath  r.r@att.net




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

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

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