Always: use strict; use warnings;
On Thu, Jun 19, 2008 at 6:10 AM, dakin999 <[EMAIL PROTECTED]> wrote: > Hi, > > I have following code which works ok. It does following: > > 1. reads data from a input file > 2. puts the data into seperate variables in a array > 3. reads from this array and prints out to another file __CODE__ open my $output, "> file" or die "Can't open file\n"; while (my $line = <DATA>) { chomp $line; my @array = split( ",", $line ); for my $item ( @array ) { print $output "$item\n"; } print $output "\n"; } __DATA__ yellow,blue,orange,red black,white,red,pink __CODE__ __OUTPUT__ yellow blue orange red black white red pink __OUTPUT__ Does that help? > while (<input>) #reading a line from file > # Read the line into a set of variables > ($1,$2,$3,$4)=split(/,/,$_); $1, $2, ... are reserved variables used for RegEx's. I'd advise against using them (or $a and $b - used in sort) as regular variables. > # Buid an array with these varaibles > my @array = ([$1, $2, $3, $4]); The [] brackets are used to look up an element in an array. I'm not sure what the intent or result here would be. > foreach my $r(@array) { > foreach (@$r){ Are you looping over the same data inside itself? Why the double loop? $r is a scalar. Why are you casting it to an array and looping over it? > ... print <out> "$1\n"; I hope you got something like: print $out "$var\n"; HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/