Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Use of uninitialized value in division (/) /admin/Links/Import/S2BK.pm line 121.

Quote Reply
Use of uninitialized value in division (/) /admin/Links/Import/S2BK.pm line 121.
Hi,

I'm getting this error when I build (Glinks 3.1.0):

Code:
Creating backup file ...
Use of uninitialized value in division (/) at /home/qango/public_html/cgi-local/dir/admin/Links/Import/S2BK.pm line 121.
Use of uninitialized value in division (/) at /home/qango/public_html/cgi-local/dir/admin/Links/Import/S2BK.pm line 121.



Here's the whole sub from S2BK.pm with line 121 highlighted in red:

Code:


sub import {
my $opt = shift;
return if ref $opt ne 'HASH';
{
my $warning = shift;
return if ref $warning ne 'CODE';
$Warning_Code = $warning;
my $critical = shift;
return if ref $critical ne 'CODE';
$Critical_Code = $critical;
my $mild = shift;
$Mild_Code = $mild if ref $mild eq 'CODE';
my $output = shift;
$Print_Out = $output if ref $output eq 'CODE';
}
my $DB = new GT::SQL(def_path => $$opt{source}, subclass => 0);
my $prefix = $DB->prefix || "";
my $delimiter = $$opt{delimiter};
critical "Invalid delimiter `".(defined$delimiter?$delimiter:'')."' for a delimited file!"
unless defined $delimiter and length $delimiter == 1 and $delimiter ne '\\';
my @tables;
opendir (D, "$CFG->{admin_root_path}/defs") or critical "unable to opendir $CFG->{admin_root_path}/defs ($!)";
while (defined (my $def = readdir(D))) {
next if ($def =~ /^\.\.?$/);
$def =~ s,\.def$,,;
next if ($def =~ /Word_List$/);
next if ($def =~ /Score_List$/);
push @tables, $def;
}
if ($prefix) {
@tables = grep { $_ =~ /^$prefix/ and s/^$prefix// } @tables;
}
local ($,,$\,*EXPORT_FH);
open EXPORT_FH, "> $$opt{destination}" or critical "Unable to open $$opt{destination} for writing: $!";
binmode EXPORT_FH; # this is NOT a text file.
print EXPORT_FH "Links SQL 2 backup. This backup was generated at " . gmtime() . " UTC. THIS FILE IS NOT A TEXT FILE. You should NOT attempt to edit this file as you will end up corrupting the data contained in it.\0";
=pod
Schematic for the file:
- Newline delimiter is changed to \0 (hex and ascii 0).
- Each line starting with '\\\\' starts off a new table.
- The first line following the '\\\\' is the table name by itself (NOT prefixed).
- The first character of the line after that is the delimiter for that table, and
the rest of that line is the columns of the table delimited by the delimiter.
- All subsequent lines (until another '\\\\') are individual records.
- All fields (headers and records) are escaped where needed in '\\XX' format
(where 'XX' is the hexadecimal representation of the character).
- All lines until the first '\\\\' are treated as comments and are ignored.
- Everything following '\\\\' is treated as a comment and is ignored.
=cut
for my $t (@tables) {
import_print "Exporting $prefix$t ...\n";
print EXPORT_FH "\\\\ The following is table $t".($prefix ? " (from prefixed table $prefix$t)" : "")."\0";
print EXPORT_FH "$t\0";
my $table = $DB->table($t);
print EXPORT_FH $delimiter; # The first character on this line is the delimiter
local ($a,$b);
print EXPORT_FH join($delimiter, sort { $table->{schema}{cols}{$a}{pos} <=> $table->{schema}{cols}{$b}{pos} } map BK_escape($_,$delimiter), keys %{$table->cols}),"\0";
my $count = $table->count;
my $sth;
my $printed = 0;
for my $i (0 .. $count/1000) {
$sth = $table->prepare("SELECT * FROM $prefix$t LIMIT ".($i * 1000).", 1000") or critical "Unable to prepare query `SELECT * FROM $prefix$t LIMIT ".($i * 1000).", 1000': ".$sth->errstr;
$sth->execute();
while (my $row = $sth->fetchrow_arrayref) {
print EXPORT_FH join($delimiter, map BK_escape($_,$delimiter), @$row),"\0";
unless (++$printed % 500) {
import_print "$printed records from $prefix$t exported ...\n";
}
}
}
import_print "$printed records from $prefix$t exported.\n",
"All records from $prefix$t have been exported.\n\n";
}
close EXPORT_FH;
}


I noticed this on another thread, but there was no resolution posted.

Any idea what's going wrong or how to fix it?

Cheers,
Shaun
Quote Reply
Re: [qango] Use of uninitialized value in division (/) /admin/Links/Import/S2BK.pm line 121. In reply to
You're getting that error when you perform a Build? Do you have a plugin installed that's performing some sort of import during a build?

Adrian
Quote Reply
Re: [brewt] Use of uninitialized value in division (/) /admin/Links/Import/S2BK.pm line 121. In reply to
Nope, no plugins installed at all. Here's the code from nph-build.cgi:


Code:
sub _build_backup {
# ------------------------------------------------------------------
# Create a backup file in our backup directory.
#
if (! $CFG->{build_use_backup}) {
print "Creating backup file... skipped\n\n";
return;
}
_time_start();
print "Creating backup file...\n";
require Links::Import::S2BK; my $max_keep = 7;
my $root = $CFG->{admin_root_path} . '/backup';
my $filename = 'BACKUP'; for my $n (reverse 0 .. $max_keep) {
my $oldname = join '.', $filename, $n || ();
my $newname = join '.', $filename, $n+1;
if (-e "$root/$oldname") {
rename "$root/$oldname", "$root/$newname" or print "\tCouldn't rename '$root/$oldname' -> '$root/$newname': $!";
}
}
Links::Import::S2BK::import({ source => "$CFG->{admin_root_path}/defs", destination => "$root/$filename", delimiter => "\t" }, sub { print "\n\tWARNING: @_\n" }, sub { die @_ }, sub { print "\n\tWARNING: @_\n" }, sub { });
_display_time();
}



Cheers,
Shaun
Quote Reply
Re: [qango] Use of uninitialized value in division (/) /admin/Links/Import/S2BK.pm line 121. In reply to
Is this just a "warning" or fatal error?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Use of uninitialized value in division (/) /admin/Links/Import/S2BK.pm line 121. In reply to
Not sure; I assume a warning since the backup files are created okay and it does carry on to do the build as expected.

Do you think it'd be safe to ignore it and carry on regardless? Smile

Cheers,
Shaun
Quote Reply
Re: [qango] Use of uninitialized value in division (/) /admin/Links/Import/S2BK.pm line 121. In reply to
In Reply To:
Not sure; I assume a warning since the backup files are created okay and it does carry on to do the build as expected.

Do you think it'd be safe to ignore it and carry on regardless? Smile

Cheers,
Shaun
Hi,

Well, as long as its not a fatal <G>

Obviously, if GT can fix this problem, then that would be ideal - but if it hasn't caused any problems thus far, I don't envisage it causing any headaches further down the line (I still can't believe people use static built files instead of dynamic <G>)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [qango] Use of uninitialized value in division (/) /admin/Links/Import/S2BK.pm line 121. In reply to
Ahh, I see. It's not a bad error, but it does mean that you have def files in your defs folder for tables that don't exist in the database.

Adrian
Quote Reply
Re: [brewt] Use of uninitialized value in division (/) /admin/Links/Import/S2BK.pm line 121. In reply to
In Reply To:
Ahh, I see. It's not a bad error, but it does mean that you have def files in your defs folder for tables that don't exist in the database.
Ah interesting, I'll have to remember thats what it means (I've seen it a couple of times before, I think in older versions). Thanks for the info :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [brewt] Use of uninitialized value in division (/) /admin/Links/Import/S2BK.pm line 121. In reply to
Adrian,

Thanks for explaining what it means.

I was just about to do a build, so I double-checked my .def files against my table list.

Sure enough, I found a table with no def (copied over from my previous V2 install), and a couple of .def files with no table (from a previous V2 plugin I had once tried-out).

Removed the extra table and .def files and now it builds without showing the error/warning Smile

Cheers,
Shaun