| Author |
Grep and LWP |
nodnil
Member

Posts: 7
Location: Australia
Joined: 19.11.08 Rank: Apprentice |
|
Hi,
I am working through Perl and LWP by O'Reilly and I am having troubles with this.
% perl -MLWP::Simple -e "getprint('http://cpan.org/RECENT')||die" | grep Apache
I hadn't come across grep before so I did some research and the syntax for searching arrays but not web files. How do I do this?
EDIT: This is my code:
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
getprint('http://cpan.org/RECENT') || die;
grep(/Apache/);
Edited by nodnil on 21-05-10 12:35 |
|
| Author |
RE: Grep and LWP |
wolfmankurd
Member

Posts: 1519
Location: UK
Joined: 30.05.05 Rank: God |
|
What do you want to do?
Idk much about perl, but grep is a program (and as far as I know) not a command in perl.
| is a pipe, it puts output from 1 command and feeds it into another.
perl -MLWP::Simple -e "getprint('http://cpan.org/RECENT')||die"
That -e runs the perl code in the "'s. The output is then piped into grep which is set to search for 'Apache'.
BY READING MY POST, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE USE OF THIS (MIS)INFORMATION.

|
|
| Author |
RE: Grep and LWP |
nodnil
Member

Posts: 7
Location: Australia
Joined: 19.11.08 Rank: Apprentice |
|
Thanks for your reply.
Well when I searched I found this:
@LIST = grep(expresblockedsion, @ARRAY);
Example
@myNames = ('Jacob', 'Michael', 'Joshua', 'Matthew', 'Alexander', 'Andrew');
@grepNames = grep(/^A/, @myNames); |
|
| Author |
RE: Grep and LWP |
wolfmankurd
Member

Posts: 1519
Location: UK
Joined: 30.05.05 Rank: God |
|
|
#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
my $lol = getprint('http://cpan.org/RECENT') || die;
print grep(/Apache/,$lol);
Is this what you want?
I'm no perl programmer :/
BY READING MY POST, YOU ACCEPT IT AS IS AND AGREE TO MY DISCLAIMER OF ALL WARRANTIES, EXPRESS OR IMPLIED, AS WELL AS DISCLAIMERS OF ALL LIABILITY, DIRECT, INDIRECT, CONSEQUENTIAL OR INCIDENTAL, THAT MAY ARISE FROM THE USE OF THIS (MIS)INFORMATION.

Edited by wolfmankurd on 21-05-10 13:28 |
|
| Author |
RE: Grep and LWP |
nodnil
Member

Posts: 7
Location: Australia
Joined: 19.11.08 Rank: Apprentice |
|
That still displayed all the results and didn't filter them but it did work without errors however. I'll have a play around with it. Thanks 
Edited by nodnil on 21-05-10 13:57 |
|
| Author |
RE: Grep and LWP |
spyware
Member

Posts: 4190
Location: The Netherlands
Joined: 14.04.07 Rank: God Warn Level: 90
|
|
getprint outputs to STDOUT.

"The chowner of property." - Zeph Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term. - Carl Sagan Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor? - Ebert |
|
| Author |
RE: Grep and LWP |
fashizzlepop
Member

Posts: 482
Location: Old folks home.
Joined: 08.04.08 Rank: Uber Elite |
|
Grep, in Perl, takes a pattern and an array. It then searches through to find mathces and returns those. Smart matching would also work if you know that better.
"The definition of insanity is doing the same thing over and over again and expecting different results.
~Albert Einstein~
 |
|