On Mon, Mar 1, 2010 at 6:06 PM, Shawn H Corey <shawnhco...@gmail.com> wrote:

> raphael() wrote:
> > Hi,
> >
> > I am trying to understand WWW::Mechanize
> >
> > I understand that the downloaded content is stored in content().
> > Why am I not able to use a regex on it in scalar form?
> >
> > ------code------
> >
> > use strict;
> > use warnings;
> > use WWW::Mechanize;
> >
> > my $mech = WWW::Mechanize->new();
> > $mech->get("http://checkip.dyndns.org";);
> > my $last_page = $mech->content(); # last page fetched
> >
> > # this works if I store content in an array @last_page
> > # for ( @last_page ) {
> > #    if ( m/([\d+.]+)/ ) {
> > #    print "$1\n";
> > #    }
> > # }
> >
> > # ( my $ip ) = grep/(\d+\.)/, $last_page;
> >
> > ( my $ip = $last_page ) =~ m/([\d+\.]+)/;
> > print "$ip\n";
> >
> > ------end------
> >
> > my $ip gets the whole source page as its value.
> >
> > --
> > Got it while writing out this post :)
> > --
> >
> > Now the question becomes what is the difference between these two?
> >
> > ( my $ip = $last_page ) =~ m/([\d+\.]+)/;
> >
> > ( my $ip ) = ( $last_page ) =~ m/([\d+\.]+)/;
> >
> > I think the above one is "wrong syntax" for using list context?
> >
> > Also  how can I make grep work?
> >
> > ( my $ip ) = grep/(\d+\.)/, $last_page;
> >
>
> Try:
>
>  my ( $ip ) = $last_page =~ m/([\d\.]+)/;
>
> This will capture the first one.  To get more than one:
>
>  my @ips = $last_page =~ m/([\d\.]+)/g;
>
>
> grep() works on lists.  See `perldoc -f grep` for details.
>
>
> --
> Just my 0.00000002 million dollars worth,
>  Shawn
>
> Programming is as much about organization and communication
> as it is about coding.
>
> I like Perl; it's the only language where you can bless your
> thingy.
>
> Eliminate software piracy:  use only FLOSS.
>

Thanks!

grep() works on lists. -- How foolish of me, I knew that but didn't recall
it.
That I think are the perils of being new to programming.

I like Perl too; it's the only language where you can bless your
thingy. It is the first programming language that I am learning.

I picked it up because it looked like shell scripting which I daily used.
But Perl is so much better even if you just know the basics. It leaves shell
scripting way behind.

Reply via email to