Hey Sam,
humm, I tested my code before sending it to you, it
was working on my machine, ..., but lets see.
oh wait ok, you said that when you put a debug line
right after the chomp, that debug output shows you the
entire conf_file? Oh ok I think I know what is going
on then. Its the line with the Perl $/ variable, thats
most probably whats causing this behaviour.

The Perl $/ is the input record separator. It is
newline by default. So when you are reading in a file,
with an idiom like while(<file_handle>) it will
recognize each line as being well a new, line.
In the NavBar code, in the handler subroutine,
the line
local($/) = "";
sets $/ to nothing, since there is nothing between the
double quotes. With this, in the next statement after
the local statement, when you say while(<$fh>) since
the input record separator is not defined, it slurps
the entire file at once. So that in the next statement
where you do the substitution, you are doing it on the
default variable $_, which contains the entire slurped
in file. 
The behavior you are describing implies to me, that
the input record separator is still nothing and thats
why the configuration file is being slurped in at once
too, thats why your line output after the chomp shows
you the entire file. So either you forgot to put a 
local around your definition of $/ in the handler
routine, or if for some real bizarre scoping reason $/
is still being recognized as "nothing" in your NavBar
new routine, you can redeclare something like this:
see code insertion below. And that should do the
trick,
but the right thing to do is to figure out why $/ is
behaving like this in your NavBar new routine.
You might also want to just get the code for the book
from the Eagle books website www.modperl.com and use
the NavBar.pm from their to see how that code behaves,
and that might help you figure out whats different
between your NavBar.pm and tried and tested one.



> sub new {
>     my ($class,$conf_file) = @_;
>     my (@c,%c);
>     my $url;
>     my $label;
>     print "filename = [$conf_file]\n";

      local($/) = "\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


__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail – Free email you can access from anywhere!
http://mail.yahoo.com/

Reply via email to