Re: Reading a comma delimited file into an array

2004-06-18 Thread Prasanna Kothari
Try this
%hashVal;
open(FH,"sample.txt")|| die "Could not open $!\n";
@FileLines = ;
$i=0;
foreach $line (@FileLines) {
  my @commaLines = split(/,/,$line);
  $arrval [EMAIL PROTECTED];
  $hashVal{$i} =$arrval;
  $i++;
}
foreach $keyval (keys %hashVal) {
  $ra_val = $hashVal{$keyval};
  foreach $value (@$ra_val) {
print "$value\n";
  }
}
[EMAIL PROTECTED] wrote:
Greetings,
As a learning Perl Person, this is fun.  Would someone please point me in the 
correct direction to read a comma delimited file and put it into an array?  
The fields are always in the same position, blank fields will have a comma.
My sample is:

header10,header11,,header13
header20,header21,header22,header23
header30,,header32,header33
I then need to format this data and an array looks like the easiest way of 
doing this.

Many thanks,
Richard Hug
 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Reading a comma delimited file into an array

2004-06-18 Thread David Dorward
On 18 Jun 2004, at 14:30, [EMAIL PROTECTED] wrote:
As a learning Perl Person, this is fun.  Would someone please point me 
in the
correct direction to read a comma delimited file and put it into an 
array?
http://search.cpan.org/~alancitt/Text-CSV-0.01/CSV.pm
http://search.cpan.org/~jwied/Text-CSV_XS-0.23/CSV_XS.pm

--
David Dorward
 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Reading a comma delimited file into an array

2004-06-18 Thread Sripathi Guruprasannaraj
On Fri, 18 Jun 2004 09:30:56 EDT, <[EMAIL PROTECTED]> wrote:
Greetings,
As a learning Perl Person, this is fun.  Would someone please point me  
in the
correct direction to read a comma delimited file and put it into an  
array?
The fields are always in the same position, blank fields will have a  
comma.
My sample is:

header10,header11,,header13
header20,header21,header22,header23
header30,,header32,header33
I then need to format this data and an array looks like the easiest way  
of
doing this.

Many thanks,
Richard Hug

Use the split function. Look up 'perldoc -f split ' to know more about the  
function.

To get started, try this,
open(FH,"File.dat") or die "Cannot open filed #!\n";
while() {
my @array = split(/,/,$_);
# do something with the array
}
Raj
--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]