[Israel.pm] LWP Q.

Gaal Yahas gaal at forum2.org
Sun Jul 1 08:50:39 PDT 2007


Sure. The following are NOT equivalent in Perl:

my ($p) = $str =~ m/(ab)/;
my $p   = $str =~ m/(ab)/;

In the first, the possible values for $p are either "ab" (if the match
succeeded) or undef (if it
did not).

In the second, the possible values are a true value (in actuality, 1)
or a false one (in actuality, "").

This is an example of an important concept in Perl called context. In
a nutshell, it's a way for the _caller_ of some code to influence the
kind of results it expects to get back from it. (Searching for "perl
context" would bring up some good longer discussions.) Most other
languages don't have this feature so it can be confusing, but once you
know about it it's a pretty great thing.

On 6/30/07, Ernst, Yehuda <yernst at nds.com> wrote:
> Hello!
>
> Thansk for you answer.
>
> what do you mean by
>
> "Make sure to put $p in list context"
>
> can you put in an example.
>
>
> Thanks
>
> -----Original Message-----
> From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il]On Behalf Of Gaal Yahas
> Sent: Thursday, June 28, 2007 10:58 PM
> To: Perl in Israel
> Subject: Re: [Israel.pm] LWP Q.
>
>
> I think your m// needs a /g modifier if you want @p to have more than one match.
>
> If you want only the first,
>
> my ($p) = (the match);
>
> Make sure to put $p in list context! Otherwise it'll only indicate
> whether the match succeeded.
>
> On 6/28/07, Shlomi Fish <shlomif at iglu.org.il> wrote:
> > On Thursday 28 June 2007, Ernst, Yehuda wrote:
> > > hello!
> > >
> > > I am trying to run this
> > >
> > > $res = $browser->get ("http........................
> > > my @p = $res-> =~ m|somthing(.*?)somthing|;
> > >
> > > $p[0] is empty.
> > >
> > > but if i print $res->as_string in the middle
> > >
> > > $res = $browser->get ("http........................
> > > print $res->as_string;
> > > my @p = $res-> =~ m|somthing(.*?)somthing|;
> > >
> > >
> > > $p[0] is not empty.
> > >
> >
> > This snippet works for me:
> >
> > {{{{{{{{{{{{{{
> > #!/usr/bin/perl
> >
> > use strict;
> > use warnings;
> >
> > use LWP::UserAgent;
> > use Data::Dumper;
> >
> > my $ua = LWP::UserAgent->new();
> >
> > my $res = $ua->get("http://www.shlomifish.org/");
> >
> > my @p = ($res->content() =~ m{<p(.*?)</p>});
> >
> > print Dumper(\@p);
> > }}}}}}}}}}}}}}
> >
> > I'm using perl-5.8.8-12mdv2008.0 on Mandriva Cooker. It would be useful if you
> > could provide a full script that reproduces this problem, and mention your
> > perl version and platform.
> >
> > Regards,
> >
> >         Shlomi Fish
> >
> > ---------------------------------------------------------------------
> > Shlomi Fish      shlomif at iglu.org.il
> > Homepage:        http://www.shlomifish.org/
> >
> > If it's not in my E-mail it doesn't happen. And if my E-mail is saying
> > one thing, and everything else says something else - E-mail will conquer.
> >     -- An Israeli Linuxer
> > _______________________________________________
> > Perl mailing list
> > Perl at perl.org.il
> > http://perl.org.il/mailman/listinfo/perl
> >
>
>
> --
> Gaal Yahas <gaal at forum2.org>
> http://gaal.livejournal.com/
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
> *************************************************************************************
> This e-mail is confidential, the property of NDS Ltd and intended for the addressee only.  Any dissemination, copying or distribution of this message or any attachments by anyone other than the intended recipient is strictly prohibited.  If you have received this message in error, please immediately notify the postmaster at nds.com and destroy the original message.  Messages sent to and from NDS may be monitored.  NDS cannot guarantee any message delivery method is secure or error-free.  Information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses.  We do not accept responsibility for any errors or omissions in this message and/or attachment that arise as a result of transmission.  You should carry out your own virus checks before opening any attachment.  Any views or opinions presented are solely those of the author and do not necessarily represent those of NDS.
>
> To protect the environment please do not print this e-mail unless necessary.
> **************************************************************************************
>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>



-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list