Skip to content

Instantly share code, notes, and snippets.

@dbb
Created July 22, 2011 18:08
Show Gist options
  • Save dbb/1100016 to your computer and use it in GitHub Desktop.
Save dbb/1100016 to your computer and use it in GitHub Desktop.
#!/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