Re: processing a hash of a hash of a hash

2006-07-06 Thread Peter Hoose

foreach $key2 (keys %{$top{$key{$key1}}}){   # line 522



Try:

foreach $key2 (keys %{$top{$key}{$key1}}){   # line 522

* Maybe it's a missing right curly brace around $key

~P

- Original Message - 
From: "Ryan Moszynski" <[EMAIL PROTECTED]>

To: 
Sent: Thursday, July 06, 2006 5:14 PM
Subject: processing a hash of a hash of a hash



I am trying to print out a hash of a hash of a hash table(with code
chunk 1), but I keep getting the following error:

Use of uninitialized value in hash element at ./clearwhite.pl line 522.


I don't understand where this error is coming from since I can process
a hash of a hash just fine, using code chunk2, and i know that the
values I am trying to process exist, as i can print them out, or run
the exists/defined/true tests on them as i do here.

Where is my mistake?  How is this done?

thanks fo rlooking at this,
ryan

-

1 - Use of uninitialized value in hash element at ./clearwhite.pl line 
522.

##

   print "Exists\n" if exists $top{$getgroup}{IOTESTS}{0} ;
   print "Defined\n" if defined $top{$getgroup}{IOTESTS}{0};
   print "True\n"  if $top{$getgroup}{IOTESTS}{0};

#prints Exists\nDefined\nTrue\n


foreach $key (keys %top){

foreach $key1 (keys %{$top{$key}}){

foreach $key2 (keys %{$top{$key{$key1}}}){   # line 522

 print "$key $key1 $key2 $top{$key}{$key1}{$key2}\n";
}
}
}

##

2 - works
#
my $key; my $key1; my $key2; my $value;

foreach $key (keys %top){

foreach $key1 (keys %{$top{$key}}){

print "$key $key1 $top{$key}{$key1}\n";

}
}


--
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: Newbie Perl Question

2006-07-17 Thread Peter Hoose
I'm pretty new myself, as such I like to see a little more error checking to 
accomodate for mine (or other people's) mistakes, here's one similar to 
Rob's but with some additional error checking that you might want, basically 
the main difference is that it expects your lines to be formatted like:


dr5digitsVariableLengthFieldOfDigits5digitsFreeFormDescription

* upper or lower case is fine thanks to the i switch at the end of the regex

If the line doesn't look like that it will let you know what line is in 
error and exit.


This also prints both to the screen and to an output file:

Screen Output:

print "Writing output to: $OutputFileName: 
$PartNum;$Quantity;$Description\n";


File Output:


print OUTF "$PartNum;$Quantity;$Description\n";


I find this to be quite handy when I'm first running a script like this as 
it will help me see how things are working real time.


If you want to stop printing to either one, just delete the line or comment 
it out with a preceding #.


===BEGIN COPY PASTE SCRIPT=

#!/usr/bin/perl

use strict;
use warnings;

my $InputFileName   = "somefile.txt";
my $OutputFileName  = "outputfile.txt";

open(INF, $InputFileName) or die "Could not open $InputFileName for reading: 
$!\n";
open(OUTF, ">$OutputFileName") or die "Could not open $OutputFileName for 
output: $!\n";


print "\n";

while() {
 if ($_ !~ /^(dr\d{5})(\t)(\d*)(\t)(\d{5})(.*)/i) {
   print "Found an incorrectly formatting line at line: $. $_, please 
correct this line and try again\n";

   exit;
 }
 else {
   my ($OrderNum, $PartNum, $Quantity, $Description) = ($1, $3, $5, $6);
   $Quantity += 0;
   chomp($Description);
   print "Writing output to: $OutputFileName: 
$PartNum;$Quantity;$Description\n";

   print OUTF "$PartNum;$Quantity;$Description\n";
 }
}

print "\n\nAll done! Please see: $OutputFileName for your data!\n";

close(INF);
close(OUTF);

END COPY PASTE SCRIPT

Hope this helps!

~P


- Original Message - 
From: "Rod Burgess" <[EMAIL PROTECTED]>

To: 
Sent: Monday, July 17, 2006 1:59 PM
Subject: Newbie Perl Question



I am new to the Perl world and am trying to learn it.  A coworker tells me
that Perl will not work for what I am trying to do however, I think Perl
would be a great tool to use and  I feel this coworker is wrong.
I have a file that contains several lines all as below:
DR03555{tab}45600062888{tab} 8FLAT WASHER
DR03555{tab}228765329{tab}1GASKET

The meaning of the file is
DR03555 = order number
45600062888 = part number
8 = quantity
FLAT WASHER = Description

The lines all begin with the prefex DR  I would like to read this file and
produce the following output:

45600062888;8;FLAT WASHER
228765329;1;GASKET

basiclly I need a file that lists the following: 
Part#;Quantity;Description


Is this possible with Perl?



--
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: Access MDF files

2006-08-09 Thread Peter Hoose
- Original Message - 
From: "Mike Blezien" <[EMAIL PROTECTED]>

To: "Perl List" 
Sent: Wednesday, August 09, 2006 11:20 AM
Subject: Access MDF files



Hello,

is there a Perl module available to obtain data from Access .mdf files ?

thx's

Mike(mickalo)Blezien

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




DBI and DBD::ODBC

Here's a sample connection script:
==

#!/usr/bin/perl

use DBI;
use DBD::ODBC;
use strict;
use warnings;

my $dsn = "test.mdb";

my $dbh = DBI->connect("dbi:ODBC:driver=microsoft access driver 
(*.mdb);dbq=" . $dsn) or die "Can't connect to database: $dsn: 
$DBI::errstr\n";


if ($dbh) {
 print "Connected to: $dsn\n";
 $dbh->disconnect;
 exit;
}

==

You can also use "ODBC Data Source Administrator" to setup System DSN's as 
another way to connect, instead of directly to the file, like the above 
example.


There's a number of tutorials on this subject that you can find by googling 
"perl access tutorial" or "perl odbc access", etc...


Hope this helps,

Peter 



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