Why does this work:
        open(APACHE_CONF, "/usr/local/apache/conf/httpd.conf") or die "Could
not open Apache config file:\n$!\n";
        my @servernames;
        while(<APACHE_CONF>) {
                push (@servernames, $1)
                if/ServerName\swww.(.*)/;
        }
        close(APACHE_CONF);
        my $h;
        foreach $h(@servernames) {
        print $h;
    #blah blah blah

But this doesn't:

open(FP, "$tempfile"); # Open $tempfile for reading
                my $i=0;
                while(<FP>) {
                        push (@list, $1)
                        if /(.com\S)/;
                }
                foreach my $h(@list) {
                        print "$h";
                }

They're more or less the same thing except the regexps are different....

Tyler

----- Original Message -----
From: "Jos I. Boumans" <[EMAIL PROTECTED]>
To: "Tyler Longren" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, July 18, 2001 2:25 PM
Subject: Re: looking at rows in text files


> using 'my' within the while loop will make it lose it's value once the
loop
> exits and it will be reset every time you read in a new line
> declare 'my @list' above the loop, and you'll not have that problem.
>
> for readabillity, use:
> if(/(\S+/){ push @list, $1 }
> altho that's a bit superfluous i think, as i pointed out in my example
> earlier
>
> read up on scoping on MJD's site:
> http://perl.plover.com/FAQs/Namespaces.html
>
> Jos


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to