Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
And you have the followingstate=$state zip=$zip phone=$phone
This prints outmy $state = "IA"; my $zip = "44444"; my $phone = "343-343-3443"; open(FILE, "file.txt") or die "oops $!"; my @contents = <FILE>; close(FILE) or die "oops $!"; print @contents;
instead ofstate=$state zip=$zip phone=$phone
So obviously it's reading everything literally, even if the vars are assigned prior to reading of the text file. I know I can s/\$var/$var//; but the question isn't how to get around it, it's WHY is it this way? Why aren't the variables being used as variables if it's read from a file?state=IA zip=44444 phone=343-343-3443
Is there a way to read from a file where it WOULD do as expected without s///?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reading from txt makes variables literal?
by japhy (Canon) on Mar 02, 2006 at 22:13 UTC | |
by Anonymous Monk on Mar 02, 2006 at 22:16 UTC | |
by japhy (Canon) on Mar 02, 2006 at 22:42 UTC | |
by Anonymous Monk on Mar 02, 2006 at 22:36 UTC | |
by spiritway (Vicar) on Mar 03, 2006 at 09:42 UTC | |
|
Re: Reading from txt makes variables literal?
by Roy Johnson (Monsignor) on Mar 02, 2006 at 22:26 UTC | |
|
Re: Reading from txt makes variables literal?
by crashtest (Curate) on Mar 02, 2006 at 23:01 UTC | |
|
Re: Reading from txt makes variables literal?
by davido (Cardinal) on Mar 03, 2006 at 05:00 UTC |