How do I unsubscribe from this list?

-----Original Message-----
From: Jon Lapham [mailto:[EMAIL PROTECTED]
Sent: Sunday, February 27, 2005 8:38 AM
To: susan lam
Cc: [email protected]
Subject: Re: parsing a file


Jon Lapham wrote:
> susan lam wrote:
> 
>> How can I modify my subroutine to parse file2 by
>> skipping those '#'? 
>> file2:
>> #
>> # Usage: <variable>=<value>
>> #
>> userid=apps
>> userpwd=appspwd
>> database=mydb
>>
>> sub mysub {
>>         open(PFILE,$ARGV[0]) || die ("Could not open
>> file");
>>         @pf=<PFILE>;
>>         foreach $param (@pf) {
> 
> 
> next if (/^#/);

Oops, of that should say:
next if ($param =~ /^#/);

>>                 chop($param);
>>                 my ($pname,$pval)=split(/=/,$param);
>>                 $ary{$pname}=$pval;
>>         }
>>         close(PFILE);
>> }

PS: you do not need to read the file into an array before working on it. 
  In fact, that will read the whole file into memory.   I guess this is 
not a problem for this example since the files are small...

You could try this, which will process the data files one line at a time.

sub mysub {
   open PFILE, $ARGV[0] or die "Could not open file";
   while (<PFILE>) {
     next if (/^#/);
    ($pname,$pval)=split(/=/,$_);
    $ary{$pname}=$pval;
   }
   close PFILE;
}

-- 
-**-*-*---*-*---*-*---*-----*-*-----*---*-*---*-----*-----*-*-----*---
  Jon Lapham  <[EMAIL PROTECTED]>                Rio de Janeiro, Brasil
  Personal: http://www.jandr.org/
***-*--*----*-------*------------*--------------------*---------------

Reply via email to