I'll take a whack at this: At 08:19 11.22.2001 +0800, Harry Varvarigos wrote: > I am trying to count the no. of blanks that appear and then break out of the >loop when all arrays' last elements are blanks/spaces. I think sprintf >will do it but I can't figure it out: > >printf >DGSUM" +--------------------------------------------------------+\n"; > > for $sr(1 ..9) > { > $one = ""; > > if($place1[$sr] eq ""){ > printf DGSUM " | %d | N/A |",$sr; > $one = "mt"; > }else{ > printf DGSUM " | %d | %9s | ",$sr, $cwdp[$sr]; > } > > if($place2[$sr] ne ""){ > if($one eq "mt"){ > printf DGSUM " %9s |", $place2[$sr]; > }else{ > printf DGSUM " %9s |", $place2[$sr]; #data > in so print to screen > } > }else{ > printf DGSUM " N/A |"; > } > > if($place3[$sr] eq ""){ > $one = "mt"; > printf DGSUM " N/A |"; > }else{ > printf DGSUM " %9s |", $place3[$sr]; > > } > > if($place4[$sr] ne "" ){ > printf DGSUM " %9s |\n",$place4[$sr]; > }else{ > if($one ne "mt"){ > printf DGSUM " %9s |\n", $place4[$sr]; > }else{ > printf DGSUM " N/A |\n"; > #printf DGSUM "place4=%s\n",$place4[$sr++]; > } > > #printf DGSUM "place4=%s\n",$place4[$sr++]; > #if (($place1[$sr++] eq "") && ($place2[$sr++] eq "") && > ($place3[$sr++] eq "") && ($place4[$sr++] eq "")){ > #break;}
I see that you tried to use simple if-then-else to solve your problem. I believe that that was failing because you were doing an exact match of $place[$sr] to be equal to "" (nothing) but you've already explained above that actually, you are looking for white space and "nothing" != white space. Ok. So, I will hit this at three angles. 1. Lets consider hitting this from the angle you tried above? I would change the condition like so: if ( $place[$sr++] =~ /\s|\s+/ ) { ... } 2. The way I probably would have come at this (and I am still not clear on everything but consider that I am now going about your whole project at a very different angle than you went using printf) is by actually throwing every line of output from gateway into a byte-by-byte check for-loop 3. splitting my output into the four fields (place1-4[$sr]) would actually be a multidimensional array and I would have checked each array element to be equal to nothing but whitespace using the same kind of condition I mentioned in 1. >} > >each $place1[$sr] , $place2[$sr] , $place3[$sr], $place4[$sr] is a >dial-in gateway. I go through each gateway, pluck out its call stats and >print them out. If there's no gateway, I print N/A (that is there are 3 >gw's per site except for the last one that has 5 gw's, therefore the other >3 gateway's for their row 4 +5 have N/A beside them here's the output: > >+--------------------------------------------------------+ > | Daily Dial Gateway Call Totals | > | for 14 11 2001 | > +--------------------------------------------------------+ > > +--------------------------------------------------------+ > | DG # | Place1 | Place2 | Place3 | Place4 | > +--------------------------------------------------------+ > | 1 | 83018 | 66848 | 87005 | 62313 | > | 2 | 76762 | 66734 | 87000 | 62260 | > | 3 | 59572 | 57035 | 74555 | 53402 | > | 4 | N/A | N/A | N/A | 0 | > | 5 | N/A | N/A | N/A | 0 | > | 6 | N/A | N/A | N/A | N/A | > +--------------------------------------------------------+ > |Total | 219352 | 190617 | 248560 | 177975 | > +--------------------------------------------------------+ > > +--------------------------------------------------------+ > | Grand Total | 836504 | > +--------------------------------------------------------+ > >I am trying to prevent the last row of N/A from appearing as there is no >gateway 6 therefore the rows should stop at >row 5 and row 6 should not appear. I have been at this for a while and >can't work out how to do this with sprintf > >any ideas ? thanks in advance > >Harry >-- > >_______________________________________________ >Sign-up for your own FREE Personalized E-mail at Mail.com >http://www.mail.com/?sr=signup > > >1 cent a minute calls anywhere in the U.S.! > >http://www.getpennytalk.com/cgi-bin/adforward.cgi?p_key=RG9853KJ&url=http://www.getpennytalk.com > > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] - Jim -~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~- http://www.perlmonks.org/index.pl?node_id=67861&lastnode_id=67861 -----BEGIN PERL GEEK CODE BLOCK----- ------BEGIN GEEK CODE BLOCK------ Version: 0.01 Version: 3.12 P++>*@$c?P6?R+++>++++@$M GIT/CM/J d++(--) s++:++ a- >++++$O!MA->++++E!> PU-->+++BD C++++(+) UB++++$L++++$S++++$ $C-@D!>++++(-)$S++++@$X?WP+>++++MO!>+++ P++(+)>+++++ L+++(++++)>+++++$ !E* +PP+++>++++n-CO?PO!o >++++G W++(+++) N+ o !K w--- PS---(-)@ PE >*(!)$A-->++++@$Ee---(-)Ev++uL++>*@$uB+ Y+>+++ PGP t+(+++)>+++@ 5- X++ R@ >*@$uS+>*@$uH+uo+w-@$m! tv+ b? DI-(+++) D+++(++) G(++++) ------END PERL GEEK CODE BLOCK------ ------END GEEK CODE BLOCK------ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]