Re: Need help with a question.
- From: "Dan Mercer" <damercer@xxxxxxxxxxx>
- Date: Sat, 28 Jun 2008 12:02:11 -0500
"Trev" <trevor.dodds@xxxxxxxxx> wrote in message news:b1faad3b-49cb-4fc8-a65a-7b7ac82e9df5@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm having a problem with my Perl script, what I would like the script
to achieve is to read a file, search it for certain words, put the
results into an Array so I can then call each result with $var[1] etc
and print output to a file. I tried doing it without Sub routines but
wasn't able to split the results. When I rapped the code into a Sub I
get these errors:
syntax error at test.pl line 7, near "@cpqlog_data"
syntax error at test.pl line 24, near "}"
How come these errors only appear when I use Sub { } ?
test.pl
use English;
use Warnings;
Sub LoadFile
{
open (DAT, "<output.txt") || die("Could not open file!");
@cpqlog_data=<DAT>;
foreach $cpqlog (@cpqlog_data)
{
{
chomp($cpqlog);
if ($cpqlog =~ /MAC/)
{
$cpqlog =~ s/ <FIELD NAME="Subject" VALUE="//i;
$cpqlog =~ s/ <FIELD NAME="MAC" VALUE="//i;
$cpqlog =~ s/"\/>//i;
}
}
}
close DAT;
}
Sub CreateLOG
{
open (BOO, "<blah2.txt");
@lines=<TMP>;
print $lines[1];
close BOO;
}
LoadFile;
CreateLOG;
You're going to feel really dumb. I feel really dumb because it took me 5 minutes to figure out.
Perl is case sensitive. Sub should be sub. In fact, Sub is treated as the name of a subroutine
which cascades into all sorts of ugliness. Ironically, it's not something the syntax checker
is good at figuring out. BTW, in CreateLOG you open BOO and read TMP. You should also
consider "use strict;" which will help you find many syntax errors (just not this one). You can also
run "perl -c" against your script to just run the compiler pass. I have F4 set to do that in vim
so I can check for syntax errors as I write the code - saves enormous amounts of time and
energy.
Dan Mercer
.
- References:
- Need help with a question.
- From: Trev
- Need help with a question.
- Prev by Date: Re: Need help with a question.
- Next by Date: Re: Need help with a question.
- Previous by thread: Re: Need help with a question.
- Next by thread: Re: Need help with a question.
- Index(es):
Relevant Pages
|