Created
July 22, 2011 18:08
-
-
Save dbb/1100016 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use 5.010; | |
my $string = "This is the real string."; | |
system 'echo ' . "'" . '$string' . "'" . '> example.txt'; | |
# the command is: | |
# % echo '$string' > example.txt | |
# so the file literally contains the line: $string | |
open(my $in, "<", "example.txt"); | |
my $read = <$in>; | |
# perl reads the file literally, i.e. as if saying: | |
# my $first_line = '$string'; | |
# my $read = $first_line; | |
# perl doesn't know that $string is a variable in the file | |
say "\$string = '$string'"; | |
say "\$read = '$read'"; | |
# but when you evaluate it, the variable is "discovered" | |
my $ev = eval $read; | |
say "\$ev = '$ev'"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment