I am attempting to read a line from a single-line text file containing three numbers separated by commas. It would be like this:
40045,47250,400
I have been fussing with this for several days by trying different combinations I have found on the web. Below is what I have:
open(my $fn, '<', 'prgcfg.txt' or die "Could not open configuration file: '$fn' $!");
my $line = <$fn>;
chomp $line;
close $fn;
my ($n,$e,$g) = split /,/,$line[1];
The three scalars in the last line are declared above this. It always generates an error regardless of what I try. Any ideas?
Thank you!
Assuming your error and warning messages originated from
use strict; use warnings;
, you can eliminate them with the following changes:The parentheses for
open
are misplaced; in fact, you don't need them at all.$fn
is a file handle, not a file name. Do not try to print the handle in thedie
message.$line
is a scalar; don't try to access an element of it as if it were an array.