CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Variable Subs?

 



muinatit
Deleted

Feb 12, 2001, 2:23 PM

Post #1 of 3 (791 views)
Variable Subs? Can't Post

I have a small snip of code here..


Code
    my $info = sub { 
open (HTD, "$htpasswd") || die "$htpasswd: $!";
print $_ while (<HTD>);
close (HTD);
};

open (MAN, "main.html") || die "main.html: $!";
while (<MAN>) {
$_ =~ s/\[dir\]/$direct/g;
$_ =~ s/\[info\]/$info/g;
print $_;
}
close (MAN);

I want to replace the [info] in the file with the content from the $htpasswd file. When I run the script the [dir] if fine, but I get CODE(0x805dd5c) in place of the [info].

Don't have to worry about Tainting and strict and everything, I have both there.

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com


japhy
Enthusiast / Moderator

Feb 12, 2001, 3:29 PM

Post #2 of 3 (788 views)
Re: Variable Subs? [In reply to] Can't Post

Your code reference is never getting called, and if it were, it would be printing the contents, not storing it in a string. Perhaps you want to do:


Code
my $info; 
{
local (*FILE, $/);
open FILE, $filename or die "can't read $filename: $!";
$info = <FILE>;
}

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


muinatit
Deleted

Feb 13, 2001, 2:45 PM

Post #3 of 3 (773 views)
Re: Variable Subs? [In reply to] Can't Post

Thanks much japhy. Works like a charm.

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives