Hi, I am prototyping a simple soap server in perl, and have run up against a problem accessing global variables. I would normally avoid them as much as I can, and pass variables, but in this circumstance I really don’t think I can. However, I can’t seem to access the global variable either. How would I do it? The code is below, in it the $count variable is the on I am playing with, and obviously, the code doesn’t actually do very much, but I just want to be able to access it. I have tried using my and the $Metaspace::count notation, but it just won’t work. Thanks in advance!
#!/usr/bin/perl -w
use SOAP::Transport::HTTP;
use XML::Parser;
SOAP::Transport::HTTP::CGI
->dispatch_to('Metaspace')
->handle;
package Metaspace;
$count = 0;
# snipped some irrelevant code
sub ls {
my ($class, $metas) = @_;
my $datadir = "data";
$return = 'listing files matching '.$metas.'<br />';
opendir(DIR, $datadir) or return "can't open $datadir: $!";
while (defined($file = readdir(DIR))){
if (check_metas("$datadir/$file", $metas)){
$return .= '<a href="'.$datadir.'/'.$file.'">'.$file.'</a><br />
+';
}
}
closedir(DIR);
return $return.$count;
}
sub check_metas {
my ($file, $metas) = @_;
return 0 unless -f $file;
my $parser = new XML::Parser(ErrorContext =>2);
$parser->setHandlers(Start => \&XML_start_handler,
Char => \&XML_char_handler);
$parser->parsefile($file);
return 1;
}
sub XML_start_handler {
$count++;
}
sub XML_char_handler {
$count++;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.