I know how to use and maintain .txt data files with two or more fields. I want to learn how to use just one field so I can do away with the $nothing field which... does nothing. I just use it so the data file will have two fields separated with a comma (The only way I know to work it). My name.txt file consists of:
name1,
name2,
name3,
nameetc,
This is the code to read the name.txt file.
name1,
name2,
name3,
nameetc,
This is the code to read the name.txt file.
Code:
#!/usr/bin/perl -w
my ($nothing, $name, @records, $rec);
open (INFILE, "<", "name.txt");
@records = <INFILE>;
close(INFILE);
foreach $rec (@records) {
chomp ($rec);
($name, $nothing) = split(/,/, $rec);
print "$name <br>\n";
}