On Mon, 21 Feb 2000, Robert Canary wrote:
| > Sorry for the perl question.....
| > I have extracted from a log file ta line that reads that reads something
| > like this:
| > item1='value', item2='value2', item3='value3'
| > i am trying to get parse the line as to assign to an array as such:
| > $line{item1}=$value1 etc etc etc
On Tue, Feb 22, 2000 at 09:13:59PM +0100, Igmar Palsenberg wrote:
| That needs to be something like
| $line{$item1} = $value1
| Constants are :
| $line{'somevalue'} = $value1;
| Perl variables always start with $
Igmar, he was asking _how_ to do that.
Robert, try this:
while (<THEFILE>) # take lines from somewhere, put in $_
{ chomp; # strip trailing \n if any
%line=(); # flush array
# look for x='y'
while (/(\w+)='([^']*)'[\s,]*/)
{ $item=$1; $value=$2; $_=$';
$line{$item}=$value;
}
# do something with %line here
}
Cheers,
--
Cameron Simpson, DoD#743 [EMAIL PROTECTED] http://www.zip.com.au/~cs/
No one is completely worthless... they can always serve as a bad example.
--
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.