Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenDir Question * Please Help!!!!

Status
Not open for further replies.

JRMS

MIS
Sep 4, 2003
144
US
Greetings. I am not an expert by any means. I have modified this script in order to parse data and insert into MySQL db. I have having problems with the OpenDir syntax. Any insight what the issue is, I would truly appreciate it.

#!/usr/lib/perl
use strict;
use DBI;

# Connect To Database
my $db = "DB";
my $dsn = "DBI:mysql:database=$db;host=localhost;port=3306;mysql_read_default_file=/etc/mysql/my.cnf";
my $user = "root";
my $pass = "Pwd";

my $dbh = DBI->connect($dsn,$user, $pass, {'RaiseError' => 1});

# Retrieve and open file
my $dir = "/home/Myfolder/"
my opendir(DIR,$dir) || die "Folder not found: $!";
@files = grep (/\.nbe$/, readdir(DIR));

while (my $file = readdir (DIR))
{
my $line = $_;
if ($line =~/results/) # Only pull results from the nbe file.
{
our @values = split (/\|/, $line);
# Only pull full results lines (not just posrtscan entries)

if ($values[5] ne '')
{
my $SQL = "INSERT INTO ScanResults SET IP=' ".$values[2]."',
Port='".$values[3]."', PluginID='".$values[4]."', Type='".$values[5]."',
Description=".$dbh->quote($values[6])."";

print "$SQL\n";

my $sth = $dbh->prepare($SQL) or die "Cannot prepare statement:
$DBI::errstr\n";

$sth->execute() or die "Cannot execute statement: $DBI::errstr\n";
$sth->finish();
}
}
}
$dbh->disconnect ();
close(DIR);

The Errors are as followings:

No such class opendir at ./nbeparser3a.pl line 15, near "my opendir"
syntax error at ./nbeparser3a.pl line 15, near "my opendir"
Global symbol "$dir" requires explicit package name at ./nbeparser3a.pl line 15.
Global symbol "@files" requires explicit package name at ./nbeparser3a.pl line 16.
Execution of ./nbeparser3a.pl aborted due to compilation errors.

Thanks!!
 
As posted on perlgurus:

Code:
# Retrieve and open file
my $dir = "/home/Myfolder/"[red];[/red] <--missing semi-colon 
[red]opendir[/red](DIR,$dir) || die "Folder not found: $!";
[red]my[/red] @files = grep (/\.nbe$/, readdir(DIR));

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top