Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Keep It Simple, Stupid
 
PerlMonks  

Weird things...

by Anonymous Monk
on Jul 13, 2001 at 15:47 UTC ( [id://96447]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

This is weird.

I have some variables that won't show up in a required file.

Example...

$name = "turd"; require "./turd.pl";
turd.pl is an html document with surrounding print<<ENDHTML; ENDHTML things...

whenever I run the program, the variable $name is never shown, and even though I see the html without the variables, I do see this error (which is repeated 3 times...)

Use of uninitialized value in concatenation (.) at /turd.pl line 1.

line one contains "print<<ENDHTML;"

The Weird thing in all of this is that if i replace the require statement with exactly what is in the "required" file, everything works fine.

Even though they are not required in this particular subroutine, I have multiple required files in this script, and all of them are working fine. I am at a loss.

Any ideas?

Edit: chipmunk 2001-07-13

Replies are listed 'Best First'.
Re: Weird things...
by HyperZonk (Friar) on Jul 13, 2001 at 15:51 UTC
    Is name initialized in the main routine? If so, you need to qualify its use in loaded modules with main::. Example: in turd.pl, use $main::name in place of $main.
Re: Weird things...
by Anonymous Monk on Jul 13, 2001 at 15:52 UTC
    correction..
    $name="turd"; require "./turd.pl";
    line one contains "print< < ENDHTML"
Re: Weird things...
by bikeNomad (Priest) on Jul 13, 2001 at 15:52 UTC
    What kind of variable is $name? If it's a lexical (my) variable, it won't be visible in the included file. You could make it a local, or you could eval the contents of the file:

    open FH, 'included.pl'; my $text; { local $/ = undef; $text = <FH>; } close FH; my $name = 'turd'; eval $text; die "error in included file: $@" if $@;
Re: Weird things...
by Wookie (Beadle) on Jul 13, 2001 at 16:39 UTC
    If you want to include settings from an external file - the easiest way I have found to do this is to have the external file like:
    #!/usr/bin/perl $name = 'turd'; $blah = 'sample';
    Then in your main program:
    #!/usr/bin/perl -w use strict; use vars qw($name $blah) require './turd.pl';
    That should allow you to read in the variables :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://96447]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.