So I'm writing a small program to read a file and print to the screen. The file, called abbrevs.abr, is a text file with the following lines of text:
United States,US Poland,PL United Kingdom,UK Canada,CA
My code is as follows:
#!/usr/bin/perl -w
print "What is the filename? ";
$filename = <STDIN>;
# load abbreviations
open(ABBR, $filename) || die ("Could not open file.");
@raw_data = <ABBR>;
close(ABBR);
print "The abbreviation list:\n";
foreach $abbreviation (@raw_data) {
chomp($abbreviation);
($fullname, $abbrev) = split(/,/, $abbreviation);
print "$fullname abbreviates to $abbrev\n";
}
What it should do is print a series of lines that says something like "United States abbreviates to US" and so forth.
It doesn't.
It properly prompts for the filename, the file is in the same folder as the .pl file, it prints "The abbreviation list:" and then finishes. No errors, no nothing.
It's probably a very stupid little error, since I'm trying to teach myself this language out of a book that's 15 years old and the internet.
I also tried this, just to straight out print the information from the file:
#!/usr/bin/perl -w
print "What is the filename? ";
$filename = <STDIN>;
# load abbreviations
open(ABBR, $filename);
print "The abbreviation list:\n";
while (<ABBR>) {
chomp;
print "Line: $_\n";
}
That gave the same result as the other. What am I doing wrong? Since I'm running Xubuntu, I thought maybe I'd have to run it as root/sudo, but that made no difference either.
Thanks in advance,
Mila
This post has been edited by Mila: 29 October 2009 - 07:42 PM

New Topic/Question
Reply



MultiQuote





|