perl - Read from CSV file into array, parse through array, access second element of each line -
i'm extremely new programming in perl, , new programming world in general.
i'm trying write program opens csv file, reads array, , parses through using split().
each field of csv file contains 4 things:
$full_name, $user_name, $password, $con_password
my problem need access second element of each line (user_name). need put user names array can work that.
i've done split, don't know how make sure second element of each line.
this have:
#!/usr/bin/perl use cgi qw(:standard); use strict; use warnings; print "content-type: text/html\n\n"; $file = '/home/2014/amosqu/public_html/cgi-bin/members.csv'; open(my $csv, '>>', $file) or die "could not open '$file' $!"; #i these values form in html file $full_name = param('full_name'); $user_name = param('user_name'); $password = param('password'); $con_password = param('con_password'); #array store user names @users = (); while(my $lines = <$csv>) { chomp $lines; @fields = split(/,/, $lines); } #access second element , put @users ???
you need write this...
my @list; open (my $csv, '<', $file) || die "cant open"; foreach (<$csv>) { chomp; @fields = split(/\,/); push @list, $fields[1]; }
in code file opened appending not reading.
Comments
Post a Comment