| Author |
queston about appending a variable to a url
|
|
| Nospam 2006-10-30, 7:10 pm |
| I am wondering how I might append a variable onto a url, say for example, my
variable is $domain, and I wanted to append it to a url to complete the full
url, i.e:
$mech->get(http://."$domain"."\.com");
would the above work in representing the full url?
| |
| anno4000@radom.zrz.tu-berlin.de 2006-10-30, 7:10 pm |
| Nospam <nospam@home.com> wrote in comp.lang.perl.misc:
> I am wondering how I might append a variable onto a url, say for example, my
> variable is $domain, and I wanted to append it to a url to complete the full
> url, i.e:
>
> $mech->get(http://."$domain"."\.com");
>
> would the above work in representing the full url?
I see a few problems, but it's demeaning to do the work of a machine.
Why don't you run it and see?
Anno
| |
| Nospam 2006-10-30, 7:10 pm |
|
<anno4000@radom.zrz.tu-berlin.de> wrote in message
news:4qhhpeFna1gsU1@news.dfncis.de...
> Nospam <nospam@home.com> wrote in comp.lang.perl.misc:
example, my[color=darkred]
full[color=darkred]
>
> I see a few problems, but it's demeaning to do the work of a machine.
> Why don't you run it and see?
>
> Anno
so far:
#usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
my $mech = WWW::Mechanize=>new();
my $domain = 'example';
$mech->get('http://www.'."$domain".'.com');
print $mech->uri."\n";
I am getting this error msg:
Bareword "WWW::Mechanize" not allowed while "strict subs" in use at
gtexam1.pl l
ine 12.
gtexam1.pl had compilation errors.
I am at a loss as to how to amend the variable http://...www in the get
function
| |
| Jürgen Exner 2006-10-30, 7:10 pm |
| Nospam wrote:
> I am wondering how I might append a variable onto a url, say for
> example, my variable is $domain, and I wanted to append it to a url
> to complete the full url, i.e:
>
> $mech->get(http://."$domain"."\.com");
>
> would the above work in representing the full url?
Well, your idea of using the concatenation operator is one way of doing it,
but there are several problems with the way you implemented this idea. What
do you believe
http://."$domain"
is supposed to do? This
http://
is not a valid Perl item.
And why are you escaping the dot in "\.com"?
Instead of bothering with proper quoting and tons of concatenation
operations _I_ would just use a simple stringification:
$mech->get "http://$domain.com";
jue
| |
| anno4000@radom.zrz.tu-berlin.de 2006-10-30, 7:10 pm |
| Nospam <nospam@home.com> wrote in comp.lang.perl.misc:
>
> <anno4000@radom.zrz.tu-berlin.de> wrote in message
> news:4qhhpeFna1gsU1@news.dfncis.de...
> example, my
> full
>
> so far:
>
> #usr/bin/perl
> use strict;
> use warnings;
> use WWW::Mechanize;
>
>
> my $mech = WWW::Mechanize=>new();
^^
That's the wrong kind of arrow. Try again.
Anno
| |
| Jürgen Exner 2006-10-30, 7:10 pm |
| Nospam wrote:
>
> $mech->get('http://www.'."$domain".'.com');
Do you see the difference between those 2 lines?
Why did you lead us on a wild goose chase with your first posting?
> Bareword "WWW::Mechanize" not allowed while "strict subs" in use at
Why didnt' you include this error message in your first posting?
> I am at a loss as to how to amend the variable http://...www in the
> get function
Why do you think the construction of that string has anything to do with the
error message that you are getting?
Instead you may want to check out how you construct that object that perl is
complaining about in line 12:
Your code:
> my $mech = WWW::Mechanize=>new();
Sample code from the documentation:
my $mech = WWW::Mechanize->new()
Do you see the difference?
jue
| |
| J. Gleixner 2006-10-30, 7:10 pm |
| Nospam wrote:
> #usr/bin/perl
Also, the shebang line should be more like:
#!/usr/bin/perl
|
|
|
|