Adding to a Hash

2004-11-26 Thread Graeme St. Clair
I've inherited an application that issues several different SQL requests,
lovingly creating different lists of user-friendly column names for each of
the different database column names that might be returned.  To cut down
future maintenance requirements, I thought I would generalise the
HTML-emitting code to read the column names from
 
The following hash is intended to help render database column names into
more user-friendly column names for the resulting HTML .  Some
user-friendly names are two words, some only one.
 
my %sname = qw {
  COUNTRY_NAME   Country
  ...
};
my %words2 = (
  "ORDER_NUMBER",   "Order Number",
  ...
);
#%sname{keys %words2} = values %words2;
%sname = (%sname, %words2);
 
I couldn't find a way to combine the whole assignment into any fewer
statements, apart from the obvious way of double-quoting everything in
sight, on the model of %words2.  Moreover, the commented line was lifted
straight out of the Llama book 2nd Ed p70, and gave a syntax error - the
line below it works, but is described there as "much slower" than the
commented line.
 
Any offers to improve the foregoing, other than what I've called "the
obvious way"?
 
Rgds, GStC.
 
 
 


RE: Adding to a Hash

2004-11-27 Thread Graeme St. Clair
Thanks for the hint.  What worked in the end was:-

%s =
(
qw( a 1 b 2 ),
"3", "3",
"4", "4",
);

which is about as terse and clear as I'd been hoping for.

Rgds, GStC.

PS: The Llama line is actually a correction to an earlier edition.  Goodness
knows why it didn't work, but I don't think I'll bother with it any more...


