From jvanslyk at matchlogic.com Mon Jun 18 09:57:36 2001 From: jvanslyk at matchlogic.com (Jason Van Slyke) Date: Wed Aug 4 23:58:33 2004 Subject: [boulder.pm] good book Message-ID: <5FE9B713CCCDD311A03400508B8B30130AB7F839@bdr-xcln.corp.matchlogic.com> Just got my hands on a copy of "Debugging Perl" by Martin Brown. Read over 200 pages this weekend (I wasn't feeling well and was pretty much house bound, sssoooo :| . Some 1st ed "bugs" in the book, but good form and informative in my opinion. Has anyone gotten into the "Perl Debugged" book yet? jvs Jason Van Slyke Sr. Performance Analyst MatchLogic/SAS Site Representative MatchLogic Inc (303) 222-7434 alpha pager: pagejvanslyk@matchlogic.com From Robert.L.Harris at rdlg.net Mon Jun 18 10:49:48 2001 From: Robert.L.Harris at rdlg.net (Robert L. Harris) Date: Wed Aug 4 23:58:33 2004 Subject: [boulder.pm] next in a for loop? Message-ID: <20010618094948.E26975@rdlg.net> @content is the result of a get($url) which is populated correctly. I have this: foreach $i (@content) { next if ($i =~ /^$/); print "\$i :$i:\n"; } In theory, if $i is empty ( i.e. "") it should skip to the next iteration. I've also done a 'next $i if ($i eq "");' and a number of combinations of those 2. It doesn't correctly skip the print statement. The print statement is just an exampla, I actually have a good bit of processing so I cant just say "print if ($i ne ""); or such... How do I get it to go to the next iteration of the loop if $i is empty? :wq! --------------------------------------------------------------------------- Robert L. Harris | Micros~1 : Senior System Engineer | For when quality, reliability at RnD Consulting | and security just aren't \_ that important! DISCLAIMER: These are MY OPINIONS ALONE. I speak for no-one else. FYI: perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);' From petek at bsod.net Mon Jun 18 11:09:28 2001 From: petek at bsod.net (Pete Krawczyk) Date: Wed Aug 4 23:58:33 2004 Subject: [boulder.pm] next in a for loop? In-Reply-To: <20010618094948.E26975@rdlg.net> Message-ID: Date: Mon, 18 Jun 2001 09:49:48 -0600 From: Robert L. Harris Subject: [boulder.pm] next in a for loop? } foreach $i (@content) { } next if ($i =~ /^$/); } print "\$i :$i:\n"; } } }How do I get it to go to the next iteration of the loop if $i is empty? The problem being that $i probably isn't empty. Remember, if $i contains "\n", that's sufficient to make it not do the next. So, first and foremost, I'd throw in a "chomp($i);" to the top of the loop. Next, in your debugging, what's between the colons? If it's nothing (i.e. it says "$i ::"), then there may be a problem between the next and print which is incorrectly editing $i. Try putting that print immediately after the next. And if you really, really want to make absolutely sure that the next goes with the foreach, you can always do: UGLYLOOP: foreach my $i (@content) { next UGLYLOOP if $i =~ /^$/; ... } (As an aside, that's why if I don't need blank lines, I generally write that statement as "next if $i =~ /^\s*$/;".) -Pete K -- Pete Krawczyk petek at bsod dot net http://www.bsod.net/~petek/ From jsimoni at totalsite.com Mon Jun 18 22:50:44 2001 From: jsimoni at totalsite.com (skazat) Date: Wed Aug 4 23:58:33 2004 Subject: [boulder.pm] next in a for loop? In-Reply-To: <20010618094948.E26975@rdlg.net> Message-ID: I think you have the next block thingy mixed up, the way you have it written, next if ($i =~ /^$/); This will skip whatever $_ is on if it actually does have a value, instead, just say: next unless ($i =~ /^$/); or next if ($i !~/^$/); you may just be able to simplify it and say: next if(!$i); which is nicer and can be easilly read as 'next if no $i' -- justin simoni! http://skazat.com ___________________________________________________________________ We NEVER clean the toilet, Neil! That's what being a student is all about! No way, Harpic! No way, Dot! All that Blue Loo scene is for squares. One thing's for sure, Neil. When Cliff Richard wrote "Wired for Sound", no way was he sitting on a clean lavatory! He was living on the limit, just like me. Where the only place to put bleach is in your hair! -Rick, from "the Young Ones" On 6/18/01 9:49 AM, "Robert L. Harris" wrote: > > > @content is the result of a get($url) which is populated correctly. > > I have this: > > > foreach $i (@content) { > next if ($i =~ /^$/); > > print "\$i :$i:\n"; > > } > > > In theory, if $i is empty ( i.e. "") it should skip to the next iteration. > I've also done a 'next $i if ($i eq "");' and a number of combinations > of those 2. It doesn't correctly skip the print statement. The print > statement is just an exampla, I actually have a good bit of processing so > I cant just say "print if ($i ne ""); or such... > > How do I get it to go to the next iteration of the loop if $i is empty? > > > :wq! > --------------------------------------------------------------------------- > Robert L. Harris | Micros~1 : > Senior System Engineer | For when quality, reliability > at RnD Consulting | and security just aren't > \_ that important! > DISCLAIMER: > These are MY OPINIONS ALONE. I speak for no-one else. > FYI: > perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);' > > From petek at bsod.net Tue Jun 19 09:44:00 2001 From: petek at bsod.net (Pete Krawczyk) Date: Wed Aug 4 23:58:33 2004 Subject: [boulder.pm] next in a for loop? In-Reply-To: Message-ID: Date: Mon, 18 Jun 2001 21:50:44 -0600 From: skazat Subject: Re: [boulder.pm] next in a for loop? }This will skip whatever $_ is on if it actually does have a value, instead, }just say: } } next unless ($i =~ /^$/); No. That says, "go back to the top of the loop unless $i is empty". The point is that it was processing when $i was empty, and it shouldn't. -Pete K -- Pete Krawczyk petek at bsod dot net http://www.bsod.net/~petek/