Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Grep and LWP


ghost's Avatar
0 0

Hi,

I am working through Perl and LWP by O'Reilly and I am having troubles with this.

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:


use strict;
use warnings;
use LWP::Simple;

getprint('http://cpan.org/RECENT') || die;
grep(/Apache/);```

ghost's Avatar
0 0

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. markupperl -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'.


ghost's Avatar
0 0

Thanks for your reply.

Well when I searched I found this:


Example
@myNames = ('Jacob', 'Michael', 'Joshua', 'Matthew', 'Alexander', 'Andrew');
@grepNames = grep(/^A/, @myNames);``` 

ghost's Avatar
0 0

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 :/


ghost's Avatar
0 0

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 :)


spyware's Avatar
Banned
0 0

getprint outputs to STDOUT.


fashizzlepop's Avatar
Member
0 0

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.