For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > February 2006 > Printing An Array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Printing An Array
overkill@sadsix.com

2006-02-26, 9:56 pm

Currently I have my script print in a long list .csv file. I need to
print my long list into rows of 20 elements. How can I go about doing
this?

while ($x = <DATA> )
{

chop $x;
@arr = split /\s+/,$x;
$temp = @arr;
print "$arr[$temp -1],\n";

}

__DATA__
hostname01
Unknown
DL360 G3
M0PCLGP82F





Redhat_ES_3.0




Production


2.4.21-27.ELsmp
hostname03
Unknown
Netra X1











Production


117350-02
John W. Krahn

2006-02-26, 9:56 pm

overkill@six.com wrote:
> Currently I have my script print in a long list .csv file. I need to
> print my long list into rows of 20 elements. How can I go about doing
> this?
>
> while ($x = <DATA> )
> {
>
> chop $x;
> @arr = split /\s+/,$x;
> $temp = @arr;
> print "$arr[$temp -1],\n";
>
> }


Based on your data, this seems to work:

while ( <DATA> ) {
chomp;
print $_, $. % 18 ? ',' : ",,\n";
}



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com