Re: Need help with a question.



"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

.



Relevant Pages

  • Re: Need help with a question.
    ... When I rapped the code into a Sub I ... syntax error at test.pl line 7, ... If you use GNUish indenting, and such a large indent, you'll quickly run ... We do not stop playing because we grow old; ...
    (comp.lang.perl.misc)
  • Re: Syntax error in INSERT INTO statement.
    ... It looks like you're trying to concatenate fields together. ... execute this INSERT. ... > End Sub ... > Exception Details: System.Data.OleDb.OleDbException: Syntax error in> INSERT INTO statement. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Strange syntax error
    ... I get a syntax error I can't explain. ... sub openFile() ... Removing or commenting the openFile sub. ... the Switch module uses a source filter to do its thing. ...
    (comp.lang.perl.misc)
  • Re: Strange syntax error
    ... I get a syntax error I can't explain. ... sub openFile() ... Removing or commenting the openFile sub. ... Switch seems to be incompatible with mod_perl under ...
    (comp.lang.perl.misc)
  • [tip:perf/scripting] perf trace: Add perf trace scripting support modules for Perl
    ... Add Perf-Trace-Util Perl module and some scripts that use it. ... new file mode 100644 ... +GNU General Public License version 2 as published by the Free ... +sub define_flag_field ...
    (Linux-Kernel)