On Mon, Apr 29, 2002 at 02:16:13PM +0100, Anders Holm wrote: > Thank you Micheal!! > > Having loads of fun with this at the moment!! ;) > > There seems to be another caveat as well, SMP systems. ;) Fortunate enough > to be able to test it on such a box at work. > > So, input would be something of the following: > > [anders@redhat anders]$ cat /proc/cpuinfo > processor : 0 > vendor_id : GenuineIntel > ... > > processor : 1 > vendor_id : GenuineIntel > cpu family : 6 > model : 8
Then how about the following: my $cpu_id = 'unknown'; while (<>) { next unless /insert match here/; my ($key, $value) = ($1, $2); # Store them to avoid them # beiing overridden due to # a side effect $cpu_id = $val if $key eq 'processor'; $hash{$cpu_id}{$1} = $2; ... } Another option could be to start with '$cpu_id = 0' and increase it as soon as $hash{$cpu_id}{$key} is already defined. $cpu_id++ if exists $hash{$cpu_id}{$key}; $hash{$cpu_id}{$key} = $value; > There are now 2 empty lines that'd need to be stripped out, or I'll be > getting : > > Use of uninitialized value in hash element at ./cpuinfo.pl line 27, > <CPUINFO> line 19. That's the reason I usually write the next unless /match/; my @fields = ($1, $2, ...); Perl's behaviour to leave $nn alone in case the match fails will finally be fixed with 5.8 as far as I remember, but I could mix that up with Perl 6. -- If we fail, we will lose the war. Michael Lamertz | +49 221 445420 / +49 171 6900 310 Nordstr. 49 | [EMAIL PROTECTED] 50733 Cologne | http://www.lamertz.net Germany | http://www.perl-ronin.de -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]