oldcity has asked for the wisdom of the Perl Monks concerning the following question:
Using Ubuntu 18.04 the default perl. Have tried to understand this code but not getting expected results. Any help please. tia oldcity
########################################## sub OPEN_200R { open(FILE, '<', 'CATAGORIES.DAT') or die("Could not open* file! +CATAGORIES DAT\n"); @lines = <FILE>; close(FILE); $gcnt = 0; foreach (@lines) { ($catg) = (split(/,/)); $gcnt = $gcnt + 1; chomp $catg; $catg[$gcnt] = $catg; if ($gcnt <= 5) { $catlgs5 = join '', $catg[$gcnt]; }elsif ($gcnt >= 6){ $catlgs6 = join '', $catg[$gcnt]; } # end of if gcnt print ("$catlgs5"); print ("$catlgs6 \n"); # chomp $catg; } # end of foreach at 200r # { ##########################################
Not results Expected. 1-AT&T 2-FP&L 3-WATER 4-GAS 5-PLAN-D 5-PLAN-D 6-AARP 5-PLAN-D 7-DIAZ 5-PLAN-D 8-DRUGS 5-PLAN-D 9-HOUSE 5-PLAN-D10-CAR 5-PLAN-D11-MISC
Had expected 2 rows 1 of 5 catgs and 1 of 6 catgs. How to fix?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected Results
by Athanasius (Archbishop) on Nov 13, 2018 at 03:05 UTC | |
|
Re: Unexpected Results
by ikegami (Patriarch) on Nov 13, 2018 at 02:32 UTC | |
by oldcity (Novice) on Nov 13, 2018 at 16:20 UTC | |
by ikegami (Patriarch) on Nov 14, 2018 at 03:16 UTC | |
|
Re: Unexpected Results
by Laurent_R (Canon) on Nov 13, 2018 at 20:14 UTC |