[28395] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9759 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 24 06:05:50 2006

Date: Sun, 24 Sep 2006 03:05:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 24 Sep 2006     Volume: 10 Number: 9759

Today's topics:
        FYI: Something I saw on generating random-numbers (David Combs)
    Re: Learning perl - for experienced programmers <strombrg@gmail.com>
        new CPAN modules on Sun Sep 24 2006 (Randal Schwartz)
    Re: perl sort <bik.mido@tiscalinet.it>
    Re: Russel Quong's "Perl in 20 pages" <wahab@chemie.uni-halle.de>
    Re: submatch scoping in while (reading news)
    Re: submatch scoping in while <noreply@gunnar.cc>
    Re: submatch scoping in while <wahab@chemie.uni-halle.de>
    Re: submatch scoping in while <rvtol+news@isolution.nl>
    Re: submatch scoping in while <nobull67@gmail.com>
    Re: submatch scoping in while (reading news)
    Re: submatch scoping in while (Julian Bradfield)
        tying db records and other objects, speed? <skimba@dambo.di>
        Zero equals pipe?? ilya2@rcn.com
    Re: Zero equals pipe?? <kenslaterpa@hotmail.com>
    Re: Zero equals pipe?? <john@castleamber.com>
    Re: Zero equals pipe?? <sisyphus1@nomail.afraid.org>
    Re: Zero equals pipe?? <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 23 Sep 2006 21:57:32 -0400
From: dkcombs@panix.com (David Combs)
Subject: FYI: Something I saw on generating random-numbers
Message-Id: <ef4omc$svm$1@panix2.panix.com>

I like to lurk over at comp.graphics.algorithms -- extremely
good math stuff, and explanations, there.

(Not that I understand any of it!)

Especially long posts by this guy/gal who goes by "d'FAQS".

Since generation of random numbers is often talked about
here in this group, for those who like that kind of stuff,
  [even you likely know most if not all of these methods]
I post this (and which I just saw):


From nobody-here@mac.com Sat Sep 23 21:49:00 EDT 2006
Article: 165648 of comp.graphics.algorithms
NNTP-Posting-Date: Sat, 02 Sep 2006 20:02:38 -0500
From: Just d' FAQs <nobody-here@mac.com>
Newsgroups: comp.graphics.algorithms
Subject: Re: Stochastic Positioning of A Point in A 3D Gaussian Distribution
Xref: panix comp.graphics.algorithms:165648

On 1 Sep 2006 09:56:43 -0700, hoffmann@fho-emden.de wrote:
>1. Why is the Box-Muller Transform, which converts two PRNG
>   (pseudo random number generator)  numbers u1,u2 with
>   uniform distributions into a geometrical pair x,y with Gaussian
>   distributions, better than a transform which converts simply
>   one PRNG number with uniform distribution into one number
>   with Gaussian distribution ?
>   http://en.wikipedia.org/wiki/Box-Muller_transform
>   The OP needs obviously THREE numbers for x,y,z.
>
>2. Numbers by a PRNG with uniform distribution can be trans-
>   formed into numbers with Gaussian distribution either by adding
>   N numbers or by averaging N numbers.
>   E.g. one can find that N=6 is reasonable and N=12 is near to
>   perfect.
>   IMO this is perhaps faster than using Box-Muller.
>   Is any comparison of quality available ?

There is no reason anyone should need to write their own pseudo-random
number generator, whether for uniform or Gaussian distributions. It's
really easy to create a bad uniform generator, and even the venerable
Box-Muller generator for Gaussians has two major variations, one of
which is troublesome.

Four possibilities are:

 * Box-Muller: this gives two independent variates for each call, and
   is still fast even if one is discarded.
 * Ratio: This is a method using rejection, and the ellipse regions of
   Leva make it fast as well as brief.
 * Averaging uniform: This is both slow and inaccurate, it is not to
   be recommended even with some known adjustments.
 * Ziggurat: A variation of the "rectangle-wedge-tail" approach, this
   tends to be the fastest, but requires a large table.

