-2

Suppose I have:

my $enter = `curl -s "http://google.com"`;

Would it be possible to read $enter as a string as well? On top of running the curl function, I am trying to read it as a string so I can pull the website name (google.com)

Bijan
  • 7,737
  • 18
  • 89
  • 149
  • 3
    What do you mean "read `$enter` as a string?" – Ryan J Feb 06 '15 at 06:15
  • I want to run the curl command and also store the URL as a string (in this case google.com) – Bijan Feb 06 '15 at 06:25
  • I've poked through some of your other questions and cannot figure out what you're trying to do... but is there some reason you can't use the fact that it's right in front of you to "store" it somehow? – Ryan J Feb 06 '15 at 06:26
  • possible duplicate of [Perl: Look forward to command that has not run yet](http://stackoverflow.com/questions/28357962/perl-look-forward-to-command-that-has-not-run-yet) – Biffen Feb 06 '15 at 06:27
  • You can do this using the [`Backticks`](https://metacpan.org/pod/Backticks) module (beware: it uses source filtering, which is error-prone and [should generally be avoided](http://stackoverflow.com/questions/1785852/why-are-perl-source-filters-bad-and-when-is-it-ok-to-use-them)). However, there is probably a better way...could you please explain where the `curl` command comes from such that you think you're unable to access its contents directly? Perhaps you're reading it from a file or something like that? – ThisSuitIsBlackNot Feb 06 '15 at 16:41

1 Answers1

2

No, the text inside the backticks is not made available in a variable. But there is nothing stopping you from putting it in a variable of your own and executing that string:

my $cmd = 'curl -s "http://google.com"';
my $enter = `$cmd`;
Ben Grimm
  • 4,316
  • 2
  • 15
  • 24