T
Trev
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;
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;