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: Beginner:
storing/saving variables

 



mount_biker
New User

Feb 11, 2002, 8:25 PM

Post #1 of 8 (1269 views)
storing/saving variables Can't Post

 I have been wondering for some time now, how I could create a page with an input variable then save it in another script then used when needed on a separate output page. I would really apreciate it if someone could help we with it. I've spent countless hours trying to figure this out, and only getting solutions of 10 page code scripts. I'm sure it can't be that complicated just to simply store a variable information in a simple database.

In the long run if this explains my problem any better is to create a site were someone can update a baseball game score or something like that in a text field then put onto my site.
If you really want to put your manhood to the test try taking your bike on the B12 trail on mount. 7 in Golden, Alberta, Canada! (the trail is 5km long and is mostly downhill so disk brakes are a nice thing to have)


AndyNewby
Novice

Feb 12, 2002, 3:49 AM

Post #2 of 8 (1262 views)
Re: [mount_biker] storing/saving variables [In reply to] Can't Post

I would use something like;


Code
open(VARS, ">vars.pl") || &error("Unable to open variable file. Reason: $!"); 
print VARS "\$var = \"testing\"\;";
close(VARS);

sub error {

my $error = shift;
print $error;
exit;

}


Obviously then in your other script you would use a 'require' at the top of the page to include this file and all its variables. Note the \'s in front of the $ the " and thge ;. This just stops it from being processed as a variable. You could use;


Code
print VARS q|$var = "testing";|;

Those q| and |; parts should just stop it being run as code, but rather just print 'as-is'.

Hope that helps

Andy
webmaster@ace-installer.com
http://www.ace-installer.com

(This post was edited by AndyNewby on Feb 12, 2002, 3:53 AM)


Paul
Enthusiast

Feb 12, 2002, 4:12 AM

Post #3 of 8 (1258 views)
Re: [mount_biker] storing/saving variables [In reply to] Can't Post

A more robust solution would be to use Data::Dumper.

You can then print your perl structure to a file.

If you were to use Andy's method you could use q| |; to prevent escaping and you'd also need a true value at the end of the file.


(This post was edited by RedRum on Feb 12, 2002, 4:14 AM)


mount_biker
New User

Feb 12, 2002, 8:01 AM

Post #4 of 8 (1249 views)
Re: [RedRum] storing/saving variables [In reply to] Can't Post

Thanks for the help! I'll try out your idea's as soon as I get a chance and see if it works.
If you really want to put your manhood to the test try taking your bike on the B12 trail on mount. 7 in Golden, Alberta, Canada! (the trail is 5km long and is mostly downhill so disk brakes are a nice thing to have)


mount_biker
New User

Feb 21, 2002, 6:14 AM

Post #5 of 8 (1233 views)
Re: [mount_biker] storing/saving variables [In reply to] Can't Post

Sorry dude but I tried your code but I could only get error pages. If you have the time could you PLEASE post the whole code for each page just asking for a name on one page and then posting the name on another. I'm really sorry but I really have been trying different things for a long time now and I just can't seem to figure out what I am doing wrong. Thanks
If you really want to put your manhood to the test try taking your bike on the B12 trail on mount. 7 in Golden, Alberta, Canada! (the trail is 5km long and is mostly downhill so disk brakes are a nice thing to have)


AndyNewby
Novice

Feb 21, 2002, 6:44 AM

Post #6 of 8 (1230 views)
Re: [mount_biker] storing/saving variables [In reply to] Can't Post

Are you refering to my idea, or Pauls?

Andy
webmaster@ace-installer.com
http://www.ace-installer.com


Paul
Enthusiast

Feb 21, 2002, 7:36 AM

Post #7 of 8 (1228 views)
Re: [AndyNewby] storing/saving variables [In reply to] Can't Post

Doubt it was mine as i didn't give any code Tongue

[perl]
#!/usr/bin/perl

use strict;
use Data::Dumper;

my $some_data = [qw(This is your data)];

open F, ">DATA.def" or die $!;
print F Dumper($some_data);
close F;
[/perl]
....then you should be left with a file in the same directory as your script. Take a look inside it ;)

You can then grab the data whenever you want using:

my $array_ref = do "DATA.txt";


(This post was edited by RedRum on Feb 21, 2002, 7:38 AM)


mount_biker
New User

Feb 23, 2002, 11:45 AM

Post #8 of 8 (1214 views)
Re: [RedRum] storing/saving variables [In reply to] Can't Post

SmileDude sweeet!!!! It works!!! Thanks so much man, your the best!Cool
If you really want to put your manhood to the test try taking your bike on the B12 trail on mount. 7 in Golden, Alberta, Canada! (the trail is 5km long and is mostly downhill so disk brakes are a nice thing to have)

(This post was edited by mount_biker on Feb 23, 2002, 11:46 AM)

 
 


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

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