Two good sources to consult are Luc Devroye,

  <http://cg.scs.carleton.ca/~luc/rng.html>

(including his book, a free download),

  <http://cg.scs.carleton.ca/~luc/books-luc.html>

and Knuth,

  Knuth, D. The Art of Computer Programming, Vol. II., 3/e.

Or just grab an implementation, such as winrand,

  <http://crypto.mat.sbg.ac.at/ftp/pub/data/winrand.zip>

or the GNU Scientific Library (GSL).

  <http://www.gnu.org/software/gsl/>





I hope it turns out of interest.

David




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

Date: Sun, 24 Sep 2006 00:19:41 GMT
From: strombrg <strombrg@gmail.com>
Subject: Re: Learning perl - for experienced programmers
Message-Id: <pan.2006.09.24.00.20.07.13060@gmail.com>

On Fri, 15 Sep 2006 15:29:42 -0700, Matt Garrish wrote:

> 

> 
>> In my job, I use ColdFusion, Perl, and Java. Each language has its good
>> uses and bad uses. Perl is very good for one off scripts of less than
>> 25 - 50 lines.
> 
> I don't follow the logic of that. It sounds like you need a lesson in
> OO Perl if you can only write procedural code that can't be maintained
> (and I've never heard of a language that is only good until a certain
> number of lines has been passed, to be honest).

First generation BASIC was definitely better for short programs.

> Basic design practices are basic design practices. If you'd like some
> examples of hideous and unmaintainable Java code there's plenty I'm
> sifting through at my current job. A language is only as bad as the
> person writing it.

Not at all.  You couldn't possibly say that a program is equally well
expressed on all of the following:

1) a Turing machine
2) in MIX
3) in machine language
4) in assembler
5) in an advanced macro assembler
6) First generation BASIC, with goto's and gosub's and no formal
procedures and no local variables
7) FORTRAN 77, with comments in a magic column and line extension in
another
8) in K&R C
9) in ANSI C
A) in Pascal
B) in current generation Visual BASIC
C) FORTRAN 90, with modules and freeform lines
D) in C++
E) In Turing, the systems programming language with good defaults and
overrides for everything else
F) in SQL
10) in python
11) in /bin/sh
12) in Sather
13) in OCaML
14) in Haskell

 ...could you? It's possible to write good or bad code in just about
any language, but some languages definitely make it easier to write bad
code and other languages definitely make it easier to write good code.

Also, some languages require:

1) One to learn a little or a lot before starting to write and
maintain one's own code 
2) One to learn a little or a lot before starting to maintain others' code

I'm not talking about algorithms.  I'm talking about the expression of
algorithms.  Algorithms can be complex in any language, but ideally simple
algorithms will be simple to express, and complex algorithms will be as
simple as possible and no simpler :)

All this "Your code's exactly as good as the programmer" stuff seems a bit
disingenuous to me.  I'd say it's more like the language is one vector,
and the programmer is another, and the problem domain is a third, and how
good the code is, is a some of those vectors.

> Consider also that to most people the benefit of perl is cpan and the
> active community, and that the modules you're using to make your scripts
> so short are probably many thousands of lines of maintainable code (or
> not, as not everything in cpan smells like roses).

Yeah, pretty much.




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

Date: Sun, 24 Sep 2006 04:42:09 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Sun Sep 24 2006
Message-Id: <J62yE9.Jo2@zorch.sf-bay.org>

The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN).  You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.

