Click to See Complete Forum and Search --> : Running perl program which analyzes a text file


philophilous
08-13-2007, 04:21 PM
hello, I am having what seems like it should be a really simple problem with perl on xp. I am trying to run a program that I have written to count the lines, words and characters of a small text file but can't seem to get it running. I wrote the text file (sample.txt) in jEdit, saved it into the Perl directory, wrote the program (Counter1.pl) in jEdit, which opens the text file and does all the necessary processing, but in the command prompt when I enter:
c:\Perl>perl counter1.pl
I get:
Unknown warnings category 'sample.txt' at counter1.pl at line 10
BEGIN failed--compilation aborted at counter1.pl line 10

I am really green at this and would appreciate help. Thank you

dragle
08-13-2007, 05:14 PM
Hi!

My guess is that you're just attempting to use the warnings pragma in a way it wasn't intended; for example, you could trigger that error message with something like this:

no warnings 'sample.txt';

which attempts to disable all the warning messages within the category of warnings known as 'sample.txt.' But that category of warnings doesn't actually exist unless you specifically registered it; in which case, you would need to register it BEFORE you activate or disable it.

So, to answer your question more concretely, we'll need to see some more detail. Can you show us what code you've got so far?

philophilous
08-13-2007, 05:33 PM
OK, this is the first part of my program (I threw in line numbers for reference). I am under the understanding that on Windows I don't really need to have the sh-bang line in there, but it's in there anyway. This works fine with the 8th line commented out, but when I try to use warnings, I get the error. I can't run in with use strict either. Does this have something to do with lexical vs. global variables? What's going on? Thank you for your help. -Brent

1#!/usr/bin/perl -w
2#About this Program:
3#Name: Counter1.pl
4#Description: One way to count the characters, words, and lines in a text 5file.
6#Author: Brent West
7#Date: 13 August 2007
8use warnings
9#use strict
10
11#The name of the file that will be counted
12$TheFile = "sample.txt";
13
14#Open the file but quit if it doesn't exist
15open(INFILE, $TheFile) or die "The file $TheFile could not be found.\n";

dragle
08-14-2007, 09:16 AM
Your "use" statements are just like other perl statements, in that they must end with a semicolon; i.e.,
use strict;
use warnings;
etc. Try that and you should be able to move on. :)

Good luck!

philophilous
08-14-2007, 05:54 PM
I knew it was simple. I should have known better. Thank you for your help.