printing a false $something and using a real $something
hey people,
I wrote a news script a while a go to help my understanding of perl and now I am expanding on it to feed my hunger for perl
Anyways, zis is ze code:
sub writeconfig {
open (FILE, ">$CONFIGnewspage/config.txt") || die "Could not open file $!"; {
print FILE "$newspage = \"$CONFIGnewspage\"\n";
print FILE "$wwwnewspage = \"$CONFIGwwwnewspage\"\n";
print FILE "$nameofnews = \"$CONFIGnameofnews\"\n";
print FILE "$nameofsite = \"$CONFIGnameofsite\"\n";
print FILE "$subfont = \"$CONFIGsubfont\"\n";
print FILE "$memfont = \"$CONFIGmemfont\"\n";
print FILE "$subcolour = \"$CONFIGsubcolour\"\n";
print FILE "$memcolour = \"$CONFIGmemcolour\"\n";
close (FILE)
}
}
Now when I submit, it writes this to the config.txt fine.. or atleast kind of. The $'s with CONFIG written in front of them are the inpit from the user. The ones without are fake. The config file is going to be used using the require ""; in another script. The other script uses $newspage, $wwwnewspage etc to define the look of it. So in the config txt I want it to look like:
$newspage = "whatever the user enetered";
But what is happening is:
= "whatever the user enetered";
(actually it is without the ; but I haven;t added that yet).
Can anuone tell me how to stop it from being blank?> I am assuming it is doing this becuade it is looking for the $ values and not finding them and so returning them as null.
cheers,
plebius posted this at 19:21 — 5th July 2000.
They have: 2 posts
Joined: Jul 2000
use \$ instead of $
richjb posted this at 20:25 — 5th July 2000.
They have: 193 posts
Joined: Feb 2000
Use this:
sub writeconfig {
open (FILE, ">$CONFIGnewspage/config.txt") || die "Could not open file $CONFIGnewspage/config.txt: $!";
print FILE qq|\$newspage = "$newspage";\n|;
print FILE qq|\$wwwnewspage = "$wwwnewspage";\n|;
print FILE qq|\$nameofnews = "$nameofnews";\n|;
print FILE qq|\$nameofsite = "$nameofsite";\n|;
print FILE qq|\$subfont = "$subfont";\n|;
print FILE qq|\$memfont = "$memfont";\n|;
print FILE qq|\$subcolour = "$subcolour";\n|;
print FILE qq|\$memcolour = "$memcolour";\n|;
close (FILE);
}
[added]Explination: the above coe shoud work, just make sure that the variables you want to have printed are the ones listed above. The reason why your script printed blank is because you did not exscape the variable, and on trying to find it, it was null.[/added]
Hope that helped. Post anymore questions you may have.
Richard
[Edited by richjb on 07-05-2000 at 04:32 PM]
[email protected]
Everyone here has a website. It's just that not all are worth posting (Mine! ).
minton posted this at 21:11 — 5th July 2000.
They have: 314 posts
Joined: Nov 1999
It works, all I had to add was the \ in front. Thanks you two.
Suzanne posted this at 05:22 — 6th July 2000.
She has: 5,507 posts
Joined: Feb 2000
Just for reference, double quotes interpret the $variable, and single quotes simply state it.
so...
$variable = "some string";
print '$variable';
prints: $variable
and print "$variable";
prints: some string
Suzanne
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.