On 05 Jun 2001 17:49:53 -0700, Peter Cornelius wrote:
<snip>
> 
>  local $_ = 'name = "quoted string with space"';
> 
<snip>

If your pattern always looks like this then try:

#!/usr/bin/perl

use strict;    #make me behave

my $name;          #holds the key part of config
my $value;         #the value of part of config
my $delim = "=";   #the delimiter between key and value

open(FILE, shift) or die "Could not open $_:$!"; #open first argument or
                                                 #die trying

while (<FILE>) { #while there are lines left assign next line to $_
        chomp; #remove record seperator from line (ie \n)
        unless (/ ($delim) /) { die "Bad file data" } #match " = " or
                                                      #die trying 
        $name = $`;  #put everthing before the match into $name
        $value = $'; #put everything after the match into $value
        #print uses [] to make white space easier to see
        print "name = [$name] :: value = [$value]\n";
}
close FILE;

Its output looks like this:

[cowens@cowens cowens]$ cat data
this = this is another line
that = this is a line that countains =, oh no!
bugger = me
[cowens@cowens cowens]$ ./test.pl data
name = [this] :: value = [this is another line]
name = [that] :: value = [this is a line that countains =, oh no!]
name = [bugger] :: value = [me]



-- 
Today is Boomtime, the 11st day of Confusion in the YOLD 3167



Reply via email to