I just happened to write exactly this the other day,
as a generic configuration file reader. Here's the
basics:

sub readINI {    # argument: filename
   my %params;
   open( INIFILE, $_[0] )
      || die "Could not open $_[0]\n";
   while(<INIFILE>) {
      if(! /^#/ ) {  # Allow comments
         chomp;
         $params{$`} = $' if( /=/ );
      }
   }
   return %params;
}

What you get back is a hash of key/value pairs. In
your case, $myhash{name} = 'john', $myhash{id} =
'12345', etc. You can even comment a line out by
putting a "#" in the first position (or by not having
an "=" anywhere in the line). The only slightly
obscure thing here is the use of $` and $' to mean
"everything before the match" and "everything after
the match", to save you having to explicitely capture
those sections with parens.

FYI, more detail on your initial question would have
allowed us to cut to the chase faster.

- John

--- ChaoZ Inferno <[EMAIL PROTECTED]> wrote:
> Actually, the content of the file looks something
> like:-
> name=john
> id=12345
> password=12345
> colour=blue
> 
> I am trying to grab the value field of each line and
> assigned it to be a
> variable.
> 
> ...


=====
"When you're following an angel, does it mean you have to throw your body off a 
building?" - They Might Be Giants, http://www.tmbg.com
----
Word of the week: Serendipity, see http://www.bartleby.com/61/93/S0279300.html

__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com

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

Reply via email to