Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Answer: Reading Variables from a File

( #135157=categorized answer: print w/ replies, xml ) Need Help??

Q&A > input and output > Reading Variables from a File contributed by Chrisf

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


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.

Comment on Answer: Reading Variables from a File
Select or Download Code
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2015-11-29 18:15 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (752 votes), past polls