06-07-2009
Perl newbie questions!
Hi,
So I started to learn perl a few days ago, and I have some problems...
One of my problems...
PHP Code:
#!C:\Perl64\bin\perl.exe -w
use LWP::Simple;
print "Content-Type: Text/Plain\n\n";
sub pagelinks {
return @all = get($_[0]) =~ /href\s*=\s*"?([^"\s>]+)/gis;
}
@a = pagelinks("http://website.com");
foreach $key (@a){
print $key."\n";
}
so I tried using some regex I usualy have used in php with preg_match but they don't seem to work. So I got the above regex after searching google..
and tbh I don't understand it..
What I understand from it : href followed by none or more whitespaces followed by = followed by none or more whitespaces followed by 0 or 1 " and afterwards... I don';t get it at all! it's really frustrating.
my second problem..
let's assume I have this array :
@horse = ("mdamdamad" , "asdasda" ,"asdasd" ,"a");
I want to delete the element which is equal to "a".
foreach $key (@horse){
if ($key == "a"){
delete $horse[$key];}
}
the above code doesn't seem to work.. it deletes the @horse[-2] value. I have also tryied using $key =~ /a/ and (grep $key eq "a",@horse). All have failed me.. any suggestions? please...
Last edited by byte1918; 06-07-2009 at 01:55 PM..
9 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hi :)
I just wanted to ask a few basic questions really. I'm telnetting to a remote host and I've finally found out that I'm using a csh shell.
My questions are:
1. Is the somename@something, the user group logged in?
2. How do I change user?
I'm really lost so I hope someone can help... (7 Replies)
Discussion started by: hellz
7 Replies
2. UNIX for Dummies Questions & Answers
Even though I have been logging in to a UNIX shell at school to complete school projects and write programs, but I had never really worked in UNIX environment. But a couple of weeks back I got hooked on to Solaris 9OE, read a book, a tutorial, a document provided on the Sun Microsystems website,... (1 Reply)
Discussion started by: init-5
1 Replies
3. Linux
RH 7.2
I have 2 unrelated questions -
1.) I have been able to configure and run ntp but cannot figure out how to start the service upon reboot. I have read the man pages for ntsysv - this is a manual action, but I want to drop a tarball of config files on a new installation and cannot... (1 Reply)
Discussion started by: jalburger
1 Replies
4. Shell Programming and Scripting
I am relatively new to both KSH and Unix scripting, and I would like some help getting my script up and running. I would like to have the script attempt various commands (tar, copy, gzip etc) and then write the results (error msg or success msg) to a temp file. I would then like an email sent to... (2 Replies)
Discussion started by: mharley
2 Replies
5. Linux
I have been an apple customer for years now, and am not satisfied with the direction that they are going. So I just ordered my first PC notebook the other day. I have no desire to use windows, however with microsoft's hold on the market, I feel that I may have a hard time doing this. I want to... (2 Replies)
Discussion started by: Brycemb16
2 Replies
6. UNIX for Dummies Questions & Answers
Hi Unix gurus,
I know these are some easy questions.
But i just want to be sure about them.
Hope someone can help explain the following please?
1) if ]
- What does the "-r" means?
2) isql -U $DBUSER -D $DBNAME -S $DSQUERY -w 1000 -s";" << testfile > $FILE
- What does the -s";" mean and... (1 Reply)
Discussion started by: gholdbhurg
1 Replies
7. UNIX for Dummies Questions & Answers
Hello,
I want to learn LISP, and I have a GNU/Linux OS. I first sought a LISP compiler/interpreter and was told that GNU Emacs has a LISP mode. But I couldn't get into LISP mode, nor I don't know how to use it when I get into LISP mode.
How can I run LISP code under GNU Emacs?
And if... (1 Reply)
Discussion started by: rayne
1 Replies
8. Solaris
Hello everyone, I am brand spanking new to both Solaris and Unix. I thought I would give it a go after buying a SB2500 off ebay for a few hundred dollars.
I am having some issues that I am not sure how to correct, and I am wondering if I can get a few pointers?
The first one is that my system... (2 Replies)
Discussion started by: GeekMasterFlash
2 Replies
9. AIX
Hi Guys, I am new in this forum and new with AIX however not new with Power System. I have worked with iSeries for many years. Now supporting AIX on Power.
Here are some basic questions I have.
1. I am using Putty to connect from my PC to the AIX boxes. Is there any other (better) program to... (6 Replies)
Discussion started by: 300zxmuro
6 Replies
LEARN ABOUT MOJAVE
lwp::simple5.18
LWP::Simple(3) User Contributed Perl Documentation LWP::Simple(3)
NAME
LWP::Simple - simple procedural interface to LWP
SYNOPSIS
perl -MLWP::Simple -e 'getprint "http://www.sn.no"'
use LWP::Simple;
$content = get("http://www.sn.no/");
die "Couldn't get it!" unless defined $content;
if (mirror("http://www.sn.no/", "foo") == RC_NOT_MODIFIED) {
...
}
if (is_success(getprint("http://www.sn.no/"))) {
...
}
DESCRIPTION
This module is meant for people who want a simplified view of the libwww-perl library. It should also be suitable for one-liners. If you
need more control or access to the header fields in the requests sent and responses received, then you should use the full object-oriented
interface provided by the "LWP::UserAgent" module.
The following functions are provided (and exported) by this module:
get($url)
The get() function will fetch the document identified by the given URL and return it. It returns "undef" if it fails. The $url
argument can be either a string or a reference to a URI object.
You will not be able to examine the response code or response headers (like 'Content-Type') when you are accessing the web using this
function. If you need that information you should use the full OO interface (see LWP::UserAgent).
head($url)
Get document headers. Returns the following 5 values if successful: ($content_type, $document_length, $modified_time, $expires, $server)
Returns an empty list if it fails. In scalar context returns TRUE if successful.
getprint($url)
Get and print a document identified by a URL. The document is printed to the selected default filehandle for output (normally STDOUT) as
data is received from the network. If the request fails, then the status code and message are printed on STDERR. The return value is
the HTTP response code.
getstore($url, $file)
Gets a document identified by a URL and stores it in the file. The return value is the HTTP response code.
mirror($url, $file)
Get and store a document identified by a URL, using If-modified-since, and checking the Content-Length. Returns the HTTP response code.
This module also exports the HTTP::Status constants and procedures. You can use them when you check the response code from getprint(),
getstore() or mirror(). The constants are:
RC_CONTINUE
RC_SWITCHING_PROTOCOLS
RC_OK
RC_CREATED
RC_ACCEPTED
RC_NON_AUTHORITATIVE_INFORMATION
RC_NO_CONTENT
RC_RESET_CONTENT
RC_PARTIAL_CONTENT
RC_MULTIPLE_CHOICES
RC_MOVED_PERMANENTLY
RC_MOVED_TEMPORARILY
RC_SEE_OTHER
RC_NOT_MODIFIED
RC_USE_PROXY
RC_BAD_REQUEST
RC_UNAUTHORIZED
RC_PAYMENT_REQUIRED
RC_FORBIDDEN
RC_NOT_FOUND
RC_METHOD_NOT_ALLOWED
RC_NOT_ACCEPTABLE
RC_PROXY_AUTHENTICATION_REQUIRED
RC_REQUEST_TIMEOUT
RC_CONFLICT
RC_GONE
RC_LENGTH_REQUIRED
RC_PRECONDITION_FAILED
RC_REQUEST_ENTITY_TOO_LARGE
RC_REQUEST_URI_TOO_LARGE
RC_UNSUPPORTED_MEDIA_TYPE
RC_INTERNAL_SERVER_ERROR
RC_NOT_IMPLEMENTED
RC_BAD_GATEWAY
RC_SERVICE_UNAVAILABLE
RC_GATEWAY_TIMEOUT
RC_HTTP_VERSION_NOT_SUPPORTED
The HTTP::Status classification functions are:
is_success($rc)
True if response code indicated a successful request.
is_error($rc)
True if response code indicated that an error occurred.
The module will also export the LWP::UserAgent object as $ua if you ask for it explicitly.
The user agent created by this module will identify itself as "LWP::Simple/#.##" and will initialize its proxy defaults from the
environment (by calling $ua->env_proxy).
CAVEAT
Note that if you are using both LWP::Simple and the very popular CGI.pm module, you may be importing a "head" function from each module,
producing a warning like "Prototype mismatch: sub main::head ($) vs none". Get around this problem by just not importing LWP::Simple's
"head" function, like so:
use LWP::Simple qw(!head);
use CGI qw(:standard); # then only CGI.pm defines a head()
Then if you do need LWP::Simple's "head" function, you can just call it as "LWP::Simple::head($url)".
SEE ALSO
LWP, lwpcook, LWP::UserAgent, HTTP::Status, lwp-request, lwp-mirror
perl v5.18.2 2012-02-18 LWP::Simple(3)