Re: CSV munging and uninitialized values
On 12 Aug 2003, $Bill Luebkert wrote in perl: while (HITSFILE) { #open1 chomp; @line = split /,/, $_, -1; A slightly different approach: for (@line .. 41) { $line[$_] = ''; } I'm not certain exactly what this does -- to me, it looks as though it should set every member of the array to an empty string. That's something I definitely don't want. Or are you suggesting that the empty string declarations ought to go after the check for definedness below? for $y (1 .. 41) { #open2 this deals with empty cells unless (defined $line[$y]) { Also, later on I'm going to need to access another set of array members that don't start with element 1 of the array. Are you suggesting something like for (@line .. 43 .. 83) { would work? This is why I declared a $y -- so that I could more easily set it in the for loops to whatever I need, and it seems better to me to have more uniform code if possible. It's bad enough that I have to post my ugly, inefficient code here for you experts. But at least I'm not reposonsible for any code that *other* people are going to be using. ;-) -- Ted Schuerzinger Homer Simpson: I'm sorry Marge, but sometimes I think we're the worst family in town. Marge: Maybe we should move to a larger community. http://www.snpp.com/episodes/7G04.html ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: CSV munging and uninitialized values
$Bill Luebkert wrote: for (@line .. 41) { $line[$_] = ''; } I've seen this use of .. only a few times before and don't really know what it's all about. I don't even know what to look for in the Llama book - them two dots? Terry Fowler ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: CSV munging and uninitialized values
Terry Fowler wrote: $Bill Luebkert wrote: for (@line .. 41) { $line[$_] = ''; } I've seen this use of .. only a few times before and don't really know what it's all about. I don't even know what to look for in the Llama book - them two dots? Terry Fowler range operator. In the Camel ed 3, it is discussed on p 103. While its use is straightforward in list context, its behavior in scalar context surprises me. Will Woodhull [EMAIL PROTECTED] ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: CSV munging and uninitialized values
=== #! perl -w use strict; # declare an array my @line = (); # fill in some values $line[0] = a name; # first location $line[3] = 9; # fourth location $line[9] = 15;# tenth location my $length = @line; # number of members in the array; print Length of array line is: $length\n; # now test each member print testing each member of the line array\n; my $i; for ($i = 0; $i $length; $i++) { print Array member $i contains \$line[$i]\\n; } print testing each member of line array that has been initialized\n; for ($i = 0; $i $length; $i++) { print Array member $i contains \$line[$i]\\n if defined $line[$i]; } print now test each and beyond but ensure that the member is initialized\n; for ($i = 0; $i $length + 5; $i++) { $line[$i] = unless defined $line[$i]; print Array member $i contains \$line[$i]\\n; } == - Original Message - From: Terry Fowler [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 1:02 PM Subject: Re: CSV munging and uninitialized values $Bill Luebkert wrote: for (@line .. 41) { $line[$_] = ''; } I've seen this use of .. only a few times before and don't really know what it's all about. I don't even know what to look for in the Llama book - them two dots? Terry Fowler ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: CSV munging and uninitialized values
Ted S. wrote: On 11 Aug 2003, Keith Ivey wrote in perl: Ted Schuerzinger [EMAIL PROTECTED] wrote: @line = split /\,/; In the documentation for split() it says By default, empty leading fields are preserved, and empty trailing ones are deleted. You want to preserve the empty trailing fields, so you need to use the third argument (and to use the third, you have to specify the second): @line = split /,/, $_, -1; Also note that commas are not special in regular expressions, to there's no need to escape them. Sorry, but I'm still getting the uninitialized value warnings. The offending code is now: snip while (HITSFILE) { #open1 chomp; @line = split /,/, $_, -1; A slightly different approach: for (@line .. 41) { $line[$_] = ''; } for $y (1 .. 41) { #open2 this deals with empty cells unless (defined $line[$y]) { # open3 -- somebody else suggested # changing exists to defined. Both give # the error message. $line[$y] = ; } #close3 if ($line[$y] =~/\d/) { #open4 $hash{$line[0]}{ratings}[$y]=$line[$y]; } #close4 }#close2 for $y (1 .. 41) { #open5 if ($hash{$line[0]}{ratings}[$y] =~/\d/) { #open6 $hash{$line[0]}{ratingstotal}=$hash{$line[0]}{ratingstotal}+$hash{$ line[0]}{ratings}[$y]; } #close6 } #close5 ... /snip The warnings still come on the pattern match. -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: CSV munging and uninitialized values
$Bill Luebkert wrote: Perlop man page - Range operator. Yes, that's it. Thanks. I combine all the manpages and make it easy to search for '/ \.\. /' (script on my Tripod site). No need to look it up in a book or try to figure out the name and only 3MB. This has been on my list of things to do for, literally, a couple of years now. I finally did it and have a copy on my laptop and a copy on my Sun Ultra now. Thanks again! Terry ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: CSV munging and uninitialized values
Terry, look for range operators. Important to note that .. differs from .. returns true is both tests are true. ... doesn't return true if both tests are true. You can use them with patterns or line numbers. Cheers, Carter. -Original Message- From: Terry Fowler [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 12, 2003 10:03 AM Cc: [EMAIL PROTECTED] Subject: Re: CSV munging and uninitialized values $Bill Luebkert wrote: for (@line .. 41) { $line[$_] = ''; } I've seen this use of .. only a few times before and don't really know what it's all about. I don't even know what to look for in the Llama book - them two dots? Terry Fowler ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: CSV munging and uninitialized values
Ted Schuerzinger [EMAIL PROTECTED] wrote: @line = split /\,/; In the documentation for split() it says By default, empty leading fields are preserved, and empty trailing ones are deleted. You want to preserve the empty trailing fields, so you need to use the third argument (and to use the third, you have to specify the second): @line = split /,/, $_, -1; Also note that commas are not special in regular expressions, to there's no need to escape them. -- Keith C. Ivey [EMAIL PROTECTED] Washington, DC ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs