[26011] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8228 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 8 16:20:28 2005

Date: Tue, 5 Jul 2005 11:05:05 -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           Tue, 5 Jul 2005     Volume: 10 Number: 8228

Today's topics:
    Re: Checking IP addresses against lists of IPs, partial <a24061@yahoo.com>
    Re: Checking IP addresses against lists of IPs, partial (Anno Siegel)
    Re: Checking IP addresses against lists of IPs, partial <a24061@yahoo.com>
    Re: DBD::Sybase / DBD::ODBC + FreeTDS woes - placeholde <richard@zync.co.uk>
    Re: DBD::Sybase / DBD::ODBC + FreeTDS woes - placeholde <am@*t.com.au>
    Re: DBD::Sybase / DBD::ODBC + FreeTDS woes - placeholde <richard@zync.co.uk>
    Re: Help to get started with Module Games::QuizTaker <rprp@gmx.net>
    Re: Help to get started with Module Games::QuizTaker <mstep@t-online.de>
    Re: Help to get started with Module Games::QuizTaker <rprp@gmx.net>
    Re: Help With Pattern Matching axel@white-eagle.invalid.uk
    Re: OT: keeping track of time when programming <arcofdescent@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 05 Jul 2005 14:03:02 +0100
From: Adam Funk <a24061@yahoo.com>
Subject: Re: Checking IP addresses against lists of IPs, partial IPs, and netmasks.
Message-Id: <dae0e7$281d$1@godfrey.mcc.ac.uk>

Anno Siegel wrote:

>> I can read the input file and for each netmask string, create a
>> Net::Netmask and test with the Net::Netmask->match($ip) method, until it
>> returns true or I run out of input.
>> 
>> But I'm wondering if there is a more efficient way to do it.
> 
> Don't worry about efficiency at this point. Enjoy having found a
> method that *works* and move on.  When the program as a whole is too
> slow, and if it turns out that the IP search is the culprit, then it's
> time to think about a speed-up.

