If this did what you wanted Robert, then please ignore. But from the looks
of it, this will just get the first item1='value' from each line.
The following gets all values on each line, using your example data.
#!/usr/local/bin/perl -n
# this is what you want
push (@list, $1) while ( /.*?='(.*?)'/g );
# test what we got
$i=1;
print "Current Line: $_";
foreach $item ( @list ) { print "item" . $i++ . " = $item\n"; }
hth
charles
p.s. who or what is inseerting the list name into the subject (which I
removed), and why?
On Mon, 21 Feb 2000, David Kramer wrote:
> Robert Canary wrote:
> >
> > Hi,
> >
> > 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
> >
> > I can't figure out how to get the line into an array. Can anyone offer
> > some ideas?
>
> You may need to adjust the parsing line a little depending on what is
> valid for your keys and values, but this should work otherwise. Just
> tested it here. Next time, though, check out the newsgroup
> comp.lang.perl. If you don't have news access where you are, you can
> use http://www.deja.com.
>
>
> open(IN,'foo') or die("$0: Could not open foo for read: $1");
>
> #Read file, load array
> while(<IN>)
> {
> chomp();
> $_ =~ /^(\w+)=(\w+)$/;
> if($1 ne '')
> {
> $Line{$1}=$2;
> }
> }
>
> foreach $Key (keys(%Line))
> {
> print("[$Key]=[$Line{$Key}]\n");
> }
>
--
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.