[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
Re: [MacPerl-AnyPerl] good idea or bad idea?
On Thu, Jul 13, 2000 at 12:43:18PM -0500, Kevin van Haaren wrote:
> I have a couple of questions about the following code snippet:
>
> my $story_time;
> foreach my $line (split(/\015/,$sci_page_head)) {
> if ($line =~ /OriginalPublicationDate/) {
> ($story_time) = ($line =~ /content=\"(.*)\"/);
> }
> }
> print $story_time;
>
> First, is declaring the my $line in the foreach line a good idea/bad
> idea/doesn't matter? I know if I declare the $story_time as my
> inside the loop it doesn't seem to exist outside the loop. The code
> as written works fine (I don't need the $line variable outside the
> loop).
Doesn't matter, but if you don't need $line outside the loop, it makes more
sense to declare it as you did.
> Second, is this a good way of doing this loop? $sci_page_head is
> just the header info from a web page sucked in via LWP::Simple. If
> it where a text file I'd probably just do a while <> {}. I guess I'm
> asking if there is a way to get rid of the $line variable altogether.
I don't think you need a loop at all:
my($story_time) =
$sci_page_head =~ /OriginalPublicationDate.*content="(.*)"/;
print $story_time;
Ronald
==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org