Alex Brelsfoard wrote:
> sub main {
> my $catalog_timestamp;
[...]
> my $catalog_settings = XML::Twig->new(
> twig_handlers => {
> 'Item' => \&get_catalog_field_names,
> 'Catalog' => \&get_catalog_timestamp,
> }
> );
[...]
> 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.
As per the error message ;--) $catalog_timestamp is in scope in the main
sub, but not in the rest of the file.
2 options: make it global to the file by declaring it outside of the
main sub, or (cleaner), pass it to the handler via a closure:
my $catalog_settings= XML::Twig->new(
twig_handlers => {
'Item' => sub { get_catalog_field_names( @_, $catalog_timestamp); }
...
sub get_catalog_timestamp {
my ($twig, $elt, $catalog_timestamp) = @_;
...
Does this help?
--
mirod
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm