[19846] in Perl-Users-Digest
Perl-Users Digest, Issue: 2041 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 31 09:05:45 2001
Date: Wed, 31 Oct 2001 06:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1004537109-v10-i2041@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 31 Oct 2001 Volume: 10 Number: 2041
Today's topics:
ANNOUNCE: moomps-0.9 <jfontain@winealley.com>
Contents of a hash blank in only *part* of a module <jason@uklinux.net>
Re: current dir location? <Graham.T.Wood@oracle.com>
Re: DBI MySQL problems <goldbb2@earthlink.net>
Linking Perl to a databse (Chris Collins)
Re: Linking Perl to a databse <simon.oliver@umist.ac.uk>
Re: Linking Perl to a databse <bart.lateur@skynet.be>
Newbie Question <no_spam.ple@se.com>
Re: Newbie Question <Laocoon@eudoramail.com>
Re: Newbie Question <josef.moellers@fujitsu-siemens.com>
Re: Perl/CGI Search Script <nobody@nowhere.com>
Re: perlish way to read/write absolute sectors from PC <epa98@doc.ic.ac.uk>
print interpreted as a function <tintin@snowy.calculus>
Re: print interpreted as a function (Anno Siegel)
Re: print interpreted as a function (Garry Williams)
Re: print interpreted as a function <nobody@nowhere.com>
Re: print interpreted as a function <dtweed@acm.org>
Re: Searching - CGI (Philip S Tellis)
Re: when does 0.58 != 0.58? <simon.oliver@umist.ac.uk>
Re: when does 0.58 != 0.58? <simon.oliver@umist.ac.uk>
Re: when does 0.58 != 0.58? <nobody@nowhere.com>
Re: XML parsing (Matt Sergeant)
Re: XML parsing (Clinton A. Pierce)
Re: Yet another regexp question <BROWNHIK@Syntegra.Bt.Co.Uk>
Re: Yet another regexp question <bart.lateur@skynet.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 31 Oct 2001 13:38:17 +0100
From: Jean-Luc Fontaine <jfontain@winealley.com>
Subject: ANNOUNCE: moomps-0.9
Message-Id: <3BDFF0B9.90003@winealley.com>
Moomps is a monitoring daemon which works using configuration
(dashboard) files created by the moodss (Modular Object Oriented Dynamic
SpreadSheet) graphical application. The configuration files contain the
definition of thresholds, which when crossed, trigger the sending of
email alert messages.
This is the initial release (beta quality). Moomps is actually part of
moodss, now at release 15.0.
When running, moomps periodically checks the threshold conditions and
eventually send email alerts to the adresses defined for those
thresholds in the configuration files, which can load any number of
modules (existing, such as system, database, network types, or custom
written by you in either Tcl, Perl, Python or C). Those modules are
actually also used by the moodss graphical monitoring application.
More documentation on moomps, moodss and existing modules can be found at:
http://jfontain.free.fr/moomps.htm
http://jfontain.free.fr/moodss.htm
You may find it now at my homepage:
http://jfontain.free.fr/moodss-15.0.tar.bz2 (contains moomps)
http://jfontain.free.fr/moomps-0.9-1.i386.rpm
Enjoy and please let me know what you think.
Jean-Luc
------------------------------
Date: Wed, 31 Oct 2001 11:42:30 +0000
From: Jason Clifford <jason@uklinux.net>
Subject: Contents of a hash blank in only *part* of a module
Message-Id: <Pine.LNX.4.30.0110311134340.1936-100000@s1.uklinux.net>
I am having a very vexing problem.
I have a module to which I am passing some data in the form of a scalar
and a reference to a hash and from which I am expecting a scalar return
containing a string some of which will originate from the passed hash.
My problem is that the returned string contains all of the information it
should *except* for the data that was in the hash.
At first I thought perhaps the hash data was not being properly received
however I checked that by dumping it out to a file from inside the module
just before it gets used properly and the data is all there.
Below is the relevant section of code:
Firstly I am dumping a section of the data to a file and this does work.
The file contains the correct name=string data.
open (DUMP, "> user_dat.file") || die "unable to open user_dat.file";
my $jasonvar = "name=".$user_dat->{'name'};
print DUMP $jasonvar;
close DUMP;
Immediately following on from this however when I try to use the hash
below all I get is blank. Other variables used such as $countb are fine.
$basket_data = <<EOBD;
Content-type: text/html\n\n\n
##START##
cname=GBP
max=$countb
name=$user_dat->{'name'}
adr1=$user_dat->{'adr1'}
adr2=$user_dat->{'adr2'}
adr3=$user_dat->{'adr3'}
adr4=$user_dat->{'adr4'}
pcde=$user_dat->{'pcde'}
mail=$user_dat->{'mail'}
dnme=$user_dat->{'dnme'}
EOBD
Can anyone shed any light on this for me?
Jason
------------------------------
Date: Wed, 31 Oct 2001 11:20:05 +0000
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: current dir location?
Message-Id: <3BDFDE64.1DADBDF4@oracle.com>
This is a multi-part message in MIME format.
--------------7ED1B1CEDBF04ACE34E679E7
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
MAGiC MANiAC^mTo wrote:
> current location...
>
> How can I find the current dir location?...
use Cwd; # this is a module that ships with perl
$current_dir=cwd; # cwd is the function in the module that returns the
current directory
Graham Wood
--------------7ED1B1CEDBF04ACE34E679E7
Content-Type: text/x-vcard; charset=UTF-8;
name="Graham.T.Wood.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Graham Wood
Content-Disposition: attachment;
filename="Graham.T.Wood.vcf"
begin:vcard
n:;Graham
x-mozilla-html:FALSE
adr:;;;;;;
version:2.1
email;internet:Graham.T.Wood@oracle.com
fn:Graham Wood
end:vcard
--------------7ED1B1CEDBF04ACE34E679E7--
------------------------------
Date: Wed, 31 Oct 2001 08:22:43 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: DBI MySQL problems
Message-Id: <3BDFFB23.57B2D820@earthlink.net>
martinblack wrote:
>
> Hi, I've been having trouble with this script from day one. I'm not
> sure what the problem is, but I'm trying to query the database with
> the form parameters ie: $product_id = $q->param('product_id');. If the
> item in question is already in the database, the script should UPDATE.
> If not, the script should INSERT. Instead, I get a 500 error. If I
> turn the warn flag on, I get:
> "Filehandle main::header never opened at add.cgi line 29". and
> "Use of uninitialized value at add.cgi line 107". I have totaly
> revamped this script about four times, nothing seems to work. Any help
> on this would be greatly apprecieated. Thanks in advance.
> Cheers. Martinblack.
>
> Below is a copy of the script:
>
> #!/usr/bin/perl
#!/usr/bin/perl -wT
use strict;
# always, ALWAYS use -w and strict, unless you really really know what
# you are doing. Also, use -T when doing CGI stuff.
use diagnostics;
# causes perl's warnings and error messages to be more verbose,
# and more useful.
> BEGIN {
> open (STDERR, ">html/error.txt");
> }
>
> ### add.cgi
>
> use DBI;
> use CGI::Carp qw(fatalsToBrowser carpout);
Looks like cargo-cult programming.
If you import carpout, use it. If you don't use it, don't import it.
Also, that BEGIN { open(STDERR....) } stuff above is ugly.
use CGI::Carp qw(fatalsToBrowser carpout);
BEGIN {
local *MY_STDERR;
open(MY_STDERR, ">html/error.txt");
carpout(*MY_STDERR);
}
use DBI ();
> use CGI;
> $q=new CGI;
By creating a new CGI object, you are preventing CGI from loading the
non-object-oriented stuff. I would suggest you just import those
functions which you need, and not bother with the object-oriented
interface.
use CGI qw(param header);
>
> # input..................................
>
> $io{'company_id'} = $company_id = $q->param('company_id');
> $io{'product_id'} = $product_id = $q->param('product_id');
> $io{'title'} = $title = $q->param('title');
> $io{'description'} = $description = $q->param('description');
> $io{'spex'} = $spex = $q->param('spex');
> $io{'price'} = $price = $q->param('price');
> $io{'sex'} = $sex = $q->param('sex');
None of these are declared anywhere -- they're global variables. Blech.
Also, why do you bother to put these things in seperate variables,
instead of using *just* the %io hash?
I would turn the above into:
my %io = map { $_ => param($_) } qw(
company_id product_id title
description spex price sex);
> # mainline...............................
>
> print header;
Since you did $q=new CGI; you prevent header from being recognized as a
CGI.pm subroutine... which makes perl think of it as a filehandle, not a
function name. If you import it, the problem goes away. Or, if you
insist on using the OO interface for CGI.pm, replacing header with
$q->header will also make the problem go away.
> $DBname= "dbi:mysql:minmin";
> $DBhost = "localhost";
> $DBusername = "minmin";
> $DBpassword = "fFUZsFtD";
>
> $dbh = DBI->connect("$DBname:$DBhost", $DBusername, $DBpassword ||
> die "connection problem: ", $DBI::errstr;
This is a syntax error. Not to mention you ought to declare all of
these, probably as lexicals.
> $dbh->{'RaiseError'} = 1;
This can and probable should be done as part of the connect statement.
[snip]
> sub kaboom() {
>
> $sth = $dbh->prepare( q[
> SELECT company_id, product_id
> FROM product
> WHERE company_id = ? and
> product_id= ?
> ] ) || die "prep problem: ", $DBI::errstr;
> $sth->execute( $company_id, $product_id ) || die "execution problem:
> ", $DBI::errstr;
>
> &fetch_results;
>
>
> if ($newid) {
Inside fetch_results, you set $newid to "$com-$pro" regardless of
whether that company,product id exists in the database. If it exists,
it gets set to something useful, but if there isn't such a pair, then it
still gets set... to undef() . "-" . undef() ... which is equal to "-"
... which is a TRUE value, not a false one.
If I were you, I would move the above prepare statement, and the fetch
statements from fetch_results into a new subroutine, called
record_exists, which returns a true/false value depending on whether
that company,product id exists in the database.
Then, the above if() statement would become
if(record_exists()) {
>
> $dbh->do(do { local $" = ", "; qq[
> UPDATE product
> SET @{[map "$_ = ?", keys %io]}
> WHERE company_id = ? AND product_id = ?
> ] }, undef,
> values %io,
> @io{qw(company_id product_id)} );
>
> } else {
>
> $dbh->do(do { local $" = ", "; qq[
> INSERT INTO product (@{[ keys %io ]})
> VALUES (@{[ ('?') x values %io ]})
> ] }, undef, values %io );
>
> }
> }
>
> sub fetch_results {
>
> while ($x = $sth->fetchrow_hashref) {
> $com = $x->{'company_id'};
> $pro = $x->{'product_id'};
> }
> $newid = $com ."-".$pro;
> }
Besides the problems I mentioned before, the above has another serious
problem: all the variables are global! Blech.
sub record_exists {
my $sth = $dbh->prepare( qq[
SELECT COUNT(*) FROM product
WHERE company_id = ? and product_id = ?
] );
$sth->execute( @io{qw{company_id product_id}} );
return ($sth->fetchrow_array)[0];
}
--
Klein bottle for rent - inquire within.
------------------------------
Date: 31 Oct 2001 03:43:23 -0800
From: chris.collins@rbos.com (Chris Collins)
Subject: Linking Perl to a databse
Message-Id: <c1b9601c.0110310343.62908c13@posting.google.com>
I am trying to link a Perl script to a sybase database. I then want
to run a query and print the results into a seperate file. I am
confident that i can do this once i have the necesaary material.
Unfortunately i cannot find anywhere how to access a database. Is
there a standard form to follow?
i.e. DB name
login
password etc
Thanks
Chris
------------------------------
Date: Wed, 31 Oct 2001 11:51:30 +0000
From: Simon Oliver <simon.oliver@umist.ac.uk>
To: Chris Collins <chris.collins@rbos.com>
Subject: Re: Linking Perl to a databse
Message-Id: <3BDFE5C2.C126566D@umist.ac.uk>
See DBI and DBD::Sybase or DBD::ODBC
Chris Collins wrote:
>
> I am trying to link a Perl script to a sybase database. I then want
> to run a query and print the results into a seperate file. I am
> confident that i can do this once i have the necesaary material.
> Unfortunately i cannot find anywhere how to access a database. Is
> there a standard form to follow?
>
> i.e. DB name
> login
> password etc
>
> Thanks
>
> Chris
------------------------------
Date: Wed, 31 Oct 2001 13:28:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Linking Perl to a databse
Message-Id: <6ouvtt402f2radlq7d7uhh4psavjf1dl5h@4ax.com>
Chris Collins wrote:
>I am trying to link a Perl script to a sybase database. I then want
>to run a query and print the results into a seperate file. I am
>confident that i can do this once i have the necesaary material.
>Unfortunately i cannot find anywhere how to access a database. Is
>there a standard form to follow?
Duh. What planet are you from? ;-)
The standard is called "DBI". The database drivers used by DBI are under
"DBD::*"; you'll want DBD::Sybase. The homepage for DBI is
<http://dbi.symbolstone.org/> although it looks like the server is not
accessible right now. You can get started by looking for "DBI" and
"DBI-FAQ" on CPAN. There's a good book available from O'Reilly,
"Programming the Perl DBI " (by the same people that brought you DBI and
that FAQ) to get you up to speed really fast, although it doesn't really
contain much that isn't in the (free) online docs. And there's a mailing
list, "dbi-users" (at perl.org); you can search the archives and
subscribe on <http://lists.perl.org/showlist.cgi?name=dbi-users>
--
Bart.
------------------------------
Date: Wed, 31 Oct 2001 13:08:06 -0000
From: "Peter Morris" <no_spam.ple@se.com>
Subject: Newbie Question
Message-Id: <9rot3l$pne$1@lyonesse.netcom.net.uk>
Hello, I'm just learning PERL. I don't really understand
what these $_ and @_ variables are all about. Can someone
explain, please.
--
______________________________
/____________________________(_)
| ___________________________ email to
| | |________________________(_) Peter_Morris_1
| |/__________________________ at Hotmail dot com
|____________________________(_)
------------------------------
Date: Wed, 31 Oct 2001 14:37:48 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Newbie Question
Message-Id: <Xns914B94D272CB8Laocooneudoramailcom@62.153.159.134>
perldoc perlvar
------------------------------
Date: Wed, 31 Oct 2001 14:47:53 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Newbie Question
Message-Id: <3BE00109.5C840221@fujitsu-siemens.com>
Peter Morris wrote:
> =
> Hello, I'm just learning PERL. I don't really understand
> what these $_ and @_ variables are all about. Can someone
> explain, please.
It's really a very widely used thing, so this only touches the surface:
A number of operators and such (mainly loops) implicitly set the $_
variable:
foreach (@ARGV) {
print "$_\n";
}
Beware that modifying $_ in a loop will modify the corresponding array
element, too. Note that each loop will create a new instance of $_:
foreach (@ARGV) {
# $_ regers to an element of @ARGV
foreach (keys %ENV) {
# $_ refers to an element of the list of keys of %ENV
}
# $_ regers to an element of @ARGV
}
=
Also, a number of operators implicitly use $_, e.g. the pattern matching
operators:
foreach (@ARGV) {
print if (/^a/);
}
At last, the @_ array contains a function/procedure's arguments.
As I said, there are probably more uses of $_ and @_ than language
dialects of BASIC.
HTH,
Josef, not really a Perl hacker
-- =
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
------------------------------
Date: Wed, 31 Oct 2001 22:03:30 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: Perl/CGI Search Script
Message-Id: <QJRD7.404$lh4.4678@newsfeeds.bigpond.com>
"Matt" <pneumatus@NOSPAMhotmail.com> wrote in message
news:9rnblg$458$1@plutonium.btinternet.com...
> Hi,
>
> I'm looking for a free search script written in perl/cgi. The thing is, I
> want one that can handle ? and &'s in urls as the site i need it for is
> totally CGI driven.
>
> I hope someone can point me in the right direction.
>
> Pneumatus®
>
This is the one I use. Crawling can be run from the web or from a *nix
script.
http://www.xav.com/scripts/search/
gtoomey
------------------------------
Date: 30 Oct 2001 13:28:12 +0000
From: Edward Avis <epa98@doc.ic.ac.uk>
Subject: Re: perlish way to read/write absolute sectors from PC disk?
Message-Id: <xn9itcxb6kz.fsf@voxel32.doc.ic.ac.uk>
Raw disk access is easy on Unix (if you're root); on Windows I believe
that DJGPP and maybe Cygwin provide device nodes for raw disk access,
so you could use a DJGPP-compiled Perl to do it. But DJGPP's raw
access won't work on NT and its successors.
If you just want multi-boot, on NT the easiest way to do it is
probably the boot.ini file which controls the startup menu. You can
boot DOS, WinDOS, Linux (and of course NT) from that file, and change
the default choice at boot time. If you run a telnet or ssh service
on the Windows boxes, you can connect to them and run edlin
non-interactively (woo hoo!) to change the boot.ini file. Have a look
at <http://www.doc.ic.ac.uk/~epa98/bin/nt_boot_linux>.
--
Ed Avis <epa98@doc.ic.ac.uk>
Finger for PGP key
------------------------------
Date: Wed, 31 Oct 2001 22:08:52 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: print interpreted as a function
Message-Id: <s_QD7.18$tu7.300056@news.interact.net.au>
I know I can do
$mtime = (stat("/etc/passwd"))[9];
print $mtime;
But if I try to combine the print with:
use diagnostics;
print (stat("/etc/passwd"))[9];
I get the error:
print (...) interpreted as function at /tmp/a line 3 (#1)
(W syntax) You've run afoul of the rule that says that any list operator
followed by parentheses turns into a function, with all the list
operators arguments found inside the parentheses. See
perlop/Terms and List Operators (Leftward).
I read the relevant section in perlop, but I'm still none the wiser. Can
some kind soul try to explain it to me in simple terms.
------------------------------
Date: 31 Oct 2001 12:03:21 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: print interpreted as a function
Message-Id: <9ropa9$i7j$1@mamenchi.zrz.TU-Berlin.DE>
According to Tintin <tintin@snowy.calculus>:
> I know I can do
>
> $mtime = (stat("/etc/passwd"))[9];
> print $mtime;
>
> But if I try to combine the print with:
>
> use diagnostics;
> print (stat("/etc/passwd"))[9];
>
> I get the error:
>
> print (...) interpreted as function at /tmp/a line 3 (#1)
> (W syntax) You've run afoul of the rule that says that any list operator
> followed by parentheses turns into a function, with all the list
> operators arguments found inside the parentheses. See
> perlop/Terms and List Operators (Leftward).
>
> I read the relevant section in perlop, but I'm still none the wiser. Can
> some kind soul try to explain it to me in simple terms.
Hmm... I don't know if I can make it simpler, but I can make it longer:
When a list operator ("print" in your code) is followed by an opening
parenthesis (as it is in your code), there is an ambiguity: The
parenthesis could introduce one expression in the list of expressions
that may follow a list operator (this is your intended interpretation).
Perl takes another path and reads the parenthesis as opening the
list of arguments to print; that is meant by "turns into a function".
Accordingly, the corresponding closing parenthesis ends the argument
list, and the parser ends up with a solitary [] which is it supposed
to apply to the result of print: "print( ...)[9]". That makes no sense,
and that's what it is trying to tell you.
The remedy is to disambiguate. You can add another pair of parentheses
(as a compensation you can avoid an inner pair):
print( (stat "/etc/passwd")[9]);
Or you can use the slightly obscure "+"-prefix which exists expressly
for this purpose. It does nothing semantically, but separates "print"
from "(" syntactically:
print +(stat "/etc/passwd")[9];
Anno
------------------------------
Date: Wed, 31 Oct 2001 12:03:32 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: print interpreted as a function
Message-Id: <slrn9tvq4k.1r5.garry@zfw.zvolve.net>
On Wed, 31 Oct 2001 22:08:52 +1100, Tintin <tintin@snowy.calculus> wrote:
> I know I can do
>
> $mtime = (stat("/etc/passwd"))[9];
> print $mtime;
>
> But if I try to combine the print with:
>
> use diagnostics;
> print (stat("/etc/passwd"))[9];
>
> I get the error:
>
> print (...) interpreted as function at /tmp/a line 3 (#1)
> (W syntax) You've run afoul of the rule that says that any list operator
> followed by parentheses turns into a function, with all the list
> operators arguments found inside the parentheses. See
> perlop/Terms and List Operators (Leftward).
>
> I read the relevant section in perlop, but I'm still none the wiser. Can
> some kind soul try to explain it to me in simple terms.
The print operator takes a list. If the parser "sees" `(' after the
keyword print, it assumes the list is inside the parentheses. The
manual suggests that adding `+' in front of the parens will cause it
to be parsed as a single term instead.
print +(stat("/etc/passwd"))[9];
--
Garry Williams
------------------------------
Date: Wed, 31 Oct 2001 22:13:37 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: print interpreted as a function
Message-Id: <kTRD7.423$lh4.4565@newsfeeds.bigpond.com>
"Tintin" <tintin@snowy.calculus> wrote in message
news:s_QD7.18$tu7.300056@news.interact.net.au...
> I know I can do
>
> $mtime = (stat("/etc/passwd"))[9];
> print $mtime;
>
> But if I try to combine the print with:
>
> use diagnostics;
> print (stat("/etc/passwd"))[9];
>
> I get the error:
>
> print (...) interpreted as function at /tmp/a line 3 (#1)
> (W syntax) You've run afoul of the rule that says that any list
operator
> followed by parentheses turns into a function, with all the list
> operators arguments found inside the parentheses. See
> perlop/Terms and List Operators (Leftward).
>
> I read the relevant section in perlop, but I'm still none the wiser. Can
> some kind soul try to explain it to me in simple terms.
Add an extra set of parentheses:
print ((stat("/etc/passwd"))[9]);
gtoomey
------------------------------
Date: Wed, 31 Oct 2001 12:50:14 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: print interpreted as a function
Message-Id: <3BDFF356.1E9DA9A4@acm.org>
I just got the same warning yesterday on the following code, which I
also don't understand:
#!perl -w
use strict;
print ("all on one line\n", "another line\n") if 1;
print ("first of two lines\n",
"second of two lines\n") if 1;
~/temp/perl>perl printfunc.pl
print (...) interpreted as function at printfunc.pl line 5.
all on one line
another line
first of two lines
second of two lines
Note that only the second print, with the argument list on two source
lines, invokes the warning. Why does this matter at all?
-- Dave Tweed
------------------------------
Date: 31 Oct 2001 03:19:18 -0800
From: philip@ncst.ernet.in (Philip S Tellis)
Subject: Re: Searching - CGI
Message-Id: <d1eff1dd.0110310319.12439de5@posting.google.com>
> #!/usr/bin/perl
Where is the -w switch? Where is use strict? Just add these two
things to your code, and you'll find out what else is wrong. Please
read the man pages and faq first.
I'm going to skip over most errors, and just point out a few.
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
what??
> @lines =`cat 10_1_64_0` ;
Yuck! How do you know if the `` succeeded or failed? Why does perl
provide an open function that returns meaningful values if you're not
going to use it?
> $lines =~ /([A-Za-z0-9]*)\s(\w*)\s([\d\d.]*)/;
Should also match the following lines:
@ @
<sp><sp> (two spaces)
basically, anything with at least two spaces, since that's all
that's required by your re
I cannot go any further, so fix these bugs first, read all relevant
documentation, and then post a better question.
Also, please don't post your entire input file.
Philip
------------------------------
Date: Wed, 31 Oct 2001 11:15:19 +0000
From: Simon Oliver <simon.oliver@umist.ac.uk>
To: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: when does 0.58 != 0.58?
Message-Id: <3BDFDD47.D643514E@umist.ac.uk>
When 0.58 = 0.580000000000000070
Try
printf "%.18f", $a;
and you'll se what I mean.
Like most programming languages Perl stores floating point numbers as
approximations. On the first iteration of your loop the approximation
is near enough but ar the loop progresses the errors are compounded .
--
Simon Oliver
Paul Boardman wrote:
>
> Hi all,
>
> I've been having a problem with a script & I've narrowed it down to a
> floating point comparison. Basically I want to do something with a load
> of data if a variable is equal to 0.58. All sounds easy right? good.
>
> Problem is that a comparison of my variable with 0.58 is false, even
> when the variable is 0.58.
>
> Here's a little code to clarify :-
>
> CODE1
>
> perl -MDevel::Peek -le 'for(my $a = 0.56; $a < 0.60; $a += 0.02){print
> "\nComparing ";Dump $a;print "with 0.56\n";if($a == 0.56){print "They
> are the same!"}else{print "They are different!"}}'
>
> <OUTPUT1>
> Comparing
> SV = NV(0x8124f30) at 0x80fa2a8
> REFCNT = 1
> FLAGS = (PADBUSY,PADMY,NOK,pNOK)
> NV = 0.56
> with 0.56
>
> They are the same!
>
> Comparing
> SV = NV(0x8124f30) at 0x80fa2a8
> REFCNT = 1
> FLAGS = (PADBUSY,PADMY,NOK,pNOK)
> NV = 0.58
> with 0.56
>
> They are different!
> </OUTPUT1>
>
> All is fine here.
>
> CODE2
>
> perl -MDevel::Peek -le 'for(my $a = 0.56; $a < 0.60; $a += 0.02){print
> "\nComparing ";Dump $a;print "with 0.58\n";if($a == 0.58){print "They
> are the same!"}else{print "They are different!"}}
>
> <OUTPUT2>
> Comparing
> SV = NV(0x8124f50) at 0x80fa2a8
> REFCNT = 1
> FLAGS = (PADBUSY,PADMY,NOK,pNOK)
> NV = 0.56
> with 0.58
>
> They are different!
>
> Comparing
> SV = NV(0x8124f50) at 0x80fa2a8
> REFCNT = 1
> FLAGS = (PADBUSY,PADMY,NOK,pNOK)
> NV = 0.58
> with 0.58
>
> They are different!
> </OUTPUT2>
>
> Er... so what's going on here?
>
> Paul
------------------------------
Date: Wed, 31 Oct 2001 11:17:59 +0000
From: Simon Oliver <simon.oliver@umist.ac.uk>
To: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: when does 0.58 != 0.58?
Message-Id: <3BDFDDE7.C0DE9728@umist.ac.uk>
Try this to see what I mean:
for (my $a = 0.56; $a < 0.60; $a = $a + 0.02) {
my $b = 0.58;
printf "%.18f == %.18f\n", $a, $b;
if ($a == $b) {
print "They are the same!\n\n"
} else {
print "They are different!\n\n"
}
}
------------------------------
Date: Wed, 31 Oct 2001 22:00:06 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: when does 0.58 != 0.58?
Message-Id: <EGRD7.400$lh4.4669@newsfeeds.bigpond.com>
"Paul Boardman" <peb@bms.umist.ac.uk> wrote in message
news:3BDFD418.371FED9F@bms.umist.ac.uk...
> Hi all,
>
> I've been having a problem with a script & I've narrowed it down to a
> floating point comparison. Basically I want to do something with a load
> of data if a variable is equal to 0.58. All sounds easy right? good.
This is a bit of a kludge but it works:
use POSIX;
sub round {
return floor($_[0]+0.5);
}
if (round($x*100) == round($y*100)) ...
gtoomey
------------------------------
Date: 31 Oct 2001 03:38:50 -0800
From: msergeant@star.net.uk (Matt Sergeant)
Subject: Re: XML parsing
Message-Id: <eb3031b9.0110310338.6677d05e@posting.google.com>
clintp@geeksalad.org (Clinton A. Pierce) wrote in message news:<aOKD7.213273$K6.104503349@news2>...
>
> [2] The AxKit developers owe me two weeks of my life. After jumping through
> all of the hoops to get it installed, I find out that a major component they
> sold me on was based on something that hadn't quite been released from another
> package entirely (gnome?). Bastards. Ah, well, I'd probably have wasted those
> two weeks anyway. PS: They're STILL not ready for primetime.
And being an asshole helps this how? Maybe if I'd have had 1 single
email requesting help from you, I could have done something about it.
But instead you post your bitchfest here, slagging off the hard work
I've done FOR FREE.
------------------------------
Date: Wed, 31 Oct 2001 13:08:20 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: XML parsing
Message-Id: <8JSD7.213443$K6.104895490@news2>
In article <eb3031b9.0110310338.6677d05e@posting.google.com>,
msergeant@star.net.uk (Matt Sergeant) writes:
> clintp@geeksalad.org (Clinton A. Pierce) wrote in message news:<aOKD7.213273$K6.104503349@news2>...
>>
>> [2] The AxKit developers owe me two weeks of my life. After jumping through
>> all of the hoops to get it installed, I find out that a major component they
>> sold me on was based on something that hadn't quite been released from another
>> package entirely (gnome?). Bastards. Ah, well, I'd probably have wasted those
>> two weeks anyway. PS: They're STILL not ready for primetime.
>
> And being an asshole helps this how? Maybe if I'd have had 1 single
> email requesting help from you, I could have done something about it.
> But instead you post your bitchfest here, slagging off the hard work
> I've done FOR FREE.
I asked questions of the AxKit mailing list, in #AxKit on whichever
IRC channel is listed in the docs, and a few other places. The installation
instructions didn't refer to the version of AxKit that was in the bundle
("we've made significant changes, but haven't had time to update the docs")
and the prerequisites weren't listed anywhere except in the linker's error
messages.
I can dig up the IRC logs and the mail responses I received if you like.
I still have them. My frustration was clearly evident then, this rant
hasn't changed in the intervening 4 months.
I admire your hard work, it's probably very good code. Good luck.
It's just wrong to tout a package as being ready to use for use when
it's clearly still under heavy development and not stable at all. I wanted
a package to do my job, not to tinker with someone else's development
toys.
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Wed, 31 Oct 2001 11:55:27 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: Yet another regexp question
Message-Id: <9rop25$9ro$1@pheidippides.axion.bt.co.uk>
This code does it in 2 matching operations.
I've never seen the point of trying to do everything in one line or the
fewest number of characters - as some perl experts seem to do. Readability
is more important in production code which may need to be quickly understood
by other programmers.
$str = "BAUGHMAN, KINNEY GRAGG, JACK A GRAGG, MARY LEA W";
$term = "GRAGG";
($partmatch) = ($str =~ /($term,[^,]+),/);
($fullmatch) = ($partmatch =~ /^(.*)\s+\w+$/);
print "$partmatch--\n";
print "$fullmatch--\n";
# the 2 --'s show that no extra spaces are included in the match.
Hope this helps
Kevin Brownhill
"Kinney Baughman" <baughmankr@appstate.edu> wrote in message
news:3BDF2433.94E94D81@appstate.edu...
> OK, I give!
>
> I've been working on this for a couple of hours now.
>
> I'm trying to work out a regular expression that will do the following:
>
> 1) I have strings of names in a database.
>
> For ex., "BAUGHMAN, KINNEY GRAGG, JACK A GRAGG, MARY LEA W".
>
> 2) Users will search on last names, "Gragg", for example.
>
> 3) The database will return the string above but ...
> 4) All I want to return is the first occurence of the search term plus the
> next word.
>
> So in my example above, if someone searches on "GRAGG", then I want to
> return "GRAGG, JACK".
>
> I've tried grouping and all sorts of techniques but I'm not even getting
> close.
>
> So how do I do this?
>
> Thanks.
> --
> +-----------------------------------------------------------------------+
> | Kinney Baughman Appalachian State University |
> | Appalachian Regional Development Institute Boone, NC 28608 |
> | Email: baughmankr@appstate.edu Phone: (828) 262-6523 |
> +-----------------------------------------------------------------------+
------------------------------
Date: Wed, 31 Oct 2001 14:01:19 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Yet another regexp question
Message-Id: <eo00utcs9ro2cln0lrd8sa9npuu8m70o2f@4ax.com>
Kevin Brownhill wrote:
>I've never seen the point of trying to do everything in one line or the
>fewest number of characters - as some perl experts seem to do. Readability
>is more important in production code which may need to be quickly understood
>by other programmers.
>
>$str = "BAUGHMAN, KINNEY GRAGG, JACK A GRAGG, MARY LEA W";
>$term = "GRAGG";
>($partmatch) = ($str =~ /($term,[^,]+),/);
>($fullmatch) = ($partmatch =~ /^(.*)\s+\w+$/);
You don't seem to mind not being able to match the last entry on the
line?
my ($partmatch) = ($str =~ /(\b$term,[^,]+,?)/);
(my $fullmatch = $partmatch) =~s/\s+\w+,$//;
Try it with
$str = "BAUGHMAN, KINNEY GRAGG, JACK A GREGG, MARY LEA W";
and
for my $term ('GRAGG', 'GREGG') { ... }
--
Bart.
------------------------------
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.
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 2041
***************************************