-Original Message-
From: Paul Johnson [mailto:[EMAIL PROTECTED] 
Sent: Friday, November 26, 2004 9:32 PM
To: Graeme St. Clair
Cc: '[EMAIL PROTECTED]'
Subject: Re: Adding to a Hash

On Fri, Nov 26, 2004 at 06:19:28PM -0800, Graeme St. Clair wrote:

> my %sname = qw {
>   COUNTRY_NAME   Country
>   ...
> };
> my %words2 = (
>   "ORDER_NUMBER",   "Order Number",
>   ...
> );
> #%sname{keys %words2} = values %words2; %sname = (%sname, %words2);
>  
> I couldn't find a way to combine the whole assignment into any fewer 
> statements, apart from the obvious way of double-quoting everything in 
> sight, on the model of %words2.  Moreover, the commented line was 
> lifted straight out of the Llama book 2nd Ed p70, and gave a syntax 
> error - the line below it works, but is described there as "much 
> slower" than the commented line.

Either you have miscopied that line or there is an error in the Llama.

  @sname{keys %words2} = values %words2;

> Any offers to improve the foregoing, other than what I've called "the 
> obvious way"?

This, perhaps?

use Data::Dumper;

%s =
(
qw( a 1 b 2 ),
c => "3 3",
d => "4 4",
);

print Dumper \%s;

%t = ( e => 5 );
@t{keys %s} = values %s;

print Dumper \%t;

--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Running Perl Scripts Via A Web Page

2004-11-30 Thread Graeme St. Clair
O'Reilly is your friend (IMHO).  You need a good HTML book, and Musciano is
its author.  You need the "Camel book" ("Learning Perl", Schwartz et al),
and probably the "Llama book" ("Programming Perl", Wall et al).  I'm happy
with them all.  I haven't yet found a definitive Apache/CGI book, but you
will need one!  I usually take an afternoon to go to my local decent book
shop (here, Barnes & Noble in State College PA), and just plain browse...
And ordering them online will probably save a few bucks too.

HTH, G.


-Original Message-
From: Brian Volk [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, November 30, 2004 3:52 PM
To: Beginners (E-mail)
Subject: Running Perl Scripts Via A Web Page

Hi All,
 
Can someone please recommend a book for me.  I do some web administration w/
perl scripts.  I would like to create a web page w/ drop down menus... and
depending on the selection criteria, run that script.  I searched on Google
a little, but not really sure what I'm looking for.  :~)  
 
Thanks!
 
Brian Volk
HP Products
317.298.9950 x1245
  [EMAIL PROTECTED]
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: mysql timeout

2004-12-06 Thread Graeme St. Clair
There is a MySQL global variable called connect_timeout.  Its default value
is 5 minutes.  Try searching www.mysql.com doc links for details.

Rgds, GStC.


-Original Message-
From: Ing. Branislav Gerzo [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 06, 2004 9:04 AM
To: [EMAIL PROTECTED]
Subject: mysql timeout

Hi all,

maybe this is not perl related, but I am not sure. I'm connecting to mysql,
and after I'm executing some queries. Sometimes - when query is too
complicated, or I start second complicated query, I get:

DBD::mysql::st execute failed: Lost connection to MySQL server during query
at...

Do you know how to set up this timeout ? I also looked at mysql
documentation, but I found nothing what helps.

Thanks

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: [Released] [Contains offensive content] RE: Building Network Redundancy into a Perl Client

2004-12-06 Thread Graeme St. Clair
Does anyone know why or where the phrase [Contains o f f e n s i v e
content] is being inserted into these headers?  I wouldn't care, except my
employer's spam filter is holding them up for whatever reason, as it might
be, use of the said phrase...

Rgds, G.

-Original Message-
From: Joshua Berry [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 06, 2004 10:01 AM
To: Jim
Cc: [EMAIL PROTECTED]
Subject: [Released] [Contains offensive content] RE: Building Network
Redundancy into a Perl Client

I don't think that it is possible to do within perl so I had to enable these
options:

echo 1 >> /proc/sys/net/ipv4/tcp_tw_reuse echo 1 >>
/proc/sys/net/ipv4/tcp_tw_recycle

-Original Message-
From: Jim [mailto:[EMAIL PROTECTED]
Sent: Saturday, December 04, 2004 8:27 PM
To: Joshua Berry
Cc: [EMAIL PROTECTED]
Subject: RE: Building Network Redundancy into a Perl Client

> I am trying to implement redundancy in a client application that I am 
> writing so that I can have a primary server and a backup server.  The 
> client is tailing a logfile and sends results to a server for 
> processing, at the end of the tail loop it sends data to a function 
> that tries to establish a connection to the primary server and send 
> the data, if that fails then the data is sent to the backup (failover) 
> server.
> The way the function works, if the primary comes back online then it 
> automatically knows and starts sending data back to the primary.
> 
> The only problem with the way this is implemented is that every 
> connection remains for a couple of minutes in the TIME_WAIT stage:
> 
> tcp0  0 xxx.xxx.xxx.xxx:xxx   xxx.xxx.xxx.xxx:xxx
> TIME_WAIT
> tcp0  0 xxx.xxx.xxx.xxx:xxx   xxx.xxx.xxx.xxx:xxx
> TIME_WAIT
> 
> Which adds up if I am sending several connections per minute or 
> possibly per second.  My question is, is there a way to bypass the 
> TIME_WAIT stage or at least reduce the time it is in this stage from 
> within the program?  Below is the subroutine and how it is called.  If 
> there is another way of doing this please let me know.

I took a look at socket options ( setsockopt() ) but I don't see anyting
that would change the time_wait timer ,but I didn't look that hard :).
What
OS are you using? You may have tomodify some kernel settings if you are
using UNIX/LINUX. With windows, here are a few links that may help

http://www.winguides.com/registry/display.php/878/

http://www.windowsitpro.com/Web/Article/ArticleID/23276/23276.html




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.802 / Virus Database: 545 - Release Date: 11/26/2004
 


--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] 




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE:[Contains content] OT topic concluded

2004-12-06 Thread Graeme St. Clair
Yes, I did know it was OT - in fact I nearly put OT in the header.  Except
that that might have disturbed whatever was going on, and I wanted to find
if the annotation emanated from the system of one of the list users.  Asking
the question on some other list would not have elicited your answer, for
which thanks!  I'll try to get an explanation from our anti-spammers.

Rgds, G.
 

-Original Message-
From: Jonathan Paton [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 06, 2004 6:45 PM
To: Graeme St. Clair
Cc: [EMAIL PROTECTED]
Subject: Re: [Released] [Contains offensive content] RE: Building Network
Redundancy into a Perl Client

Dear Graeme,

The problem is with your employers filtering software, as the copy of the
same message I received was unaltered.  Perl beginners is not the place to
ask about this.

Jonathan Paton

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Finding missing syntax element

2004-12-13 Thread Graeme St. Clair
 
From: Harry Putnam <[EMAIL PROTECTED]>
> I'm working on a program with some 433 lines of perl code.
> Some where in the course of editing today I've run up on an error that 
> I need some way to debug.
> 
> the code includes 
>use diagnostics;
> 
> And the message I get when I try to run it:
> 
>   Missing right curly or square bracket at ./nms2.pl line 433, at end
>   of line syntax error at ./nms2.pl line 433, at EOF Execution of
>   ./nms2.pl aborted due to compilation errors (#1)

Clutching at straws...  Is it possible that in the diff's your eye slid past
a curly bracket that should have been square, but in classic fashion, you
saw what you expected to see?

BTDT, GStC.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: remote database access in perl

2004-12-13 Thread Graeme St. Clair
As someone else said, this is almost certainly a MySQL "problem".

When you connect from a local machine, you are known to MySQL as
'fred'@'localhost', and you have a particular identity.  When you connect
from a remote m/c, you are 'fred'@'some.tcp.ip.addr', and you have a totally
different identity.  You almost certainly need to get your MySQL
administrator to allow the remote identity to connect.

Rgds, GStC.


-Original Message-
From: Adam Saeed [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 13, 2004 7:55 AM
To: Perl Beginners List
Subject: remote database access in perl

I have written a simple program that should get data from a remote database,
but it is not working giving error:
DBI->connect(sugs:192.168.14.2) failed: Host 'www.sample.com' is not
allowed to connect to this MySQL server at testbug.pl line 12

code is below:
*
#! /usr/bin/perl -w

use DBI;
use strict;

my ($driver = 'mysql',$user = 'root',$pass = "",$database = 'sugs');

my $dsn = "DBI:$driver:$dbname:192.168.14.2";
my $dbh = DBI->connect($dsn,$user,$pass);

my $strsql="select * from products where product='L2'"; my $sth =
($dbh->prepare($strsql) || die "Query could not be executed " .
$dbh->errstr()); i$sth->execute(); while (my $row =
$sth->fetchrow_arrayref){ print join("\t", @$row), "\n"; } $sth->finish();
$dbh->disconnect();

Script is working fine on the host machine(192.168.14.2) but give error when
run from remote machine...
any suggestion?

Thanks
Adam

--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Missing output on browser

2004-12-21 Thread Graeme St. Clair

You may be getting a different set of environment variables in cgi than from
the command line. I had to put a "BEGIN" block in all of my cgi scripts - to
set environment - for the scripts to work in cgi...

Jwm



Interesting!  I guess that explains the BEGIN block I recently inherited.
Context is Solaris and Oracle:-

use DBI;
use CGI;

#
# Database connect information
#
BEGIN {
$ENV{ORACLE_HOME} = q{/long/complicated/oracle/name};
$ENV{TWO_TASK}= q{blah.fred.com};
$uid  = q{auserid};
$pw   = q{apassword};
}

Thanks for the explanation.



And for the OP: you probably should use something like:-

my $dbh = DBI->connect("dbi:Oracle:ora817", $oraUser, $oraPass) or die
"Can't connect for this reason: $DBI::errstr\n";

Oh, and if your server is Apache, look in its error.log.

HTH, GStC.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Neat Trick

2005-01-18 Thread Graeme St. Clair
Or I thought so anyway.  Gurus are at liberty to think otherwise ;-)
 
I just had to make a single  with 4 submit buttons (each with the same
'value' legend) out of 4 's each with its own 'hidden' field.  I used
the following to distinguish between them:-
 
my $request = defined $formData->param(q{Submit1}) ? q{serial} :
  defined $formData->param(q{Submit2}) ? q{order} :
  defined $formData->param(q{Submit3}) ? q{sql} :
  defined $formData->param(q{Submit4}) ? q{user} :
 q{Unknown};

Probably it could be still more obfuscated...
 
HTH somebody, rgds, GStC.
 


RE: Neat Trick

2005-01-18 Thread Graeme St. Clair
Wow!  I might just try these two for kicks, tho as nobody likely to inherit
this from me is likely to be a Perl hand, I think I'll probably KISS for
now.

I don't necessarily disagree about '' vs qq{}.  It's just that the rest of
the code is styled with qq{}, and I thought it better to keep that going.

Tx & rgds, GStC.


-Original Message-
From: Jenda Krynicky [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 18, 2005 7:26 PM
To: beginners@perl.org
Subject: Re: Neat Trick



How about:

my %action = (
Submit1 => 'serial',
Submit2 => 'order',
Submit3 => 'sql',
Submit4 => 'user',
);
...

my ($request) = grep {defined $formData->param($_) and $action{$_}} keys
%action; $request ||= 'Unknown';

or 

my ($request) = map $action{$_}, (grep (defined($formData-
>param($_)), keys %action;
$request ||= 'Unknown';

I also think that your code would be more readable if you used '' 
instead of q{}.

Jenda

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Naming Convention?

2005-01-21 Thread Graeme St. Clair
Is there any common convention governing names of variables defined in a
'require'd 'blah.pl'?  I'd like to make use of such variables detectable to
the naked eye in the scripts that 'require blah.pl'.
 
Rgds, GStC.
 


RE: How to find regex at specific location on line

2005-01-22 Thread Graeme St. Clair
Try the {} notation, that says how many whats are required before the which
(as it were).  Perhaps something like:-

 if (/.{31,33}\|[BNPG]\|/){
return 2;
}

Meaning, between 31 & 33 characters.  Untested!

HTH, GStC.


-Original Message-
From: Jason Balicki [mailto:[EMAIL PROTECTED] 
Sent: Friday, January 21, 2005 9:24 PM
To: 'Perl Beginners List'
Subject: How to find regex at specific location on line

Hello,

If you would, please consider the following input file:


|6643|Jason Balicki   |  |0501211243|000:00:00|0| S
|0|
||13145551212 |N||   0|001001|001001| 100|
10|B|A|


And the following code:


while(<>){
if (whichline($_) == 1){
print "input line is call record line 1\n";
}
else {
if (whichline($_) == 2){
print "input line is call record line 2\n";
}
}
}

sub whichline {
if (/\|[BNPG]\|/){
return 2;
}
else {
if (/\|[0A-Z]\|$/) {
return 1;
}
}
}


You'll notice that regex "|[BNPG]|" which should match the
|N| on the second line of the input file.  That field will
always be located on the 31st, 32nd and 33rd characters on the line.

This regex works, and has been in use for a couple of days now, but I'd like
to be more explicit, especially since I can never be sure that another line
of input won't contain that string (I am filtering from a serial port that
will have other output.)  If I can pin it to a specific location, it would
at least be a little better.

Is there a way that I can specify that that regex starts on a particular
character on the line?

Thanks very much for any input.

--J(K)


--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: How to find regex at specific location on line

2005-01-24 Thread Graeme St. Clair
I knew what I meant, I just didn't write what I meant.  Next time, I'll have
a coffee first...

Of course you're right I forgot to anchor it too.

Rgds, GStC.


-Original Message-
From: John W. Krahn [mailto:[EMAIL PROTECTED] 
Sent: Saturday, January 22, 2005 8:41 PM
To: Perl Beginners
Subject: Re: How to find regex at specific location on line

Graeme St. Clair wrote:
> Try the {} notation, that says how many whats are required before the 
> which (as it were).  Perhaps something like:-
> 
>  if (/.{31,33}\|[BNPG]\|/){
> return 2;
> }
> 
> Meaning, between 31 & 33 characters.  Untested!

No, that is not what it means.  It means match . (any character except
newline) 31, 32 or 33 times and since it is greedy it will usually be 33
times and *then* match \|[BNPG]\|.  So it will try to match \|[BNPG]\| at
the 34th or later position since the pattern isn't anchored to the beginning
of the line.


John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/>
<http://learn.perl.org/first-response>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Naming Convention?

2005-01-24 Thread Graeme St. Clair
Thanks for the pointer to 'perlstyle' and 'Exporter'.  I shall read, mark
and inwardly digest.

But I don't understand what you mean by C?  (I'm already using strict &
warnings.)

Rgds, GStC.
 

-Original Message-
From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED] 
Sent: Saturday, January 22, 2005 11:02 AM
To: Graeme St. Clair
Cc: beginners@perl.org
Subject: Re: Naming Convention?

Graeme St. Clair wrote:
> Is there any common convention governing names of variables defined in 
> a 'require'd 'blah.pl'?  I'd like to make use of such variables 
> detectable to the naked eye in the scripts that 'require blah.pl'.
>  
> Rgds, GStC.
>  
> 

Well you should consider using C and making it a proper module. 
Then use the Exporter if you still have to pollute namespaces.  Don't just
throw everything in main::.  Turn on 'strict' and 'warnings'.

To your question, check out:

perldoc perlstyle

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Storing $DIGIT variables in arrays

2005-01-25 Thread Graeme St. Clair
I'm no expert on regex's, but IP @'s are not all that easy to match and
validate at the same time.  There is a good discussion of precisely this
problem in Chap 4 of "Mastering Regular Expressions" by  J E F Friedl, pub
O'Reilly, at pp 123-125.  He concludes:-

"Sometimes it's better to take some of the work out of the regex.  For
example, going back to

^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$

and wrapping each component in parentheses will stuff the numbers into $1,
$2, $3 and $4, which can then be validated by other programming constructs".

The discussion context is Perl specifically.

HTH, GStC.


-Original Message-
From: Jesse Taylor [mailto:[EMAIL PROTECTED] 
Sent: Sunday, January 23, 2005 5:20 PM
To: beginners@perl.org
Subject: Storing $DIGIT variables in arrays



while($url=)
{
   chomp($url);
   $html=get("$url")
  or die "Couldn't open page located at $url";

   @ips = $html =~
/(\d{1,3}[0-255]\.\d{1,3}[0-255]\.\d{1,3}[0-255]\.\d{1,3}[0-255])/g;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Hang with Use Warnings and a Subroutine

2005-01-27 Thread Graeme St. Clair
I just solved a (to me) curious hang with Windows XP, ActiveState 5.8.6,
Apache 1.3.27.
 
On Submit, an HTML page calls a Perl script into a new page.  The Perl
script runs fine with use strict but not warnings.  Add -w to the shebang
line, or add 'use warnings', and it hangs without ever presenting anything
on the new page.  And nothing goes in Apache 'error.log'.
 
The script contained what I'm going to call an "in-line" subroutine (for
sorting, surprise, surprise).  If that sub is moved down to the end of the
script after the final 'exit 0', everything works.
 
Any explanations occur to anyone?
 
Rgds, GStC.
 


Hash Getting Doubled?

2005-01-31 Thread Graeme St. Clair
Combo ActiveState Perl 5.6.1 635 and Apache 1.0.xx from www.perl.apache.org
 .
 
The following code goes round the foreach twice as often as I think it
should.  (I realise the code is probably not particularly stylish, but I'd
prefer to leave that alone for the moment.)
 
require 'xxxconstant.pl'; # not shown
require 'xxxlib.pl'; # not shown
 
use strict;
use warnings;
use CGI::Carp qw( fatalsToBrowser );
use Data::Dumper;

my $capval;
our %capdef;

&xxxlib::set_capdef;# Create the hash.

sub bynumber { $a <=> $b; }
 
select STDERR;
$| = 1;
print STDERR Dumper(%capdef); # <-- print 1

my $counter = 0;
foreach $capval ( sort bynumber %capdef ) {
  $counter++; # debug
  if (defined $capdef{$capval}) { # debug
print STDERR $counter . " " . $capval . " " . Dumper($capdef{$capval}) .
"\n"; # <-- print 2
my @elcdev = split(/;/, $capdef{$capval}{'ELIGELC'});
my @tlcdev = split(/;/, $capdef{$capval}{'ELIGTLC'});
# Useful stuff originally went here.
  } else { # debug
print STDERR "Haha!" . $counter . "\n"; <-- print 3 debug
  } # debug
}
 
exit 0;
 
As examples, here are the last two items from the line 'print 1'.  I assume
VAR341 is the key and VAR342 the contents.  Thus there are 171 items in the
hash.
 
$VAR339 = '35';
$VAR340 = {
'CAPDESC' => '35 TB',
'ELIGTLC' => '1;2;3;102;104',
'CAPVAL' => '35',
'ELIGELC' => '1;2;3;102;104'
  };
$VAR341 = '36';
$VAR342 = {
'CAPDESC' => '36 TB',
'ELIGTLC' => '1;2;3;102;104',
'CAPVAL' => '36',
'ELIGELC' => '1;2;3;102;104'
  };
 
And the first two items from 'print 2' are:-
 
1 0 $VAR1 = {
  'CAPDESC' => '0 TB (New)',
  'ELIGTLC' => '0',
  'CAPVAL' => '0',
  'ELIGELC' => '1;2;3;102;104;500'
};
2 1 $VAR1 = {
  'CAPDESC' => '1 TB',
  'ELIGTLC' => '1;2;3;102;104',
  'CAPVAL' => '1',
  'ELIGELC' => '1;2;3;102;104'
};

'print 2' shows 171 items as expected.
 
And then --- I get Haha!172 thru Haha!342 from 'print 3'.
 
What is going on that I haven't understood?
 
Rgds, GStC.
 
 

 
 
 


RE: Hash Getting Doubled?

2005-01-31 Thread Graeme St. Clair
That was it all right.  Thank you.  And this code's been in production for
years before I got it...

Now, purely for information, what actually was happening in the original
code?

Rgds, GStC.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Monday, January 31, 2005 5:02 PM
To: Graeme St. Clair
Cc: 'beginners@perl.org'
Subject: Re: Hash Getting Doubled? 

>  
> What is going on that I haven't understood?
>  
> Rgds, GStC.

Your entire problem is :

foreach $capval ( sort bynumber %capdef ) {

Perhaps you want to sort by the KEYS of %capdef

foreach $capval ( sort keys %capdef ) { }

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g Computer
software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: Hash Getting Doubled?

2005-01-31 Thread Graeme St. Clair
Lawrence's emendation stopped the extra executions, but Jay's also preserved
the original intent, which was to get the hash sorted according to $capval
being purely numeric.

Thanks to both, rgds, GStC. 

[cut] 

> my $counter = 0;
> foreach $capval ( sort bynumber %capdef ) {
>   $counter++; # debug
> ...

[cut]

> 'print 2' shows 171 items as expected.
> And then --- I get Haha!172 thru Haha!342 from 'print 3'.
> What is going on that I haven't understood?
> 
> Rgds, GStC.

Graeme,

I think you're looking for:

foreach $capval ( sort bynumber( keys %capdef) ) {

I forget what exactly 'sort %hash' (as opposed to 'sort keys %hash') does,
but not what you want.

HTH.

--jay

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Start reading from a specific line

2005-02-15 Thread Graeme St. Clair
Well, it is, you know.  In my 3rd Edn, July 2000 printing, it's indexed
about half way down the left column on p1011, where it is also described as
$INPUT_LINE_NUMBER.  Admittedly, the first reference (to p103) is off, as
some refs are in this edn.  But it's only just over onto p104.  And p665
(correct this time!) gives you the goods.

Rgds, GStC.
 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 15, 2005 11:01 AM
To: 'Perl Beginners '
Subject: RE: Start reading from a specific line

you are correct, you do not need " " around $.
thank you!
I was using strict and warnings, but must of had another error.
I am unfamiliar with the variable $.?  I tried playing with it, but was
unsuccessful.  I could not find it in cookbook nor in programming perl.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Detect platform

2005-02-16 Thread Graeme St. Clair
I lifted the following out of (IIRC) CGI.pm, and it works on this XP SP1
m/c:-

  if (($^O eq 'MSWin32') or ($^O =~ /cygwin/i)) { ...

I don't *know* that the Cygwin leg of the compare works, but considering
where I got it, why wouldn't it?!

Rgds, GStC. 

-Original Message-
From: Daniel Kasak [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 16, 2005 6:25 PM
To: Chris Devers; Tim Johnson; beginners@perl.org
Subject: Re: Detect platform

Chris Devers wrote:

>On Wed, 16 Feb 2005, Tim Johnson wrote:
>
>  
>
>>On Wed, 16 Feb 2005, Daniel Kasak wrote:
>>
>>
>>
>>>How do I detect what platform I'm running from inside a Perl script?
>>>  
>>>
>>Check out the $^O variable.
>>
>>
> 
>...but be careful in writing code that matches it:
>
>Under Mac OSX:
>
>  $ perl -le 'print $^O'
>  darwin
>  $
>
>Under Cygwin on a Win2000 machine:
>
>  [EMAIL PROTECTED] ~
>  $ perl -le 'print $^O'
>  cygwin
>
>  [EMAIL PROTECTED] ~
>  $
>
>A CMD shell on the same machine:
>
>  C:\cygwin\usr\bin>perl -le 'print $^O'
>  perl -le 'print $^O'
>
>
>  C:\cygwin\usr\bin>
>
>Yes, it produced no output. I don't know why.
>
>I believe the Activestate version reports 'win32' or something, but I 
>don't have a copy handy to confirm that.
>
>Note that the string 'win' shows up in several different ways, so if 
>you just want to match on Windows (or win32, or win2000, or similar) 
>you have to make sure that you don't also catch the slightly different 
>Cygwin environment or the much different OSX one with the same pattern.
>  
>
Thanks guys :)

Luckily I have control over all PCs that will be running this app: 
Gentoo Linux and Windows 2000 with ActiveState Perl, maybe darwin down the
track ( if I can get Gtk2 modules working ).

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au

--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Class::MethodMaker Query

2005-02-17 Thread Graeme St. Clair
I may well be in over my head here, but I just happened to be reading about
this area only yesterday.  I'm wondering if the section "References Don't
Work As Hash Keys" on p265 of Camel 3rd edn applies here?

HTH, GStC.


-Original Message-
From: Siddharth Uppal [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 16, 2005 12:41 AM
To: beginners@perl.org
Subject: Class::MethodMaker Query

Hi,

Since yesterday I've been scratching my head over the different behavior of
the two pieces of codes listed under "listing-1" and "listing-2", because I
expect the two to behave in a similar manner.

--start listing-1---

package Foo;

use strict;
use warnings 'all';

# Member fields with their default values
our %_FIELD_DEFAULTS = ( 'a'=> "def1"
   , 'b'=> "def2"
   , 'c'=> "def3"
   );

my @fields = (keys %_FIELD_DEFAULTS);

# Automatically generate the constructor and get/set methods use
Class::MethodMaker
   'new_with_init' => "new"
 , 'new_hash_init' => "_hash_init"
 , 'get_set'   => ['a', 'b', 'c']
;

1;

--end listing-1---

and

--start listing-2---

package Foo;

use strict;
use warnings 'all';

our %_FIELD_DEFAULTS = ( 'a'=> "def1"
   , 'b'=> "def2"
   , 'c'=> "def3"
   );
my @fields = (keys %_FIELD_DEFAULTS);

# Automatically generate the constructor and get/set methods use
Class::MethodMaker
   'new_with_init' => "new"
 , 'new_hash_init' => "_hash_init"
 , 'get_set'   => [EMAIL PROTECTED]; # Pass a ref to the array!

1;

--end listing-2---

I expect Listing-1 and Listing-2 to do the same thing, but they actually
appear to behave differently.

I have a perl script test.pl that instantiates an object of Foo package. The
script looks like this:

-start listing-3---

#! /usr/local/bin/perl -w

use strict;
use warnings 'all';

use Foo;

my $obj = Foo->new(a => 1, b => 2, c=> 3); print $obj->a(), "\n"; print
$obj->b(), "\n"; print $obj->c(), "\n";

-end listing-3---

If I use the code of Foo.pm listed under listing-1, I get the expected
output (i.e. 1, 2, 3 printed on separate lines), but if I use the code of
Foo.pm listed under listing-2, I get an error that says:

Can't locate object method "a" via package "Foo" (perhaps you forgot to load
"Foo"?) at blib/lib/Class/MethodMaker.pm (autosplit into
blib/lib/auto/Class/MethodMaker/new_hash_init.al) line 342.

I need help in figuring out why this is happening? I would appreciate if
anyone could help clear things out for me!

Thanks,
Amit

--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Environment variables

2005-02-21 Thread Graeme St. Clair
The following works for me on a Windows XP box talking to a Solaris server:-

 BEGIN {
   if (($^O eq 'MSWin32') or ($^O =~ /cygwin/i)) {
 #   $ENV{ORACLE_HOME} = q{C:/Oracle/Ora81};
 #   But Oracle::DBD will find it from the Windows registry anyway
   } else {
 $ENV{ORACLE_HOME} = q{/path/to/product/8.1.7};
   }
   $host   = q{BLAH.BLAH.COM};
   .
 eval { ...
   $dbh = DBI->connect("dbi:Oracle:$host", $uid, $pw)
 or die qq{Unable to connect to $host:$DBI::errstr\n};
 ...

There is some Oracle s/w pre-installed on my XP box about which I know
nothing except that I can see the magic string BLAH.BLAH.COM inside
somewhere.  I've never tried disconnecting and reconnecting to some other
d-b.

HTH, GStC.
 

-Original Message-
From: Jason Wozniak [mailto:[EMAIL PROTECTED] 
Sent: Monday, February 21, 2005 4:15 PM
To: beginners@perl.org
Subject: RE: Environment variables

That's what I thought, but it doesn't work, which is why I tried system.

The below code:

use DBI;

my $database;
#my $address = "[EMAIL PROTECTED]"; my $address =
"[EMAIL PROTECTED]"; my %attr; my $dbh; open MAIL, "|mail $address";
open DBFILE, ") {
$ENV{ORACLE_SID} == chomp($_);
print "$ENV{ORACLE_SID}\n";
$dbh = DBI->connect( "dbi:Oracle:$database", "", "", \%attr)
or print MAIL "Could not connect to database: $ENV{ORACLE_SID}
$DBI::errstr\n"; } close MAIL;

produces the following output:

P01
P01
P01
P01
P01

The file /u01/app/oracle/check_list.txt contains several different sids, and
if I print $_ it is reading them in.


-Original Message-
From: Scott Pham [mailto:[EMAIL PROTECTED]
Sent: Monday, February 21, 2005 4:05 PM
To: Jason Wozniak
Subject: Re: Environment variables

You want use ENV hash (%ENV). The reason why system or `` doesn't work is
due to them being forked off.

$ENV{ORACLE_SID} = "whateva";

will do it for you.


On Mon, 21 Feb 2005 15:51:06 -0500, Jason Wozniak <[EMAIL PROTECTED]>
wrote:
> Hello,
> 
>I'm trying to write a paging script that connects to
several
> databases in succession, and was attempting to write the script such 
> that I would not have to hard code any user names, or passwords, by 
> using an externally identified user.
> 
> I can connect to the first database in the list ok, but I can't figure 
> out how to change my ORACLE_SID environment variable, so it simply 
> reconnects to the same database each time through the loop for every
sid
> in the file.  I tried setting $ENV{ORACLE_SID} to no effect.  I even 
> tried using:
> 
> System("export ORACLE_SID = $_");  and verified $_ was being read in 
> correctly, as seen below.  Is there no way to modify your shell 
> environment from within a perl program?  I saw a module called 
> Env-Bash-0.04, but it doesn't seem to say if you can update an 
> environment variable, it just makes sure you can access them all.
> 
> use DBI;
> 
> my $database;
> 
> my $address = "[EMAIL PROTECTED]";
> 
> my %attr;
> 
> my $dbh;
> 
> open MAIL, "|mail $address";
> 
> open DBFILE, " 
> while () {
> 
> system("export ORACLE_SID = $_");
> 
> $dbh = DBI->connect( "dbi:Oracle:$database", "", "", \%attr)
> 
>or print MAIL "Could not connect to database: $ENV{ORACLE_SID} 
> $DBI::errstr\n";
> 
> }
> 
> close MAIL;
> 
>



--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: standardising spellings

2005-02-24 Thread Graeme St. Clair
 

-Original Message-
From: Peter Rabbitson [mailto:[EMAIL PROTECTED] 
Sent: Thursday, February 24, 2005 2:01 PM
To: beginners@perl.org
Subject: Re: standardising spellings

On Thu, Feb 24, 2005 at 06:01:50PM -, Dermot Paikkos wrote:
> Hi,
> 
> I have a list of about 650 names (a small sample is below) that I need 
> to import into a database. When you look at the list there are some 
> obvious duplicates that are spelt slightly differently. I can 
> rationalize some of the data with some simple substitutions but some 
> of the data looks almost impossible to parse programmatically.
> Here what I have done so far - it's not much:
> 

I would use String::Approx's amatch, and run the list in several rounds. The
first round would look for possible 1 step mismatches, then 2 step then 4
step then 6 step etc. Every time you interactively confirm a delete, it is
deleted from some kind of global hash, so the next round will not find the
duplicate a second time. Or if it is a one time show - just write a simple
thing that will run through the list amatching a fixed number of steps, and
delete everything you confirm, writing the result to a file. Then increase
the step and do it again and again untill you get tired of it :)

#

Neat!  Being one, I particularly enjoyed the "perldoc String::Approx" bit
where it compared McScot to MacScot.

I saw this kind of thing attempted in an old IBM VM CMS user-written utility
called SCANCMS.  I don't have the code any more, but it did things like
collapse "nn" into "n", "turn "sky" into "ski", drop all h's and such like.
So Coffman, Kaufmann and Kauffman would all end up as Cofman or even Cfmn
for the purposes of the comparison.

I don't know if this approach would be any improvement on Approx; probably
not, tho it does look like Approx is a binary black box, and this approach
might be more modifiable.

Rgds, GStC.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Load an hash from a text file

2005-03-01 Thread Graeme St. Clair
Try this - the 'g' at the end means 'global', that is, every occurrence of
the target string.

> >   $line =~ s/\Q$replacement->[0]\E/$replacement->[1]/g;

HTH, GStC.

-Original Message-
From: Web Solving [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 01, 2005 11:58 AM
To: Charles K. Clarkson
Cc: Perl BG
Subject: Re: Load an hash from a text file

sorry, i'm a dummy, your script works good, but i've another question:
why your script replace only ONE word per line, even i load the array with
16 terms (and i note that there are 3 or 4 lines with at least 2 different
terms of the list)? i tried to enbed your script in a large for
routine(about 100 times) but it change only one term per lineit's
strange

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: z/OS unicode problem.

2005-03-03 Thread Graeme St. Clair
Well, not exactly.  The extra \x00 is only present in characters whose value
<= 127, which actually does not include either A-grave; the lc one is \xe0,
the uc \xc0.  Otherwise, there is an increasingly elaborate encoding scheme,
which may occupy 2, 3 or 4 bytes.  I'll paraphrase part of it:-

A 2-byte encoding, e.g. \xcf83, is interpreted thus:-

Byte 0 (here \xcf) 1 1 0 a a a a a
Byte 1 (here \x83) 1 0 b b b b b b

The whole value is a bb, in this case 0 11, or \x03c3, in
other words greek lower case sigma.  The 3- and 4-byte encodings take this
sort of thing even further.

Rgds, GStC.

  

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 02, 2005 11:59 PM
To: [EMAIL PROTECTED]; beginners@perl.org
Subject: RE: z/OS unicode problem.


Hi,

May be this is could be useful; Unicode characters have two bytes for each
character. Each character has "0x00" following to the each character. You
need to remove the "0x00" after each character and then do the Regular
Expression matching.

my $temp = chr(0x00);
$line =~ s/$temp//g; this remove the Unicode characters from the line.

Regds
Suresh

-Original Message-
From: Rajarshi Das [mailto:[EMAIL PROTECTED]

Sent: Thursday, March 03, 2005 5:33 AM
To: beginners@perl.org
Subject: z/OS unicode problem.

Hi,
I had a question regarding utf-ebcdic issues on z/OS. I tried this on a

perl-5.8.6.  If I use a unicode character within a character class and try

matching the same using a regular expression, I get a failure.

e.g. if I write this ;

use charnames:full;

$a = "\N{LATIN SMALL LETTER A WITH GRAVE}"; $b = "\N{LATIN CAPITAL LETTER A
WITH GRAVE}";

$a =~ m/[$b]/i;

This fails whereas,

$b =~ m/[$a]/i;
passes.

Does anyone have thoughts on why this might be happening ? Alternately,

could someone let know as to who could help ?

Thanks in advance,
Rajarshi.

_
Click, Upload, Print. http://www.kodakexpress.co.in?soe=4956 Deliver in

India.


--

To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] 






Confidentiality Notice


The information contained in this electronic message and any attachments to
this message are intended for the exclusive use of the addressee(s) and may
contain confidential or privileged information. If you are not the intended
recipient, please notify the sender at Wipro or [EMAIL PROTECTED]
immediately and destroy all copies of this message and any attachments.

--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: z/OS unicode problem.

2005-03-03 Thread Graeme St. Clair
This looks like a bug (hfff!) in your version of Perl.  On my Windows XP
combo Perl/Apache (ActivePerl 5.6.1 Build 635), it barfs on both
expressions, thus:-

#!/usr/local/bin/perl

use strict;
use warnings;
use Data::Dumper;
use charnames ':full';

$a = "\N{LATIN SMALL LETTER A WITH GRAVE}";
$b = "\N{LATIN CAPITAL LETTER A WITH GRAVE}";

$a =~ m/[$a]/i ? print "a is good\n" : print "a is bad\n";
$b =~ m/[$b]/i ? print "b is good\n" : print "b is bad\n";

$a =~ m/[$b]/i ? print "a is good\n" : print "a is bad\n";
$b =~ m/[$a]/i ? print "b is good\n" : print "b is bad\n";

print Dumper($a, $b);

produces:-

C:\...\PERL Documents>perl tt5.pl
a is good
b is good
a is bad
b is bad
$VAR1 = 'α'; # Hey, it's...
$VAR2 = '└'; # Windoze (GStC)

The same thing happens on a Solaris system, whose 5.6.1 Perl dates from 26
Apr 2001 (no build given).

But on a regular ActivePerl 5.8.4 Build 810, I get:-

C:\...\PERL Documents>perl tt5.pl
a is good
b is good
a is good
b is good
$VAR1 = '\x{e0}';
$VAR2 = '\x{c0}';

HTH, GStC.

 

-Original Message-
From: Rajarshi Das [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 02, 2005 7:03 PM
To: beginners@perl.org
Subject: z/OS unicode problem.

Hi,
I had a question regarding utf-ebcdic issues on z/OS. I tried this on a
perl-5.8.6.  If I use a unicode character within a character class and try
matching the same using a regular expression, I get a failure.

e.g. if I write this ;

use charnames:full;

$a = "\N{LATIN SMALL LETTER A WITH GRAVE}"; $b = "\N{LATIN CAPITAL LETTER A
WITH GRAVE}";

$a =~ m/[$b]/i;

This fails whereas,

$b =~ m/[$a]/i;
passes.

Does anyone have thoughts on why this might be happening ? Alternately,
could someone let know as to who could help ?

Thanks in advance,
Rajarshi.

_
Click, Upload, Print. http://www.kodakexpress.co.in?soe=4956 Deliver in
India.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 

RE: Invocation environment detection

2005-03-07 Thread Graeme St. Clair
You could detect OS by use of something like this:-

 if (($^O eq 'MSWin32') or ($^O =~ /cygwin/i)) { ... # works for me

And perhaps context by this:-

 if defined $ENV{GATEWAY_INTERFACE} { ... # untested, in my case "CGI/1.1"
in CGI, else undefined

And there's a variable $^V that gives you your revision etc of Perl.

I guess you could lash them all together somehow...

HTH, rgds, GStC.

 

-Original Message-
From: Peter Rabbitson [mailto:[EMAIL PROTECTED] 
Sent: Saturday, March 05, 2005 5:42 PM
To: beginners@perl.org
Subject: Re: Invocation environment detection

What if I want it to be able to run under everything:

* CGI (html output)
* Linux tty (text only output)
* ActivePerl (text only output + some workarounds for braindead OS)

(Sorry, forgot to CC)

--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Tie::File problem (or is it just me?)

2005-03-07 Thread Graeme St. Clair
-Original Message-
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Hendrik Maryns
Sent: Monday, March 07, 2005 5:58 PM
To: beginners@perl.org
Subject: [Released] [Contains offensive content] Re: Tie::File problem (or
is it just me?)

John W. Krahn schreef:
> Hendrik Maryns wrote:
> 
>> Kevin Horton schreef:
>>
>>>
>>> What kind of line endings does the file have?  If I recall 
>>> correctly, I ran into a problem where perl did not recognize 
>>> classical Macintosh line endings as ending a line.  It thought the 
>>> whole file was one line, until I converted the line endings to Unix
format.
>>
>>
>> That must be the problem!  I work on WinXP (for the moment).  The 
>> file is generated by ChatZilla, the IRC chat program part of the 
>> Mozilla suite.  I don't know what kind of line endings it uses, how 
>> can I see this?
> 
> 
> According to RFC 1459:
> 
>IRC messages are always lines of characters terminated with a CR-LF
>(Carriage Return - Line Feed) pair, and these messages shall not
>exceed 512 characters in length, counting all characters including
>the trailing CR-LF. Thus, there are 510 characters maximum allowed
>for the command and its parameters.  There is no provision for
>continuation message lines.  See section 7 for more details about
>current implementations.
> 
> 
> However when you save that data to a file the line endings are 
> determined by the application that saves that data and to some extent 
> by the operating system.

I do understand, but is there a trick in Windows to get to see which chars
are used as newline chars in a particular file, i.e. to show ASCII chars?

Thanks for your help on splice and -i, I understand now!

H.



The only one I know comes with that fine editor TextPad, which you can
download for trial for free from www.textpad.com, or even pay for, I think
maybe about 30 USD.

Use Ctrl O, then under File Format in the new window, choose "Binary", and
"Open" and inspect to your heart's content!

HTH, rgds, GStC.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: XML Generator DBI

2005-03-21 Thread Graeme St. Clair
-w is kind of pan-galactic and influences modules you're calling, regardless
of their own 'warnings' settings.  Try 'use warnings' without -w.  See p861
in the camel 3rd edition.

HTH, GStC. 

-Original Message-
From: Mike Lesser [mailto:[EMAIL PROTECTED] 
Sent: Saturday, March 19, 2005 11:41 AM
To: Perl Beginners
Subject: XML Generator DBI

Hi all. I'm messing with XML & MySQL, and I may have run into a newbie snag.

I'm using XML::Generator ::DBI with XML::Handler::YAWriter, in the same
manner that I've seen in tutorials, the MySQL Cookbook, and other assorted
places.

> $writer = XML::Handler::YAWriter->new (AsString => 1); $query = 
> 'SELECT cd_airdate, cd_copies, cd_hilites FROM cds WHERE cd_labeled=0
> ORDER BY cd_airdate';
> $generator = XML::Generator::DBI->new(  dbh =>$dbh,
> Handler =>$writer,
> RootElement=>"Creators",
> Indent=>1,
> QueryElement => ''); 
> $xml_output = $generator->execute($query);

According to the XML::Gen perldoc, "Nulls are handled by excluding either
the attribute or the tag." The XML looks and works just fine. No prob.

However,when I use the -w option with the shebang, I get a couple warnings
for each record of the database. They're all about the same:

"Use of uninitialized value in string eq at
/Library/Perl/5.8.1/XML/Generator/
DBI.pm line 180."

Now it seems to me that if nulls are supposed to be handled by the modules,
then why the warnings? Is it normal for modules to put out warnings during
their normal function? I'm used to C/C++ environments where you normally
eliminate any warning that appears.

Mike


--
To unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED] 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Problems matching or parsing with delimiters in text

2005-03-28 Thread Graeme St. Clair
-Original Message-
From: Offer Kaye [mailto:[EMAIL PROTECTED] 
Sent: Monday, March 28, 2005 12:17 PM
To: Perl Beginners
Subject: Re: Problems matching or parsing with delimiters in text

On Mon, 28 Mar 2005 11:13:05 -0500, KEVIN ZEMBOWER wrote:
> I'm trying to read in text lines from a file that look like this:
[...snip...]

As others have said, you really should use a module. For completness, here's
a solution using Text::CSV::Simple ("datafile" holds the data you gave in
the question):

use Text::CSV::Simple;
my $parser = Text::CSV::Simple->new;
my @data = $parser->read_file("datafile"); for my $aref (@data) {
   my ($partno, $language, $title, $cost, $available) = @$aref;
   print "PN=$partno, L=$language, T=$title, C=$cost, A=$available\n"; }



I just tried the following (Win XP, AS Perl 5.6.1):-

C:\...PERL Documents>ppm install Text::CSV::Simple

And got (slightly re-formatted):-

 Installing package 'Text-CSV-Simple'...
 Error installing package 'Text-CSV-Simple':
 Could not locate a PPD file for package
 Text-CSV-Simple

Only a short while before I had no trouble with "ppm install
HTML::CalendarMonthSimple".  How do I fix the above and get the CSV module?

Rgds, GStC.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]