From: ccc31807 on 8 Jun 2010 16:27 On Jun 8, 2:10 pm, ccc31807 <carte...(a)gmail.com> wrote: > This is embarrassing! Okay, now I really am embarrassed. It's not a Perl problem at all -- it's a Microsoft problem. The script that I reference is the third one out of four, the whole process takes about six input files and outputs several thousand PDF files. I get the data from various people and a couple of databases. I get some of the data in CSV format. One of my sources switched from an Access database to an Excel file. Turns out that Excel strips out the leading zeros if it thinks that the datum is an integer. I really, really should have learned this lesson by now -- check the code, check the data. Yes, I mostly validate the data as it comes in, checking the format and so on, and the particular numeric datum I used as a key validated as numeric. It never occurred to me to look at the data file until after I spent several hours checking and rechecking my code and posting on c.l.p.m. 'Garbage in, garbage out' isn't always the result of bad code, it can be the result of bad data. Thanks to all, and please accept my apology for the excitement. CC.
From: Uri Guttman on 8 Jun 2010 16:38 >>>>> "c" == ccc31807 <cartercc(a)gmail.com> writes: c> On Jun 8, 4:05�pm, Willem <wil...(a)turtle.stack.nl> wrote: >> ) This is NOT the problem here. What this does is make the hash element >> ) $fac{$id}{courses} contain a scalar value like this: >> ) '23456 34567 45678' This works perfectly and does exactly what I want >> ) it to. >> >> No, it doesn't. c> I beg to differ, but it does. I've been running this particular piece c> of code for about three years, and it has exactly the behavior I c> described. This is a line from my debugging file with only the c> personal information replaced with XXXXX. then that is not the code that you are using. it will put the list of courses into the hash as key/value pairs. the only way you get what you claim is with "@courses". did you lose the quotes in pasting? if you claim that, show exact runnable code that does this. you can whip up an dummy example in 2 minutes. here is one: perl -MData::Dumper -e '@x = ( 1 .. 4 ) ; %y = (x => @x); print Dumper \%y' $VAR1 = { '4' => undef, 'x' => 1, '2' => 3 }; as seen, it doesn't do what you claim it does. possibly the dump trick you are using is misleading you. use data::dumper to see what is really there. here is what you seem to want: perl -MData::Dumper -e '@x = ( 1 .. 4 ) ; %y = (x => "@x"); print Dumper \%y' $VAR1 = { 'x' => '1 2 3 4' }; or alternatively with a ref: perl -MData::Dumper -e '@x = ( 1 .. 4 ) ; %y = (x => \@x); print Dumper \%y' $VAR1 = { 'x' => [ 1, 2, 3, 4 ] }; uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: Uri Guttman on 8 Jun 2010 16:40 >>>>> "c" == ccc31807 <cartercc(a)gmail.com> writes: c> 'Garbage in, garbage out' isn't always the result of bad code, it c> can be the result of bad data. Thanks to all, and please accept my c> apology for the excitement. you still have a bug if you claim x => @y will do what you want. see my other post on this. uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: ccc31807 on 8 Jun 2010 17:12 On Jun 8, 4:40 pm, "Uri Guttman" <u...(a)StemSystems.com> wrote: > you still have a bug if you claim x => @y will do what you want. see my > other post on this. -----------SCRIPT--------------- #! perl # array.plx use strict; use warnings; my %presidents; while (<DATA>) { chomp; my ($order, $first, $last, @years) = split /\|/; $presidents{$order} = { first => $first, last => $last, years => @years, }; } foreach my $k (sort keys %presidents) { print "$k => $presidents{$k}\n"; foreach my $k2 (sort keys %{$presidents{$k}}) { print " $k2 => $presidents{$k}{$k2}\n"; } } exit(0); __DATA__ 1|George|Washington|1788 1792 2|John|Adams|1796 3|Thomas|Jefferson|1800 1804 4|James|Madison|1808 1812 32|Franklin|Roosevelt|1932 1936 1940 1944 ----------OUTPUT---------------- D:\PerlLearn>perl array.plx 01 => HASH(0x248e5c) first => George last => Washington years => 1788 1792 02 => HASH(0x182a344) first => John last => Adams years => 1796 03 => HASH(0x182a3b4) first => Thomas last => Jefferson years => 1800 1804 04 => HASH(0x182a8a4) first => James last => Madison years => 1808 1812 32 => HASH(0x183ce44) first => Franklin last => Roosevelt years => 1932 1936 1940 1944
From: Tad McClellan on 8 Jun 2010 17:47
ccc31807 <cartercc(a)gmail.com> wrote: > On Jun 8, 4:40 pm, "Uri Guttman" <u...(a)StemSystems.com> wrote: >> you still have a bug if you claim x => @y will do what you want. see my >> other post on this. > > -----------SCRIPT--------------- > #! perl > # array.plx > use strict; > use warnings; > my %presidents; > while (<DATA>) > { > chomp; > my ($order, $first, $last, @years) = split /\|/; > $presidents{$order} = { > first => $first, > last => $last, > years => @years, > }; > } [snip] > __DATA__ > 1|George|Washington|1788 1792 > 2|John|Adams|1796 > 3|Thomas|Jefferson|1800 1804 > 4|James|Madison|1808 1812 > 32|Franklin|Roosevelt|1932 1936 1940 1944 @years always contains exactly one element, it is a non-arrayish array. $years would work as well, and would avoid looking like it wouldn't work... -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site. |