Astro-satpass-0.010
http://search.cpan.org/~wyant/Astro-satpass-0.010/
----
CGI-Application-Plugin-JSON-0.2
http://search.cpan.org/~wonko/CGI-Application-Plugin-JSON-0.2/
easy manipulation of JSON headers
----
CMS-MediaWiki-0.080008
http://search.cpan.org/~retoh/CMS-MediaWiki-0.080008/
Perl extension for creating and updating MediaWiki pages
----
Carp-Clan-5.4
http://search.cpan.org/~jjore/Carp-Clan-5.4/
Report errors from perspective of caller of a "clan" of modules
----
Catalyst-Runtime-5.7003
http://search.cpan.org/~mramberg/Catalyst-Runtime-5.7003/
Catalyst Runtime version
----
Data-Pagination-0.37
http://search.cpan.org/~ondr/Data-Pagination-0.37/
Paginal navigation on some data
----
DateTime-Util-DayOfWeek-Locale-0.04
http://search.cpan.org/~tokuhirom/DateTime-Util-DayOfWeek-Locale-0.04/
DateTime Localized Day of Week Utilities
----
FFmpeg-Command-0.06
http://search.cpan.org/~mizzy/FFmpeg-Command-0.06/
A wrapper class for ffmpeg command line utility.
----
FLV-Info-0.13
http://search.cpan.org/~clotho/FLV-Info-0.13/
Extract metadata from Macromedia Flash Video files
----
File-Find-Rule-VCS-1.02
http://search.cpan.org/~adamk/File-Find-Rule-VCS-1.02/
Exclude files/directories for Version Control Systems
----
File-Size-0.01
http://search.cpan.org/~ofer/File-Size-0.01/
Perl extension for blah blah blah
----
File-Size-0.02
http://search.cpan.org/~ofer/File-Size-0.02/
Get the size of files and directories
----
Gnome2-Vte-0.07
http://search.cpan.org/~tsch/Gnome2-Vte-0.07/
Perl interface to the Virtual Terminal Emulation library
----
Gnome2-Wnck-0.14
http://search.cpan.org/~tsch/Gnome2-Wnck-0.14/
Perl interface to the Window Navigator Construction Kit
----
HTML-Perlinfo-1.45
http://search.cpan.org/~accardo/HTML-Perlinfo-1.45/
Display a lot of Perl information in HTML format
----
Handel-0.99_14
http://search.cpan.org/~claco/Handel-0.99_14/
Simple commerce framework with AxKit/TT/Catalyst support
----
Module-Inspector-0.01
http://search.cpan.org/~adamk/Module-Inspector-0.01/
An integrated API for inspecting Perl distributions
----
Module-ScanDeps-0.64
http://search.cpan.org/~smueller/Module-ScanDeps-0.64/
Recursively scan Perl code for dependencies
----
Net-Address-Ethernet-1.081
http://search.cpan.org/~mthurn/Net-Address-Ethernet-1.081/
find hardware ethernet address
----
Object-InsideOut-2.02
http://search.cpan.org/~jdhedden/Object-InsideOut-2.02/
Comprehensive inside-out object support module
----
POE-Stage-0.01_00
http://search.cpan.org/~rcaputo/POE-Stage-0.01_00/
a proposed base class for formalized POE components
----
PPI-1.118
http://search.cpan.org/~adamk/PPI-1.118/
Parse, Analyze and Manipulate Perl (without perl)
----
SVK-1.99_01
http://search.cpan.org/~clkao/SVK-1.99_01/
A Distributed Version Control System
----
Sledge-Plugin-PluginLoader-0.02
http://search.cpan.org/~tokuhirom/Sledge-Plugin-PluginLoader-0.02/
plugin loader
----
Template-Simple-0.01
http://search.cpan.org/~uri/Template-Simple-0.01/
A simple and fast template module
----
Test-Deep-0.096
http://search.cpan.org/~fdaly/Test-Deep-0.096/
Extremely flexible deep comparison
----
Test-WWW-Mechanize-Plugin-Jcode-0.02
http://search.cpan.org/~tokuhirom/Test-WWW-Mechanize-Plugin-Jcode-0.02/
add the charset test method to Test::WWW::Mechanize
----
WWW-IndexParser-0.5
http://search.cpan.org/~jeb/WWW-IndexParser-0.5/
Fetch and parse the directory index from a web server


