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

Re: Reading Variables from a File

by Chrisf (Friar)
on Dec 30, 2001 at 01:15 UTC ( [id://135157]=note: print w/replies, xml ) Need Help??


in reply to Reading Variables from a File

Say you have written the numbers to the file and have delimited them with | so the data in the file looks like this:

1111|2222|3333

You can then read them into your variables like so:

#!/usr/bin/perl -w use strict; # declare your variables my $varFile = "variables.txt"; my ($var1,$var2,$var3); # open the file open DATA, $varFile or die "Can't open file: $!"; while (<DATA>) { # chomp the line chomp; # split the line into values and assign them to your variables ($var1,$var2,$var3) = split /\|/; } # close the file close DATA;

The length of the code can be reduced substantially, but this gives you an idea of what's going on.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://135157]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found