Hi all,

I'm trying to do something I see as relatively simple.
I would like to call a function that declares a few variables and then runs
some XML::Twig processes which in turn access & update said original
variables.
But I'm getting an error from my twig functions when they try to access the
before-defined variables.

Right now my code is looking a little something like:

main();

sub main {
        my $catalog_timestamp;
        my $objinfo_timestamp;
        my %fields;
        
        open(my $cataloginfo_fh, "catalog.xml") || die "Could not open
catalog.xml for reading: $!\n";
        open(my $objinfo_fh, "objinfo.xml") || die "Could not open
objinfo.xml for reading: $!\n";
        open(my $new_fh, ">output.csv") || die "could not write to 
output.csv\n";

        # Need to get the header info first, to be able to make the haeder line.
        # Only go hrough the file if something was submit for that file.
        if (defined $cataloginfo_fh) {
                my $catalog_settings = XML::Twig->new(
                    twig_handlers => {
                        'Item'    => \&get_catalog_field_names,
                        'Catalog' => \&get_catalog_timestamp,
                    }
                );
                $catalog_settings->parse($cataloginfo_fh);
        }

        if (defined $objinfo_fh) {
                my $objinfo_settings = XML::Twig->new(
                    twig_handlers => {
                        'Product'  => \&get_objinfo_field_names,
                        'Published' => \&get_objinfo_timestamp,
                    }
                );
                $objinfo_settings->parse($objinfo_fh);
        }
        close($cataloginfo_fh);
        close($objinfo_fh);
        close($new_fh);
}


An example of the twig functions:

sub get_catalog_timestamp {
        my ($twig, $elt) = @_;

        # get the PublishTimeStamp attribute
        $catalog_timestamp = $elt->att('PublishTimestamp');

        $twig->purge();
}



However I get an error from this.
"Global symbol "$catalog_timestamp" requires explicit package name"
The error references the "$catalog_timestamp =
$elt->att('PublishTimestamp');" line.

I kind of get the feeling I'm doing a stupid perl mistake.
But I clearly do not know what.
Any help would be very much appreciated.

thanks.
--Alex
 
_______________________________________________
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to