Fair enough!  I think what bothered me is that this superficially resembles
testing something for membership of an array by iterating through the array
-- which I know is a no-no (you're supposed to use a hash instead).



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

Date: 5 Jul 2005 13:15:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Checking IP addresses against lists of IPs, partial IPs, and netmasks.
Message-Id: <dae168$jel$2@mamenchi.zrz.TU-Berlin.DE>

Adam Funk  <a24061@yahoo.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> 
> >> I can read the input file and for each netmask string, create a
> >> Net::Netmask and test with the Net::Netmask->match($ip) method, until it
> >> returns true or I run out of input.
> >> 
> >> But I'm wondering if there is a more efficient way to do it.
> > 
> > Don't worry about efficiency at this point. Enjoy having found a
> > method that *works* and move on.  When the program as a whole is too
> > slow, and if it turns out that the IP search is the culprit, then it's
> > time to think about a speed-up.
> 
> Fair enough!  I think what bothered me is that this superficially resembles
> testing something for membership of an array by iterating through the array
> -- which I know is a no-no (you're supposed to use a hash instead).

To get that kind of performance in your situation you'd have to expand
all address blocks explicitly to a hash.  That could mean throwing
a *lot* of memory at the problem.  Also, it would only gain much if
you have many IPs to check against the same set of address blocks.
Otherwise, rebuilding the hash frequently would eat up the gain.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Tue, 05 Jul 2005 14:49:14 +0100
From: Adam Funk <a24061@yahoo.com>
Subject: Re: Checking IP addresses against lists of IPs, partial IPs, and netmasks.
Message-Id: <dae34q$28li$1@godfrey.mcc.ac.uk>

Anno Siegel wrote:

>> Fair enough!  I think what bothered me is that this superficially
>> resembles testing something for membership of an array by iterating
>> through the array -- which I know is a no-no (you're supposed to use a
>> hash instead).
> 
> To get that kind of performance in your situation you'd have to expand
> all address blocks explicitly to a hash.  That could mean throwing
> a *lot* of memory at the problem.  Also, it would only gain much if
> you have many IPs to check against the same set of address blocks.
> Otherwise, rebuilding the hash frequently would eat up the gain.

I agree.  Thanks.



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

Date: Tue, 05 Jul 2005 14:24:10 GMT
From: Richard Gration <richard@zync.co.uk>
Subject: Re: DBD::Sybase / DBD::ODBC + FreeTDS woes - placeholders and implicit  datatype conversions
Message-Id: <pan.2005.07.05.14.24.08.56504@zync.co.uk>

On Tue, 05 Jul 2005 22:28:05 +1000, Anthony Mandic wrote:

> Richard Gration wrote:
>> 
>> >       What's wrong with using Open Client? Does it work on Gentoo?
>> 
>> Sybase ASE 11.0.3 is available only as an rpm for Redhat. It is also quite
>> picky about its libraries and often one needs to install compat library
>> rpms to get it working.
> 
> 	That may well be, but its also all of ASE. What about just what's
> 	needed to get Open Client working? Have you tried copying it over
> 	to see?

I haven't, for a couple of reasons: One, I didn't think it stood a cat in
hell's chance of working and two, it falls into the "hack" category and
makes migration of code from the dev environment to the live environment
difficult and also upgrades etc.

> 
>> >       Posting the code where you get the error might help too.
>> 
>> The script below will try to make a query against the pubs2 database
>> which comes with Sybase and is used in SQL examples in the documentation.
>> The qty column of the salesdetail table is a smallint. No such problem
>> with placeholders happens when an anlogous query is executed against a
>> varchar column.
> ...
>> # Works
>> my $sd1 = $dbh->selectall_arrayref('select * from salesdetail where qty = 75',{Columns=>{}});
>> print "\n",Data::Dump::dump($sd1),"\n";
>> 
>> # Doesn't work
>> my $sd2 = $dbh->selectall_arrayref('select * from salesdetail where qty = ?',{Columns=>{}},75);
> ...
>> DBD::ODBC::db selectall_arrayref failed: [unixODBC][FreeTDS][SQL
>> Server]Implicit conversion from datatype 'VARCHAR' to 'SMALLINT' is not
>> allowed.  Use the CONVERT function to run this query. (SQL-42000)(DBD:
>> st_execute/SQLExecute err=-1) at ./syb.pl line 23.
> 
> 	OK. I'm not sure what it thinks is going on. As far as I know,
> 	ASE's parser should know to turn the string "75" into a numeric
> 	value. You could try a convert statement to see what it does.
> 	What about assigning the "75" to a variable in Perl and passing
> 	that in the string?

I have tried that, with identical results. I've also tried convert, and
that works, but I have a 25,000 line application with 100s of queries
already written, which work with ct-lib, so converting them all is out of
the question. I would rather re-install OSes than do that!

> 
> 	I'm sure Michael Peppler could offer some advice too.

I sure ... in fact I was hoping he would!

Rich


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

Date: Tue, 05 Jul 2005 22:28:05 +1000
From: Anthony Mandic <am@*t.com.au>
Subject: Re: DBD::Sybase / DBD::ODBC + FreeTDS woes - placeholders and implicit  datatype conversions
Message-Id: <dadunl$28k$1@lust.ihug.co.nz>

Richard Gration wrote:
> 
> >       What's wrong with using Open Client? Does it work on Gentoo?
> 
> Sybase ASE 11.0.3 is available only as an rpm for Redhat. It is also quite
> picky about its libraries and often one needs to install compat library
> rpms to get it working.

	That may well be, but its also all of ASE. What about just what's
	needed to get Open Client working? Have you tried copying it over
	to see?

> >       Posting the code where you get the error might help too.
> 
> The script below will try to make a query against the pubs2 database
> which comes with Sybase and is used in SQL examples in the documentation.
> The qty column of the salesdetail table is a smallint. No such problem
> with placeholders happens when an anlogous query is executed against a
> varchar column.
 ...
> # Works
> my $sd1 = $dbh->selectall_arrayref('select * from salesdetail where qty = 75',{Columns=>{}});
> print "\n",Data::Dump::dump($sd1),"\n";
> 
> # Doesn't work
> my $sd2 = $dbh->selectall_arrayref('select * from salesdetail where qty = ?',{Columns=>{}},75);
 ...
> DBD::ODBC::db selectall_arrayref failed: [unixODBC][FreeTDS][SQL
> Server]Implicit conversion from datatype 'VARCHAR' to 'SMALLINT' is not
> allowed.  Use the CONVERT function to run this query. (SQL-42000)(DBD:
> st_execute/SQLExecute err=-1) at ./syb.pl line 23.

	OK. I'm not sure what it thinks is going on. As far as I know,
	ASE's parser should know to turn the string "75" into a numeric
	value. You could try a convert statement to see what it does.
	What about assigning the "75" to a variable in Perl and passing
	that in the string?

	I'm sure Michael Peppler could offer some advice too.

-am	© 2005


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

Date: Tue, 05 Jul 2005 11:36:02 GMT
From: Richard Gration <richard@zync.co.uk>
Subject: Re: DBD::Sybase / DBD::ODBC + FreeTDS woes - placeholders and implicit datatype conversions
Message-Id: <pan.2005.07.05.11.35.57.388549@zync.co.uk>

On Tue, 05 Jul 2005 18:55:00 +1000, Anthony Mandic wrote:

> Richard Gration wrote:
>> 
>> I'm trying to issue SQL queries, which contain placeholders, from a
>> Gentoo Linux desktop to a Redhat Linux 7.1 server running Sybase ASE
>> 11.0.3, using freetds (and unixODBC) and DBI. It all works well with a
>> variety of CLI clients: sqsh, tsql (freetds) and isql (unixODBC). The
>> problem comes when using DBI and placeholders.
>> 
>> freetds does not support placeholders at all, in any TDS version it
>> implements, so that kiboshes DBD::Sybase. They suggest using their ODBC
>> lib and DBD::ODBC. Everything is OK until trying to use a placeholder for
>> a numeric argument. Then the dreaded
>> 
>> ========
>> Implicit conversion from datatype 'VARCHAR' to 'NUMERIC' is not allowed.
>> Use the CONVERT function to run this query.
>> ========
>> 
>> error message appears. I've tried all sorts of things to get round this
>> but nothing works for me. I know that there is a little(!) magic inside
>> perl for allowing scalar values to be both strings and numbers as needed
>> and I wonder if this is the issue here.
>> 
>> Please, please, please does anybody know how I can solve this problem? I
>> have googled and peered into source code and nothing I've tried works.
> 
> 	What's wrong with using Open Client? Does it work on Gentoo?

Sybase ASE 11.0.3 is available only as an rpm for Redhat. It is also quite
picky about its libraries and often one needs to install compat library
rpms to get it working.

> 	Posting the code where you get the error might help too.

The script below will try to make a query against the pubs2 database
which comes with Sybase and is used in SQL examples in the documentation.
The qty column of the salesdetail table is a smallint. No such problem
with placeholders happens when an anlogous query is executed against a
varchar column.

rich@richg ~/perl $ cat syb.pl
#!/usr/bin/perl

BEGIN {
        # FreeTDS libs are in /usr/lib/
        $ENV{SYBASE} = '/usr';
        # Sybase chokes if LANG=en_GB.utf8
        $ENV{LANG} = 'en_GB';
}

use DBI;
use Data::Dump;

use strict;
use warnings;

my $dbh = DBI->connect('dbi:ODBC:pubs2','sa','xxxxxxxx') or die "Oh NO!!:$!\n";

# Works
my $sd1 = $dbh->selectall_arrayref('select * from salesdetail where qty = 75',{Columns=>{}});
print "\n",Data::Dump::dump($sd1),"\n";

# Doesn't work
my $sd2 = $dbh->selectall_arrayref('select * from salesdetail where qty = ?',{Columns=>{}},75);
print "\n",Data::Dump::dump($sd2),"\n";

$dbh->disconnect if (defined $dbh);
rich@richg ~/perl $ ./syb.pl

[
  {
    discount => 40,
    ord_num => 234_518,
    qty => 75,
    stor_id => 7896,
    title_id => "TC3218",
  },
  {
    discount => 40,
    ord_num => 234_518,
    qty => 75,
    stor_id => 7896,
    title_id => "TC7777",
  },
]
DBD::ODBC::db selectall_arrayref failed: [unixODBC][FreeTDS][SQL
Server]Implicit conversion from datatype 'VARCHAR' to 'SMALLINT' is not
allowed.  Use the CONVERT function to run this query. (SQL-42000)(DBD:
st_execute/SQLExecute err=-1) at ./syb.pl line 23.

undef
rich@richg ~/perl $


Thanks for the reply
Rich



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

Date: Tue, 05 Jul 2005 14:51:46 +0200
From: Reinhard Pagitsch <rprp@gmx.net>
Subject: Re: Help to get started with Module Games::QuizTaker
Message-Id: <42ca8262$0$18650$14726298@news.sunsite.dk>

Hello Marek

Marek Stepanek wrote:
> 
> Hello all, 
> 
> 
> But I am unable to understand the manual % perldoc Games::QuizTaker
What you do not understand? I did a look into this module, and it seems 
quit easy to me.


> Thank you and greetings from Munich
> 
regards from Austria,
Reinhard


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

Date: Tue, 05 Jul 2005 16:01:45 +0200
From: Marek Stepanek <mstep@t-online.de>
Subject: Re: Help to get started with Module Games::QuizTaker
Message-Id: <BEF05F69.14B5A%mstep@t-online.de>

On 05.07.2005 14:51, in article 42ca8262$0$18650$14726298@news.sunsite.dk,
"Reinhard Pagitsch" <rprp@gmx.net> wrote:

> Hello Marek
> 
> Marek Stepanek wrote:
>> 
>> Hello all, 
>> 
>> 
>> But I am unable to understand the manual % perldoc Games::QuizTaker
> What you do not understand? I did a look into this module, and it seems
> quit easy to me.
> 
> 
>> Thank you and greetings from Munich
>> 
> regards from Austria,
> Reinhard


Reinhard, greetings to Austria from Munich in Bavaria (rainy day today),


yes I know it seems quite straight forward, this man page; but I am a newbie
to Perl, specially with Modules and the read-in and put-out stuff is too
complicate for me. I would like that a good soul writes me one little
document in Perl "games_quiztaker.pl" and one little file with three
"questions.txt", which the Perl-document calls, just to get me started. This
is way over my head to this. Meantime I would learn something new in Perl!
And I don't want you to make my work, because I really want to learn Perl!

The examination is approaching, and I need a flexible solution to put
learning matters into a question and answer form. Really I would be very
grateful for some help, please :-)



marek



-- 
______________________________________________________________________
___PODIUM_INTERNATIONAL_//_the_embassy_for_talented_young_musicians___
______ Marek_Stepanek  mstep_[at]_PodiumInternational_[dot]_org ______
_________________ http://www.PodiumInternational.org _________________
______________________________________________________________________





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

Date: Tue, 05 Jul 2005 16:50:16 +0200
From: Reinhard Pagitsch <rprp@gmx.net>
Subject: Re: Help to get started with Module Games::QuizTaker
Message-Id: <42ca9e29$0$18638$14726298@news.sunsite.dk>

Hello Marek,

Marek Stepanek wrote:

> On 05.07.2005 14:51, in article 42ca8262$0$18650$14726298@news.sunsite.dk,
> "Reinhard Pagitsch" <rprp@gmx.net> wrote:
> 
> 
>>Hello Marek
>>
>>Marek Stepanek wrote:
>>
>>>Hello all, 
>>>
>>>
>>>But I am unable to understand the manual % perldoc Games::QuizTaker
>>
>>What you do not understand? I did a look into this module, and it seems
>>quit easy to me.
>>
>>
>>
>>>Thank you and greetings from Munich
>>>
>>
>>regards from Austria,
>>Reinhard
> 
> 
> 
> Reinhard, greetings to Austria from Munich in Bavaria (rainy day today),
here too :-(.
> 
> 
> yes I know it seems quite straight forward, this man page; but I am a newbie
> to Perl, specially with Modules and the read-in and put-out stuff is too
> complicate for me. I would like that a good soul writes me one little
> document in Perl "games_quiztaker.pl" and one little file with three
> "questions.txt", which the Perl-document calls, just to get me started. This
				  ^^^^^^^^ you mean the script, I guess.
Download the module from CPAN (search.cpan.org) and look at the sampleqa 
and sample.csv files. They can be used to learn how you have to create 
the "questions.txt".
> is way over my head to this. Meantime I would learn something new in Perl!
> And I don't want you to make my work, because I really want to learn Perl!
> 
> The examination is approaching, and I need a flexible solution to put
> learning matters into a question and answer form. Really I would be very
> grateful for some help, please :-)
To learn Perl I recommend to buy some books at, e.g. amazon.com/de. E.g:
the "Perl Kochbuch" (O'Reilly (Februar 2004).
I did it the same (at this time I have about 3 or 4 books at home). I 
think that that what you want is not a good idea, because Perl has to 
many features for many things you can do, e.g Web programming, 
administrate networks and much, much more.
Therefor I recommend to concentrate at the first time to the Perl-basics 
and/or a specific issue you are interested in and search for sample 
solutions on the web, try to read _and_ understand the source code, and 
if there are any questions about it try to ask in a newsgroup.
There are also many tutorials about Perl on the Web where you can get 
informations.

But I think we are OT here, so write directly to me (rpirpag [at] aon 
dot at).



I also recommend the german NG for perl: de.comp.lang.perl.misc


regards,
Reinhard


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

Date: Tue, 05 Jul 2005 13:56:12 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: Help With Pattern Matching
Message-Id: <0kwye.114092$Vj3.55291@fe2.news.blueyonder.co.uk>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> axel@white-eagle.invalid.uk wrote:
>> I suggest matching the word boundaries by the use of \b :
>> 
>>       /\b\w*p\w*\b/
> 
> How does that differ from
 
>     /\w*p\w*/
> 
> i.e. what difference would it make to include word boundaries?
 
None... I'm not sure how my thought processes were
running last night.

Axel



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

Date: Tue, 05 Jul 2005 20:24:42 +0530
From: "Rohan R. Almeida" <arcofdescent@gmail.com>
Subject: Re: OT: keeping track of time when programming
Message-Id: <1120575268.0737020a6adde6f107b826a737c0b8e9@teranews>

Dave wrote:
> <frustrated>
> 
> Sorry, this mostly doesn't belong here, but I just became very
> frustrated when I looked at the clock and noticed yet again that hours
> had passed in what seemed like minutes!
> 
> Is it an accurate assumption that this is a common tendency among
> programmers when writing or debugging code?  If so, what strategies have
> you found effective for dealing with it?
> 

I personally use Karm - a time tracker tool on KDE

http://pim.kde.org/components/karm.php

-- 
Rohan


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

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


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