Need help with a question.



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;
.



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)
  • Finding all the links in a Unix file/directory path
    ... I am working on a Perl script that copies files from a log file. ... I have attached a DirGen.pm that creates the sample directory ... my $work_dir = shift; ... sub generate_test_hier_ { ...
    (comp.lang.perl.misc)
  • Re: how to edit a batch file
    ... del test.log ... I have written a perl script to edit some of the lines. ... Is there a specific reason why you are calling the sub this way? ... based on the code fragments that you showed this should replace the ...
    (comp.lang.perl.misc)
  • Re: Need help with a question.
    ... When I rapped the code into a Sub I ... syntax error at test.pl line 7, ... I feel really dumb because it took me 5 minutes to figure out. ... Perl is case sensitive. ...
    (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)