[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


perl newbie

Posted on 2012-09-18
Medium Priority
Last Modified: 2012-09-19
hi experts,

i am new to perl and very lazy.

i am trying to run the following program so that it prints the web page from whatismyip.com for a start.
further i want to grep for string "Your IP Address Is:" and print my WAN IP to std out.

However my very first challenge is that program fails with following error:
"Use of uninitialized value in print at ./getwanip-expertexchange.pl line 11."

can you kind souls, please
- enlighten me how to fix the above error
- add additional plumbing to my scriptlet so that, it prints only the IP retrieved from this page.
#!/usr/bin/perl -w

use LWP::Simple;
use strict;

my $url = "http://www.whatismyip.com";

my $content = get($url);
print $content;

i will pray for a 10 fold increase in yr kindness and your intellect. :)
Thanks Experts
Question by:sherrysidhu
LVL 81

Assisted Solution

arnold earned 800 total points
ID: 38412001
You are using -w and strict;

Each means that you  must pre-define or pre-declare every variable you will be using.
my $content, $url;

Not sure which line is at fault try
perl -c getwanip-getexpertxchange.pl
It should pont to the line at fault.
The get($url)

The difficulty is the error might be that get($url) does not get a response such that $content is null which you then try to print.
LVL 26

Accepted Solution

arober11 earned 1200 total points
ID: 38412506

Your problem is that www.whatismyip.com will only accept requests from Browsers, or a script that has an appropriate User Agent set in the GET message header. If you try from a script, without spoofing, they'll bounce the request e.g.

perl -MLWP::Simple -e 'getprint "http://www.whatismyip.com"'
403 Forbidden <URL:http://www.whatismyip.com>

Open in new window


Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Make the most of your online learning experience.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question