[25552] in Perl-Users-Digest
Perl-Users Digest, Issue: 7796 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 18 00:05:44 2005
Date: Thu, 17 Feb 2005 21:05:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 17 Feb 2005 Volume: 10 Number: 7796
Today's topics:
[perl-python] exercise: partition a list by equivalence <xah@xahlee.org>
Re: [perl-python] exercise: partition a list by equival <wuwei23@gmail.com>
Archive::Zip - _isSeekable a bit bodgy <not@invalid.invalid>
Re: glob question axel@white-eagle.invalid.uk
Re: hash counter <lskatz@gmail.com>
Re: hash counter <1usa@llenroc.ude.invalid>
Help with research elena@monmouth.com
Re: ithreads + signals on modern Unices (Jay Tilton)
Modify keys in a %hash using tr/// or s/// <dreamer@cox.net>
Re: Modify keys in a %hash using tr/// or s/// <noreply@gunnar.cc>
Re: Modify keys in a %hash using tr/// or s/// <dreamer@cox.net>
Re: Reading compressed file and its conversion to numbe <strangeuser@nowhere.org>
Re: Reading compressed file and its conversion to numbe <jl_post@hotmail.com>
Re: Record Hash Data Structure (Newbie) rajasekaran.natarajan@gmail.com
Strange Problem rajasekaran.natarajan@gmail.com
Re: Strange Problem (Gary E. Ansok)
Re: Strange Problem xhoster@gmail.com
Re: Strange Problem rajasekaran.natarajan@gmail.com
Re: use strict; and O_WRONLY <spamtrap@dot-app.org>
Re: use strict; and O_WRONLY <noreply@gunnar.cc>
Re: use strict; and O_WRONLY <spamtrap@dot-app.org>
Re: use strict; and O_WRONLY <noreply@gunnar.cc>
Re: what is Perl state of the art? <postmaster@castleamber.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Feb 2005 15:46:20 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: [perl-python] exercise: partition a list by equivalence
Message-Id: <1108683980.894412.14060@z14g2000cwz.googlegroups.com>
here's another interesting algorithmic exercise, again from part of a
larger program in the previous series.
Here's the original Perl documentation:
=pod
merge($pairings) takes a list of pairs, each pair indicates the
sameness
of the two indexes. Returns a partitioned list of same indexes.
For example, if the input is
merge( [ [1,2], [2,4], [5,6] ] );
that means 1 and 2 are the same. 2 and 4 are the same. Therefore
1==2==4. The result returned is
[[4,2,1],[6,5]];
(ordering of the returned list and sublists are not specified.)
=cut
For those of you unfamiliar with math lingoes, partition a list means
to create sublists, based on some criteria. In our case, the input list
comes in the form of pairs, and its members are the union of all
members in the pairs. The criterion for partition in our case is that
of equivalence, specified in the pairs input.
Try to write a Python code for this. In the Python code, the input
should be a list of couples. (for Perlers, sketch out the algorithm on
paper and try to code in Python directly.)
I'll post Perl & Python code tomorrow.
==This is brought to you by the Perl-Python community.==
== http://xahlee.org/perl-python/python.html ==
Xah
xah@xahlee.org
http://xahlee.org/PageTwo_dir/more.html
------------------------------
Date: 17 Feb 2005 17:44:21 -0800
From: "alex23" <wuwei23@gmail.com>
Subject: Re: [perl-python] exercise: partition a list by equivalence
Message-Id: <1108691061.880747.95210@l41g2000cwc.googlegroups.com>
>For those of you unfamiliar with math lingoes, partition a list means
> to create sublists, based on some criteria.
Typical moronic mathematicians with their exclusionary lingoes...why
can't they just say "create sublists based on some criteria" like
normal people?
- alex23
------------------------------
Date: Fri, 18 Feb 2005 12:21:15 +1000
From: Matthew Braid <not@invalid.invalid>
Subject: Archive::Zip - _isSeekable a bit bodgy
Message-Id: <cv3jes$jq8$1@bunyip2.cc.uq.edu.au>
Hi all,
I've just found a rather annoying problem with Archive::Zip.
I'm using temp files (via File::Temp's tempfile function) to store
zipped data from a database. Unfortunately it seems there was a change
in the last version that makes Archive::Zip want a seekable handle for
the readFromFileHandle, and Archive::Zip doesn't want to believe that
temp files are seekable.
I checked the _isSeekable function in Archive::Zip:
sub _isSeekable # Archive::Zip
{
my $fh = shift;
if ( UNIVERSAL::isa( $fh, 'IO::Scalar' ) )
{
return 0;
}
elsif ( UNIVERSAL::isa( $fh, 'IO::String' ) )
{
return 1;
}
elsif ( UNIVERSAL::can( $fh, 'stat' ) )
{
return -f $fh;
}
return UNIVERSAL::can( $fh, 'seek' );
}
The problem is that the -f $fh is wrapped in a UNIVERSAL::can(). I've
never had much luck with UNIVERSAL::can(), and sure enough it's failing
here. A quick demo shows this:
use File::Temp qw/tempfile/;
my $fh = tempfile(UNLINK => 1);
print "Can stat? ", (UNIVERSAL::can($fh, 'stat') ? 1 : 0), "\n";
print "Is file? ", (-f $fh ? 1 : 0), "\n";
Can stat? 0
Is file? 1
A better way to do this test would be to use eval. Instead of:
elsif ( UNIVERSAL::can( $fh, 'stat' ) )
{
return -f $fh;
}
use:
return 1 if eval {-f $fh};
BTW, has anyone reliably used UNIVERSAL::can? It never seems to work for
me...
MB
------------------------------
Date: Thu, 17 Feb 2005 20:35:30 -0600
From: axel@white-eagle.invalid.uk
Subject: Re: glob question
Message-Id: <36mdnUGMBv_vyYjfRVn-vQ@adelphia.com>
Ted Zlatanov <tzz@lifelogs.com> wrote:
> On Mon, 14 Feb 2005, josef.moellers@fujitsu-siemens.com wrote:
> justme wrote:
>> while ( glob "*" )
>> {
>> next if /\.txt$/;
>> # Do something with non-txt
>> }
> The OP didn't say he wanted * without *.txt, so your example is
> incomplete. You need opendir() and readdir() to really get all the
> files in the directory, including the hidden ones.
Why?
#/usr/bin/perl -w
$\ = "\n";
# Print what a glob gives us
print join " ", glob ".* *";
# Print what using readdir gives us
opendir DIR, ".";
my @inlist = readdir DIR;
closedir DIR;
print join " ", @inlist;
Results:
. .. .r1.pl.swp .z.pl.swp 11-02-2050 aless_rob_udo.jpg apache_conf
bdb-conf DIRNAME DIRNAMEF m_i openldap-conf php_conf q1.c qa1 qa2.tar
qq.pl r1 r1.pl x x1.pl z.pl
. .. .r1.pl.swp .z.pl.swp 11-02-2050 aless_rob_udo.jpg apache_conf
bdb-conf DIRNAME DIRNAMEF m_i openldap-conf php_conf q1.c qa1 qa2.tar
qq.pl r1 r1.pl x x1.pl z.pl
Axel
------------------------------
Date: 17 Feb 2005 15:55:22 -0800
From: "Lee" <lskatz@gmail.com>
Subject: Re: hash counter
Message-Id: <1108684522.091414.285580@f14g2000cwb.googlegroups.com>
yeah I totally had a problem with my print statement. I was using an
array of keys before I tried switching over. When I switched over
without the array, I was unable to print any entry of the hash table
because I had no keys. Stupid me.
------------------------------
Date: Fri, 18 Feb 2005 00:41:31 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: hash counter
Message-Id: <Xns9600C8522C2FEasu1cornelledu@127.0.0.1>
"Lee" <lskatz@gmail.com> wrote in news:1108684522.091414.285580
@f14g2000cwb.googlegroups.com:
> Stupid me.
Some might call this an astute observation after your rant. Instead, I
will again try to direct your attention to the posting guidelines. The
guidelines contain valuable information on how to help other people help
you instead of yelling at them when they ask you to help them help you.
Sinan.
------------------------------
Date: 17 Feb 2005 15:41:32 -0800
From: elena@monmouth.com
Subject: Help with research
Message-Id: <1108683692.602896.52310@l41g2000cwc.googlegroups.com>
Apologies for this off-topic post.
I'm a Java/C++ developer who is also studying psychology.
I would really appreciate it if you would complete a survey that I'm
using for a research project on programmers.
It's easy [Yes/No answers] and takes about 5 minutes.
I will be presenting the results at the American Psychological
Association convention in August.
The study link is:
http://www.elena.com
The survey measures "cognitive style" (analytical/intuitive) which
describes how you process information and learn. The people I've
pre-tested it with found it to be pretty interesting.
I can go to my friends, however it occurred to me that it might be
better to post in a newsgroup and get a larger, more diverse, and
random sample.
Thanks again for your time,
Elena
------------------------------
Date: Fri, 18 Feb 2005 02:07:08 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: ithreads + signals on modern Unices
Message-Id: <42154a5d.765000652@news.erols.com>
Thomas Jahns <Thomas.Jahns@epost.de> wrote:
: Thomas Jahns <Thomas.Jahns@epost.de> writes:
[snip content that expands well upon the Subject: line]
: So does the lack of answers mean, that I
:
: - I did not describe my intended application clearly enough?
: - I should take this question to a Unix programming group?
: - I violated etiquette really badly?
: - noone except me cares about using threads and still handling
: signals, after all it has to work every time one calls system(), or
: not?
You've just summed up what is called "Warnock's Dilemma." That won't help
solve your problem, but at least you know it has a name. :)
Nothing really wrong with the article's content or topicality. I'm betting
on that last option--not enough people have used threads enough to offer
useful assistance.
------------------------------
Date: Thu, 17 Feb 2005 19:03:35 -0800
From: Fred Hare <dreamer@cox.net>
Subject: Modify keys in a %hash using tr/// or s///
Message-Id: <yv-dnQYSo_yWxojfRVnytg@giganews.com>
I have a script for comparing a dir of MP3-files to a DB-file. It works
OK unless there are files with high-ascii characters in the dir or in
the DB. I tried to add a conversion but I get errors like "uninitialized
value in pattern-match..."
Is there a way to alter the hash-keys using tr/// or s/// ?
Fred
# ~~~~~
use strict ;
use warnings ;
my $dir = 'E:\Audio' ;
my $outfile = 'D:\aa\MP3-dup.txt' ;
my $database = 'D:\aa\MP3-DB.txt' ;
my (%hash1, $hash1, %hash2, $hash2, %hash3, $hash3) ;
opendir(DIR, $dir) or die $!;
my @files = readdir DIR;
closedir(DIR);
chdir $dir;
open(OUT, "> $outfile") or die "Could not open OUT for writing: $!\n";
foreach my $infile ( @files ) {
next unless ( $infile =~ m/\.mp3$/i) ;
my $ctime = (stat($infile))[10];
my $size = (stat($infile))[7] ;
my $value = $ctime . "," . $size . " - deleted" ;
# $hash1{lc, convert(), ($infile)} = $value ; # =>error
$hash1{lc ($infile)} = $value ; # =>OK
}
open(DB, "< $database") or die "Could not open $database: $!\n";
my ($infile, $value) ;
while (<DB>) {
if( ($infile,$value) = m/^(.+?):(.+?)$/img ){
$hash2{lc($infile)} = $value ;
next ;
}
}
foreach $infile (sort keys %hash1){
next if $hash2{$infile} ;
}
my ($k, $v) ;
foreach $infile (\%hash1, \%hash2) {
while (($k, $v) = each %$infile) {
if (exists $hash2{$k} ) { next }
$hash3 {$k} = $v;
}
}
print OUT map { "$_ : $hash3{$_}\n" } keys %hash3 ;
close(OUT) or die "could not close OUT: $!";
close(DB) or die "could not close DB: $!";
sub convert {
if ($infile =~ /[óôöòõéèêáäãåà]/ ) {
$infile =~ tr/[óôöòõ]/o/;
$infile =~ tr/[éèê]/e/;
$infile =~ tr/[áäãåà]/a/;
}
}
__END__
------------------------------
Date: Fri, 18 Feb 2005 04:16:13 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Modify keys in a %hash using tr/// or s///
Message-Id: <37l5mfF5dg62mU1@individual.net>
Fred Hare wrote:
> I have a script for comparing a dir of MP3-files to a DB-file. It works
> OK unless there are files with high-ascii characters in the dir or in
> the DB. I tried to add a conversion but I get errors like "uninitialized
> value in pattern-match..."
> Is there a way to alter the hash-keys using tr/// or s/// ?
That's probably because $infile is lexically scoped to the foreach loop,
while you try to use it in a function outside the loop.
Try passing $infile to convert() like this:
$hash1{ lc convert($infile) } = $value;
and make convert() take the argument and return the altered string:
sub convert {
my $infile = shift;
if ($infile =~ /[óôöòõéèêáäãåà]/ ) {
$infile =~ tr/óôöòõ/o/;
$infile =~ tr/éèê/e/;
$infile =~ tr/áäãåà/a/;
}
$infile
}
Note that the [] notation for character classes shall not be used with
the tr/// operator (see "perldoc perlop").
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 17 Feb 2005 20:28:20 -0800
From: Fred Hare <dreamer@cox.net>
Subject: Re: Modify keys in a %hash using tr/// or s///
Message-Id: <xNKdnfQkE8p184jfRVnyhw@giganews.com>
Gunnar Hjalmarsson wrote:
> Fred Hare wrote:
>
>> I have a script for comparing a dir of MP3-files to a DB-file. It
>> works OK unless there are files with high-ascii characters in the dir
>> or in the DB. I tried to add a conversion but I get errors like
>> "uninitialized value in pattern-match..."
>> Is there a way to alter the hash-keys using tr/// or s/// ?
>
>
> That's probably because $infile is lexically scoped to the foreach loop,
> while you try to use it in a function outside the loop.
>
> Try passing $infile to convert() like this:
>
> $hash1{ lc convert($infile) } = $value;
>
> and make convert() take the argument and return the altered string:
>
> sub convert {
> my $infile = shift;
> if ($infile =~ /[óôöòõéèêáäãåà]/ ) {
> $infile =~ tr/óôöòõ/o/;
> $infile =~ tr/éèê/e/;
> $infile =~ tr/áäãåà/a/;
> }
> $infile
> }
>
> Note that the [] notation for character classes shall not be used with
> the tr/// operator (see "perldoc perlop").
Yes, that did it... Works now perfectly.
Thank you Gunnar, that was great help!
-- Fred
------------------------------
Date: 18 Feb 2005 00:44:21 -0500
From: Henry Lenzi <strangeuser@nowhere.org>
Subject: Re: Reading compressed file and its conversion to numbers.
Message-Id: <87is4qs9qi.fsf@nowhere.org>
"jl_post@hotmail.com" <jl_post@hotmail.com> writes:
>
>
> Dear Henry,
>
Hi --
Thanks for your help. I was able to improve it - but there's a bug, I
think - with the following:
###################################
#!/usr/bin/perl
use warnings;
use strict;
my $source = shift @ARGV;
my $destination = shift @ARGV;
open IN, $source;
#open OUT, "|gzip > $destination";
open OUT, "|gzip > ./OUTPUT";
print OUT <IN>;
open OUTPUTFILE, "< ./OUTPUT";
my @data;
@data = <OUTPUTFILE>;
print "@data\n";
my $data_r = \@data;
my $hex = unpack("H*", $data_r);
print "$hex\n";
close IN;
close OUT;
close OUTPUTFILE;
##################################
Some considerations:
1)
What did the trick was passing the array reference to unpack, in:
my $data_r = \@data;
my $hex = unpack("H*", $data_r);
From what I read in the Camel book, there wasn't a way to do it
_without_ passing a reference, because all has to be put into a
string. Right?
2)
The output is:
comp@ttyp2[play]$ perl p1.pl FILE1 OUTPUT2
ÝtB
ñ
ñqµUPòM,.I-ÊÌKWpÌIÏ/Ê,ÉÈ-R
©E9J
¡!þA@^ùy
þEåy%J:@^bQvv¾GfjIb^fjn&X0?#Ï7Ù%?/1'EIÁÕÅ3¬Ó_=(53'§R
:%mru
41525241592830783831393130373829
What I don't understand is why there aren't any numbers in hex
format. For instance, Ì is hex CC, decimal 204 already. So there's
something wrong, but I don't have a clue. Is it the array ref number
that was transformed, instead of the set of characters?
In that case, how would I get my @data passed to unpack? (Please
don't tell me there isn't a way without iterating line-by-line).
Any ideas/comments/help is appreciated.
TIA,
Henry
------------------------------
Date: 17 Feb 2005 19:34:49 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Reading compressed file and its conversion to numbers.
Message-Id: <1108697689.464651.156730@f14g2000cwb.googlegroups.com>
Henry Lenzi wrote:
>
> Some considerations:
>
> 1)
> What did the trick was passing the array reference to unpack, in:
>
> my $data_r = \@data;
>
> my $hex = unpack("H*", $data_r);
>
> From what I read in the Camel book, there wasn't a way to do it
> _without_ passing a reference, because all has to be put into a
> string. Right?
No -- you don't want to pass in a reference! You're right in saying
that it all has to be put in a string -- so you should join the array
into one long string with a line like:
my $dataString = join('', @data);
Then you can get the hex value with:
my $hex = unpack("H*", $dataString);
If you pass a reference in (which is what you did), the reference
will get converted to a string -- but not the one you want.
Try this code:
print 'String value of \@data: "', \@data, "\"\n";
What you'll see as output is something like this:
String value of \@data: "ARRAY(0x1a4deec)"
So when you pass in an array reference to unpack(), you won't be
converting its contents to hex, but rather a string like
"ARRAY(0x1a4deec)" instead.
> 2)
> The output is:
>
> 41525241592830783831393130373829
>
> What I don't understand is why there aren't any numbers in hex
> format.
I think you mean that no hexadecimal digits from A through F appear.
That's because when converted to hex form, the characters
"ARRAY(0x1a4deec)" don't happen to use the digits A through F (I
thought that was strange, so I tried:
print unpack "H*", "ARRAY(0x1a4deec)";
just to prove to myself that only the hex digits 0-9 are used.)
> Is it the array ref number that was transformed, instead
> of the set of characters?
You got it! :)
> In that case, how would I get my @data passed to unpack? (Please
> don't tell me there isn't a way without iterating line-by-line).
(Fortunately, you don't have to iterate line-by-line.) As you
probably already know, all you have to do is pass a join()ed string to
unpack(), like this:
my $hex = unpack("H*", join('', @data));
> Any ideas/comments/help is appreciated.
Just one more thing:
Using "H*" (and "B*") with the unpack() command confused me quite a
bit until I realized that the code 'unpack("H*",$string)' takes ONE
scalar string and returns ONE scalar string. Before realizing that I
tried passing a string expecting to return a list. In your case, you
were trying to pass in an array, expecting an array.
We both had our misconceptions, so just remember that unpacking with
"H*" (and "B*") takes one scalar and returns one scalar, and you should
do just fine.
I hope this helps, Henry.
-- Jean-Luc
------------------------------
Date: 17 Feb 2005 15:35:48 -0800
From: rajasekaran.natarajan@gmail.com
Subject: Re: Record Hash Data Structure (Newbie)
Message-Id: <1108683348.183640.233220@f14g2000cwb.googlegroups.com>
wow it is marvellous thanks Xho
I like the second approach it is great like point_x{name_of_point} = x;
this is will be damn efficinet if I compare the present one I am
employing.
I have gone too far already with the old stuff so I will rewrtie the
program
from the scratch using this. (it is ok I have plenty of idle time ;-)
I never seriously thoguth abt various ways of storing data. till now I
have used scrips (rather I call them as macros) just for simple task
which will not exceed 10 lines of the code. this is the first time I am
implelemnting something little more and deals with huge data. In our
application (Mech/aerospcae analysis) we process millions of records.
so I think this knowledge is unavoidable if I am going to do something
on them.
PS: I have implemented the old one without anyproblem and it is working
nicely still as the data increases it is taking quite some time. But I
have experienced another strange problem that I am posting it in a new
thread.
Thanks for all who helped me.
xhoster@gmail.com wrote:
> rajasekaran.natarajan@gmail.com wrote:
>
> <previously I wrote>:
> > >parallel hash
>
> > parrellel hash you mean using references, I am not yet caught upto
> > references
> > (esp to arrays and hashes) may be I will try that after this
iteration
> > with hashes. Actually I am doing this problem to learn Perl.
>
> Kind of the opposite, by parallel hashes I mean *not* using
references,
> or at least at one fewer level of them.
>
> Assuming you are have a million of 3-D points, you could store them
> something like:
>
> $point{$name_of_point}{X}=34.589;
> $point{$name_of_point}{Y}=4.998;
> $point{$name_of_point}{Z}=9.876;
>
> Here, you have %point is a hash with one million entries, and each
> entry is a (reference to an) anonymous hash (with three entries
each).
> So you have 1,000,001 hashes.
>
> Or, you could do:
>
> $point_x{$name_of_point}=34.589;
> $point_y{$name_of_point}=4.998;
> $point_z{$name_of_point}=9.876;
>
> Here, you have only 3 hashes (and none of them references). A lot
less
> overhead. But, the other way is usually better if you are not
worried
> about the memory overhead. For example, if you need to pass the
whole
> structure into a sub, you need to pass 3 references for this case
rather
> than 1 for the previous case. And if you need to change to 4D points
> rather than 3D, there would be much more code to change in this case.
>
> Other than memory, the one nice thing about the second way is that
"strict"
> will catch it if you commit a typo like $point_w{$name_of_point},
while it
> won't catch it if you typo like $point{$name_of_point}{W}.
>
> Xho
>
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 17 Feb 2005 15:51:04 -0800
From: rajasekaran.natarajan@gmail.com
Subject: Strange Problem
Message-Id: <1108684264.090704.34350@o13g2000cwo.googlegroups.com>
the code is a part of a large program, in which everythign works fine
except the IF BLOCK why? whats wrong with that. I tried everything I
can, yesterday. But no use. I do not know debugging But I have inserted
print commands to check what is going on. only IF block is not working.
WHY?
1. It is executing with a message saying
MESSG:use of Uninitiallized value (refering to $cn[$s1]) at line no#
but it can not be becuase the intial shortest is very high and the all
calculated $dist is less than 30. It *HAS* to execute the IF block and
assign the $cn[$s1] some value.
2. All calculated $dist are less than 30. but when I see the output it
is printing
1,,10000
2,,10000
3,,10000
it says it is not assigning $dist to $shortest by IF loop WHY? WHY?
WHY?
my $shortest=100000;
#assiging initial values#
foreach my $s1 (@set1){
#from array set1, the sample point is s1#
foreach my $s2 (@set2) {
#from array set2 the sample point is s2#
($x1,$y1,$z1) = ($g{$s1}->{x},$g{$s1}->{y},$g{$s1}->{z});
#this picks the coordinates for point s1 from hash#
($x2,$y2,$z2) = ($g{$s2}->{x},$g{$s2}->{y},$g{$s2}->{z});
#this picks the coordinates for point s2 froma hash #
my $dist= sqrt(($x1-$x2)**2+($y1-$y2)**2+($z1-$z2)**2);
#thiscalculate dist bet s1 and s2 #
if($dist le $shortest){
# if the dist is .LE. the shortest then do this #
$shortest = $dist;
#assign the calculated dist as the new shortest#
$cn[$s1] = $s2;
# store this particular point s2 in cn#
}
}
print OUT "$s1,$cn[s1],$shortest\n";
# print s1 and closest point s2 then the distance #
$shortest = 100000; #initialize for next iteration #
}
------------------------------
Date: Fri, 18 Feb 2005 00:47:46 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Strange Problem
Message-Id: <cv3dvi$54r$1@naig.caltech.edu>
In article <1108684264.090704.34350@o13g2000cwo.googlegroups.com>,
<rajasekaran.natarajan@gmail.com> wrote:
>my $shortest=100000;
> if($dist le $shortest){
The "le" operator operates as if its arguments are strings --
and when compared as strings, "100000" is less than practically
any value you're likely to compute (the only ones that will compare
less are "10000", "1000", etc.)
What you probably want is
if($dist <= $shortest){
-- Gary
------------------------------
Date: 18 Feb 2005 01:07:07 GMT
From: xhoster@gmail.com
Subject: Re: Strange Problem
Message-Id: <20050217200707.219$6P@newsreader.com>
rajasekaran.natarajan@gmail.com wrote:
> my $dist= sqrt(($x1-$x2)**2+($y1-$y2)**2+($z1-$z2)**2);
> #thiscalculate dist bet s1 and s2 #
> if($dist le $shortest){
You appear to be using string comparison on numeric values.
if ($dist <= $shortest) {
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 17 Feb 2005 19:34:30 -0800
From: rajasekaran.natarajan@gmail.com
Subject: Re: Strange Problem
Message-Id: <1108697670.040498.121870@l41g2000cwc.googlegroups.com>
Thanks Ansok and Xho for your replies,
you dont beleive it I spend full afternoon wondering what is going on!
today morning I can posted it here and went back to have a look at it.
Then I found out accidently what was the problem!
The book I have said this clearly like ..
le is the string equivalent for <=
(is it string equivalent or equivalent operator for strings ;-)
I think I need to improve my english.
thanks again
------------------------------
Date: Thu, 17 Feb 2005 18:06:39 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: use strict; and O_WRONLY
Message-Id: <aY-dnY1a9bcdvojfRVn-vA@adelphia.com>
Anno Siegel wrote:
> Sherm Pendley <spamtrap@dot-app.org> wrote in comp.lang.perl.misc:
>>
>> Nope. Have a look in Fcntl.pm - it's an autoloaded function.
>
> All constants are functions.
But not all functions are constants. :-) O_WRONLY is just a sub, not a
constant. It could be made into a constant, of course, but Fcntl is really
old, and it looks like no one has bothered.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Fri, 18 Feb 2005 00:00:17 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: use strict; and O_WRONLY
Message-Id: <37kmjkF5fh3jiU1@individual.net>
Sherm Pendley wrote:
> Gunnar Hjalmarsson wrote:
>> Brian McCauley wrote:
>>> Your problem is that you are trying to use the O_WRONLY function without
>>> first defining it.
>>
>> What gets imported from Fcntl is a constant, not a function. :)
>
> Nope. Have a look in Fcntl.pm - it's an autoloaded function.
Hmm.. I did look in the Fcntl POD, which talks about constants. Is that
POD possibly outdated?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 17 Feb 2005 20:33:27 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: use strict; and O_WRONLY
Message-Id: <oZydnd5tyMt12IjfRVn-sQ@adelphia.com>
Gunnar Hjalmarsson wrote:
> Hmm.. I did look in the Fcntl POD, which talks about constants. Is that
> POD possibly outdated?
I think I might have been wrong. The AUTOLOAD in Fcntl.pm calls a C
constant() function that's defined in XS code. I'm not too certain what
const-c.inc and const-xs.inc do - they're convoluted, to say the least.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Fri, 18 Feb 2005 02:47:24 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: use strict; and O_WRONLY
Message-Id: <37l0ehF5b00boU1@individual.net>
Sherm Pendley wrote:
> Gunnar Hjalmarsson wrote:
>> Hmm.. I did look in the Fcntl POD, which talks about constants. Is that
>> POD possibly outdated?
>
> I think I might have been wrong.
This code:
use warnings;
use Fcntl;
sub O_WRONLY { 2 }
results in the warning "Subroutine O_WRONLY redefined", which indicates
that you were right.
Maybe the term "constant" in the POD refers to anything else but things
defined via the constant pragma... Oh well, this became far too
technical for me. ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 18 Feb 2005 00:02:07 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: what is Perl state of the art?
Message-Id: <Xns9600B776C399Fcastleamber@130.133.1.4>
Chris Mattern wrote:
> John Bokma wrote:
>
>>
>> You probably have been looking at the "unleashed platinum gold deluxe
>> complete in 24 hours for dummies" doorstops eh books. Next time look for
>> O'Reilly first.
>>
> "Programming Perl" makes for a pretty good doorstop as well.
Oh, but that's a reference manual, those should have a lot of pages :-D
> Thing is,
> it's useful for learning Perl, too.
Not for a beginner, especially if the beginner has little or no past
programming experience.
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
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 7796
***************************************