On Feb 4, John McKown said: >On Wed, 4 Feb 2004, Jeff 'japhy' Pinyan wrote: > >> > foreach $i (@grok) { >> > chomp($i); >> > >> >($item_num,$item_desc,$b1,$b2,$b3,$b4,$cc,$vn,$qoh,$qc,$qor,$bc,$sc,$yp) >> >= split(/\|/,$i); >> > print FILE >> >"$inv|$item_num|$item_desc|$b1|$b2|$b3|$b4|$cc|$vn|$qoh|$qc|$qor|$bc|$it >> >em_num|$sc|$yp\n"; >> > $inv++; >> > } >> >> Oh good God. Do you know what that for loop is DOING? >> That is terribly insane. > >Jeff, The input and output lines are not identical. The output line >prefixes $inv at the front and inserts $item_num between $bc and $sc. I >don't know why $item_num is repeated. Granted that I think a more >efficient construct might be:
Bah, I missed that. Then I'd use split(), but just use an array. while (<IN>) { local $" = "|"; my @fields = split /\|/; print OUT "$.|@fields[0..11,0,12..13]"; } But this begs the question, WHY does item_num have to be used TWICE in the SAME line of data. This smells of poor coding on the other side. It's still ugly. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>