Hi Ken,
On 6/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
The second option worked to print Abercrombie, Neil to the screen.  Still
working on basic concepts.  The split construction was suggested by
someone as a way to get to pulling in all listings and ultimately all
votes.
All votes? You lost me there. I don't remember seeing anything about votes...
Can you complete that logic to return all lines with
representatives' names?
Have you tried the first option? It should print out all the
representatives' names:
print "$_\n" for ($browser->content =~ /(?<=size=2><i>) [^<]+/gx);

 Among my points of confusion, when is the print
command within braces and when is it outside braces?
Hmm... well, the short answer is that braces represent blocks of code
that is run together, so the braces after the if means "run all this
stuff if the condition is true." But Perl likes to give you options,
and, in retrospect, I shouldn't have used the if and for in the way I
did above (they're called "postfix if and for", if I rembember
correctly). Just know that writing:
print "$_\n" foreach (@a);

is the same as writing:
foreach (@a) { print "$_\n"; }

Same thing with if: you can just place it at the end instead of using
curly braces if you're only doing it for one expression (e.g., 'print
$b'). So my code above, re-written, is:
#!/bin/perl

use strict;
use warnings;

use WWW::Mechanize;

my $output_dir = "c:/training/bc";

my $starting_url = "http://clerk.house.gov/members/olmbr.html";;

my $browser = WWW::Mechanize->new();

$browser->get( $starting_url );

foreach ($browser->content =~ /(?<=size=2><i>) [^<]+/gx) {
   print "$_\n";
}

Anyway, hopefully I'm not making things worse. I honestly, tho', think
you should start reading Learning Perl by Randal Schwartz et al., go
to http://learn.perl.org/ or http://perlmonks.org/  All are great
resources to learning Perl.

Best,
David

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to