If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.

This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
  http://www.stonehenge.com/merlyn/LinuxMag/col82.html

print "Just another Perl hacker," # the original

--
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: 24 Sep 2006 12:02:03 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: perl sort
Message-Id: <gc4bh2t4ik94d61e6dc7d43vvqktiqptq2@4ax.com>

On Fri, 22 Sep 2006 21:06:00 +0100, Ben Morrow
<benmorrow@tiscali.co.uk> wrote:

>> perl -e 'print join "\n", sort { -M $b <=> -M $a } <*>,"\n"'
>
>You can skip the last "\n" by adding a -l to your commandline.
>You can skip the join by putting
>
>    $, = "\n";
>
>before the print statement, though that's arguably no simpler in this
>case.

And lazy guys like me, when they have -l, also like to

  print for something();

in oneliners.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Sun, 24 Sep 2006 01:23:05 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Russel Quong's "Perl in 20 pages"
Message-Id: <ef4ftm$69t$1@mlucom4.urz.uni-halle.de>

Thus spoke John Bokma (on 2006-09-22 01:00):

> I will review 
> <http://visibooks.com/pdfs/TheVisibooksGuidetoPERLBasics50.pdf>
> this book  next week when I am hopefully recovered of the first 
> glance at excerpt.

Regarding the purpose of the whole Visibooks stuff,
(http://visibooks.com/study.html) the book *might* be
not that bad after all.

To give, from the start, young people clear
instructions to get technical things done
(which they don't really understand and didn't
expect to master at all) helps them to get a
sense of self-efficacy and motivates them for
some time.

BTW. ist says "Web programming" and your
link has only first 50 of 150 pages in it,
the Perl stuff starts at page 45 somewhere.

Regards

Mirco


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

Date: Sat, 23 Sep 2006 22:09:43 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: submatch scoping in while
Message-Id: <HgiRg.5391$UG4.5094@newsread2.news.pas.earthlink.net>

On 09/23/2006 03:14 PM, Julian Bradfield wrote:
> Consider the following:
> 
> @x = ( 'aaa','bbb');
> while ( $x[$i] !~ /^(.)b/ && $i <= $#x ) { $i++; }
> print "\$1 is *$1*, i is $i\n";
> 
> The loop terminates at $i == 1 when 'bbb' matches ^(.)b
> The enclosing block for the match construct is the whole file.
> Therefore $1 should be 'b'.
> 
> But it isn't (in Perl 5.8.5).
> 
> What am I missing?
> 
> Compare
> 
> @x = ( 'aaa','bbb'); 
> if ( $x[$i] !~ /^(.)a/ && $i <= $#x ) { $i++; } 
> print "\$1 is *$1*, i is $i\n"; 
> 
> which behaves as expected.

It seems that the match variables are localized to the while block. The 
"if" statement does not do this.

If you want to use while, store the value ($1) elsewhere when you get a 
match:

use strict;
use warnings;
my ($i, $c, @x) = (0, 0);

@x = ('aaa', 'bbb');
while (! ($x[$i] =~ /^(.)b/ && ($c = $1))) {
     $i++;
}
print "\$c is *$c*, i is $i\n";

__END__

TMTOWTDI

If you don't need to know which element matched, this should work:

use strict;
use warnings;
my ($i, $c, @x) = (0, 0);

@x = ('aaa', 'rbb', 'bbb', 'cbb', 'xxy');
if ((join ':', @x) =~ /(^|:)(.)b/) {
     print "\$2 is $2\n";
}

__END__

Here is some gratuitous use of s/// :-)

use strict;
use warnings;
my ($i, $c, @x) = (0);

@x = ('aaa', 'rbb', 'bbb', 'cbb', 'xxy');
s/^(.)b/$c ||= $1, $&/e for (@x);
print "\$c is $c\n";


__KEWL__


-- 
paduille.4058.mumia.w@earthlink.net




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

Date: Sun, 24 Sep 2006 00:25:25 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: submatch scoping in while
Message-Id: <4nlqetFaroshU1@individual.net>

Julian Bradfield wrote:
> Consider the following:
> 
> @x = ( 'aaa','bbb');
> while ( $x[$i] !~ /^(.)b/ && $i <= $#x ) { $i++; }
> print "\$1 is *$1*, i is $i\n";
> 
> The loop terminates at $i == 1 when 'bbb' matches ^(.)b
> The enclosing block for the match construct is the whole file.
> Therefore $1 should be 'b'.

No. Even if 'bbb' matches ^(.)b at the last loop iteration, you don't 
test that. You test whether they *do not* match, so the test fails, and 
$1 is not set.

> What am I missing?

Combining capturing parentheses and the !~ operator is not a good idea. 
In addition to that, as Mumia pointed out, the dollar-digit variables 
(when set) seem to be scoped to the while block.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Sun, 24 Sep 2006 00:20:57 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: submatch scoping in while
Message-Id: <ef4c95$59s$1@mlucom4.urz.uni-halle.de>

Thus spoke Julian Bradfield (on 2006-09-23 22:14):

> Consider the following:
> 
> @x = ( 'aaa','bbb');
> while ( $x[$i] !~ /^(.)b/ && $i <= $#x ) { $i++; }
> print "\$1 is *$1*, i is $i\n";
> 
> The loop terminates at $i == 1 when 'bbb' matches ^(.)b
> The enclosing block for the match construct is the whole file.
> Therefore $1 should be 'b'.

Right As Mumia noted already, there is of somehow a
block, which is: { $i++; }, where the $1 is localized to.

see:

  $i = 0;
  @x = ('aaa','bbb');

  $i++  while ( $x[$i] !~/^(.)b/ && $i<@x ) ;

  print "\$1 is *$1*, i is $i\n";


Regards

Mirco


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

Date: Sun, 24 Sep 2006 00:20:27 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: submatch scoping in while
Message-Id: <ef4j0k.1dk.1@news.isolution.nl>

Julian Bradfield schreef:

> Consider the following:
>
> @x = ( 'aaa','bbb');
> while ( $x[$i] !~ /^(.)b/ && $i <= $#x ) { $i++; }
> print "\$1 is *$1*, i is $i\n";
>
> The loop terminates at $i == 1 when 'bbb' matches ^(.)b
> The enclosing block for the match construct is the whole file.
> Therefore $1 should be 'b'.

(Perl 5.8.6)
It seems that $1 is localized inside a while(...){...} or for(...){...}.

#!/usr/bin/perl
  use warnings ;
  use strict ;

  'X' =~ /(.)/ ;  #  sets $1 to 'X'

  my @x = ('aaa', 'bbb') ;

  for (@x) {
    /^(.)a/ and print "1:$1:\n" and last ;
  }
  print "2:$1:\n";

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: 23 Sep 2006 16:17:48 -0700
From: "Brian McCauley" <nobull67@gmail.com>
Subject: Re: submatch scoping in while
Message-Id: <1159053468.255942.240260@m73g2000cwd.googlegroups.com>


Julian Bradfield wrote:
> Consider the following:
>
> @x = ( 'aaa','bbb');
> while ( $x[$i] !~ /^(.)b/ && $i <= $#x ) { $i++; }
> print "\$1 is *$1*, i is $i\n";
>
> Compare
>
> @x = ( 'aaa','bbb');
> if ( $x[$i] !~ /^(.)a/ && $i <= $#x ) { $i++; }
> print "\$1 is *$1*, i is $i\n";
>
> which behaves as expected.

Actually, for what it's worth I find while's behaviour is expected and
if's is not.

With while() lexical variables, dynamic (package) variables and the
match capture variables behave consistantly. With if() the lexical
variable is inconsistant with the other two. But of course lexical
variables are and order of magnitude more prevalent in Perl programming
so my intuative expectation is based on their behaviour.

use strict;
use warnings;

'unchanged' =~ /(.*)/; # Assign $1
our $pkg = 'unchanged';
my $lex = 'unchanged';

while ( 'x'=~/(.*)/ and my $lex='y' and local $pkg='z' and 0 ) { die }
print "$1 $lex $pkg\n"; # unchanged unchanged unchanged

if ( 'x'=~/(.*)/ and my $lex='y' and local $pkg='z' and 0 ) { die }
print "$1 $lex $pkg\n"; # x unchanged y

__END__



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

Date: Sun, 24 Sep 2006 01:22:47 GMT
From: "Mumia W. (reading news)" <paduille.4058.mumia.w@earthlink.net>
Subject: Re: submatch scoping in while
Message-Id: <H5lRg.11540$v%4.975@newsread1.news.pas.earthlink.net>

On 09/23/2006 05:20 PM, Mirco Wahab wrote:
> [...]
>   $i = 0;
>   @x = ('aaa','bbb');
> 
>   $i++  while ( $x[$i] !~/^(.)b/ && $i<@x ) ;
> 
>   print "\$1 is *$1*, i is $i\n";
> 
> 
> Regards
> 
> Mirco

That's pretty good. It's just an inverted version of the OP's code; I 
wish I'd tried it. This idea crossed my mind for about ¼ a second, but I 
assumed that the same blocking problem would be there.

Oh well, at least I got to use the s/// operator where it isn't needed :-)


-- 
paduille.4058.mumia.w@earthlink.net


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

Date: Sun, 24 Sep 2006 07:08:10 +0000 (UTC)
From: jcb@inf.ed.ac.uk (Julian Bradfield)
Subject: Re: submatch scoping in while
Message-Id: <ef5asq$ciu$1@scotsman.ed.ac.uk>

In article <4nlqetFaroshU1@individual.net>,
Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote:

>> @x = ( 'aaa','bbb');
>> while ( $x[$i] !~ /^(.)b/ && $i <= $#x ) { $i++; }
>> print "\$1 is *$1*, i is $i\n";
 ...
>No. Even if 'bbb' matches ^(.)b at the last loop iteration, you don't 
>test that. You test whether they *do not* match, so the test fails, and 
>$1 is not set.

Wrong. As demonstrated by the if example later in my post, match variables 
are set by a !~ . (Otherwise  $a !~ /foo/  would not be equivalent to
! ($a =~ /foo/)   !)

>In addition to that, as Mumia pointed out, the dollar-digit variables 
>(when set) seem to be scoped to the while block.

This seems to be the case, but it's not what the manual says.
So there's a bug either in Perl or in the manual.


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

Date: Sun, 24 Sep 2006 11:11:20 +0300
From: Oobi Van Doobi <skimba@dambo.di>
Subject: tying db records and other objects, speed?
Message-Id: <lCqRg.18783$Au2.16784@reader1.news.jippii.net>

Hi,
have some issues regarding tying of db records.
I have the past few days done a class/package that tie's a database record
to a hash. I am very happy with this solution, as I can just take the CGI
params and put them into the hash, and voila they are in the database. 

But:What about speed? Could some kind soul please advice a little if this
(tie'ing records like this) is a good thing to do, or if I should take
another route. 

Background to the project:
1)web application
2)mod_perl to some extent
3)number of users only about 5-10 
4)using MySQL

Many thank's and have a good day
G



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

Date: 23 Sep 2006 18:17:38 -0700
From: ilya2@rcn.com
Subject: Zero equals pipe??
Message-Id: <1159060658.550982.283190@k70g2000cwa.googlegroups.com>

My perl program had some conditional statements that checked whether a
given characters was a pipe "|" or not. The program behaved strangely,
and I quickly realized it was treating pipes and zeros equivalently. To
make sure I was not going insane, I put the following checks:

if ( '1' == '|')  {  ... some statement ... }

if ( '0' == '|')  {  ... another statement ... }

By any sensible measure, both statements must return FALSE. First one
did that. Second one returned TRUE.

What's going on and how do I get around it?



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

Date: 23 Sep 2006 18:36:31 -0700
From: "kens" <kenslaterpa@hotmail.com>
Subject: Re: Zero equals pipe??
Message-Id: <1159061791.612178.47570@k70g2000cwa.googlegroups.com>


ilya2@rcn.com wrote:
> My perl program had some conditional statements that checked whether a
> given characters was a pipe "|" or not. The program behaved strangely,
> and I quickly realized it was treating pipes and zeros equivalently. To
> make sure I was not going insane, I put the following checks:
>
> if ( '1' == '|')  {  ... some statement ... }
>
> if ( '0' == '|')  {  ... another statement ... }
>
> By any sensible measure, both statements must return FALSE. First one
> did that. Second one returned TRUE.
>
> What's going on and how do I get around it?

My guess is that you do not want to do a numerical comparison.
Use 'eq' for a stringwise comparison.
Ken



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

Date: 24 Sep 2006 01:58:04 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Zero equals pipe??
Message-Id: <Xns9847D57FF6CC7castleamber@130.133.1.4>

ilya2@rcn.com wrote:

> My perl program had some conditional statements that checked whether a
> given characters was a pipe "|" or not. The program behaved strangely,
> and I quickly realized it was treating pipes and zeros equivalently. To
> make sure I was not going insane, I put the following checks:
> 
> if ( '1' == '|')  {  ... some statement ... }
> 
> if ( '0' == '|')  {  ... another statement ... }
> 
> By any sensible measure, both statements must return FALSE.


== is for numbers, eq is for strings, which makes sense.

What makes even more sense, if you're a newbie to Perl, put on top of your 
script:

use strict;
use warnings;

Since then you would have seen:

Argument "|" isn't numeric in numeric eq (==)

-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: Sun, 24 Sep 2006 12:57:22 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: Zero equals pipe??
Message-Id: <4515f51c$0$22937$afc38c87@news.optusnet.com.au>


<ilya2@rcn.com> wrote in message
 .
 .
>
> if ( '0' == '|')  {  ... another statement ... }
>

Any string that begins with numeric characters will be assigned the numeric
value of those numeric characters. Hence:

'1' == 1
'0' == 0
'1234' == 1234
'1234garbage' == 1234
'12garbage34' == 12

But any string that begins with a non-numeric character will be assigned a
numeric value of 0.Hence:

'garbage1234' == 0
'|' == 0

From that you can see that '0' == '|' will evaluate as true since 0 == 0.

(This is documented somewhere .... but damned if I could find it in a hurry
:-)

Cheers,
Rob




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

Date: Sun, 24 Sep 2006 03:12:22 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Zero equals pipe??
Message-Id: <qImRg.958$422.864@trnddc03>

ilya2@rcn.com wrote:
> My perl program had some conditional statements that checked whether a
> given characters was a pipe "|" or not. The program behaved strangely,
> and I quickly realized it was treating pipes and zeros equivalently.
> To make sure I was not going insane, I put the following checks:
>
> if ( '1' == '|')  {  ... some statement ... }
>
> if ( '0' == '|')  {  ... another statement ... }
>
> By any sensible measure, both statements must return FALSE. First one
> did that. Second one returned TRUE.
>
> What's going on and how do I get around it?

Well, the numerical values of your three strings are
 '1' ==> 1
 '0' ==> 0
 '|' ==> 0
In other words you got the following comparions (partially evaluated):

> if ( 1 == 0 )  {  ... some statement ... }
> if ( 0 == 0 )  {  ... another statement ... }

If you had used warnings then perl would have told you.

You may also want to check the FAQ
    "What's wrong with always quoting "$vars"?"
There is absolutely no need to quote your numbers and in fact those 
superflous quotes led you down the wrong path.

jue






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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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