Johnno wrote: > I have a data field listed below. > > "data1","data2","data3","data4","data5","data6","data7 ","data8" > > open (data,"data.txt") || die; > while (<data>) { > > this is where I run into problems... > > I am wanting do the following.. > > split up the data after every , and then remove the " and store it as > $data[1] = data1 etc... > > but i have more than one line of data.. > > so I think when it get the 2nd line of data is might have to save it as > $data[9] = data1 > > once all the data is stored the file will close > > then I can print out the data that i want and leave the rest.. just getting > the data loaded and shorted in causing a little problem... > > can anyone help please??
Your description is a but cryptic. If your file is just a couple of lines, I would slurp it into a string and split it on , + WS. my $lines; { local $/ = undef; # drop input line separator and slurp file open IN, 'data.txt' or die ... $lines = <IN>; close IN; } # now just split the lines into an array my @data = split /\s*,\s*/, $lines; You should have a comma at the end of each line or you will need to change your split to use WS instead of ',' or allow either. EG: my @data = split /\s*(,\s*|\s+)/, $lines; # assumes WS always after a field if no , You could also try to deal with the "'s in the split, but you'll end up with some extra fields with just " in them. EG: my @data = split /"\s*,?\s*"/, $lines; # would need cleanup on ends of array So I would leave them and drop them later when I went to use the data - EG: $datum = $data[$n]; # get an item $datum =~ s/^"//; $datum =~ /"$//; # remove "'s -- ,-/- __ _ _ $Bill Luebkert ICQ=14439852 (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl) -/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/ _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs