Why can't I pass the URL string to "get" in a variable?
#use strict; use warnings;
use LWP::Simple;
my $hxUrl;
my $Page;
$hxUrl="https://finance.yahoo.com/quote/SPY/history?period1=1653177600& period2=1685059200&interval=1d&filter=history&frequency=1d&includeAdjustedClose=true";
#using the variable, the page is not read in
$Page = get($hxURL);
print "at 10: length(Page) =", length($Page), "\n"; # length($Page) = null
#using the string directly, the page is accessed properly
$Page = get("https://finance.yahoo.com/quote/SPY/history?period1=1653177600& period2=1685059200&interval=1d&filter=history&frequency=1d&includeAdjustedClose=true");
print "at 14:length(Page) =", length($Page), "\n"; # length($Page) = 1399524
I have commented out 'use strict' since it won't compile and insists that: Global symbol "$hxURL" requires explicit package name (did you forget to declare "my $hxURL"?) at test.pl line 9.
NO, I didn't forget - I declared it at line 3.
I get the same message if I put the 'my' on line 6
if I put 'my' inside the parens on line 9, it complains: Use of uninitialized value in print at test.pl line 10
There is no way to satisfy it!
I have used this pattern, without 'my' and without strict in dozens of other programs without any problem. I can't understand why I'm having a problem even in this toy example.
Error messages out of LWP might help, but I get none.
The error is correct and solving the error also solves the problem you have. You've declared and assigned
$hxUrl, but used$hxURL(different spelling!!) instead. Due to this the variable$hxURLused insidegetis empty, i.e. you basically calledget("")which surely does not achieve the result you expected.