m m wrote:
>
> folks allow me, Im the other newbie who was grappling
> with Apache::NavBar the other day :-)
> Ged will be proud, I persevered as he advised ;-)
>
> Sam new to perl, welcome.
> This maynot be the canonically right answer but for a
> simple task like youre asking, you can just "warn"
> stuff to your error logs.
> so for example, (if I understood your initial request
> correctly) , this piece of code will show you the line
> you are reading from your configuration file and then
> the url,location match if any.
>
> while (<$fh>) {
> chomp;
> s/^\s+//; s/\s+$//; #fold leading and trailing
> whitespace
> next if /^#/ || /^$/; # skip comments and empty lines
> next unless my($url, $label) = /^(\S+)\s+(.+)/;
> warn "here is the line $_\n";
> if ( my($url,$label) = /^(\S+)\s+(.+)/ ) {
> warn "here are the matches $url, $label\n";
> } else {
> next;
> }
> push @c, $url; # keep the url in an ordered array
> $c{$url} = $label; # keep its label in a hash
> }
Well, I took your if statement and put cut/paste it into my code, things
still did not work. So I cut the NavBar object out of that file and put
it into a normal perl file. It works and here it is:
sub new {
my ($class,$conf_file) = @_;
my (@c,%c);
my $url;
my $label;
print "filename = [$conf_file]\n";
open fh, $conf_file or return;
while (<fh>) {
chomp;
s/^\s+//; s/\s+$//; #fold leading and trailing whitespace
next if /^#/ || /^$/; # skip comments and empty lines
# next unless my($url, $label) = /^(\S+)\s+(.+)/;
print "here is the line $_\n";
if ( ($url,$label) = /^(\S+)\s+(.+)/ ) {
print "here are the matches [$url], [$label]\n";
} else {
next;
}
print "url = [$url], label = [$label]\n";
push @c, $url; # keep the url in an ordered array
$c{$url} = $label; # keep its label in a hash
}
return bless {'urls' => \@c,
'labels' => \%c,
'modified' => (stat $conf_file)[9]}, $class;
}
Well, When I put a debug line right after the chomp of the mod_perl
code, using Apache::File to open the conf_file, it displays the whole
conf_file, not just one line. Any thoughs on how I read through the
conf_file one line at a time?
Sam