hi hi
ich will aus einer Datei Blöcke auslesen und diese dann in einem hash speicher (hash mit anonymen hash).
der hash soll als key die Part Id und als wert eine referenz, auf eine hash erhalten. das ganze klappt hat :-) mit der einschränkung das der hash nur ein key-wert Paar hat (es müssten 12 sein). im hash ist immer nur die letzte zuweisung.
ich finde meine fehler nicht kann mirjemand weiter helfen??
bis bis roman
__code__
#!/usr/bin/perl -w
use strict;
my $such_zahl='([+-]?(?:\d+[.,]\d+|[.,]\d+|\d+)(?:[eE][+-]?\d+)?)'; # !!später ausbessern!!
my $n=-1;
my (%bom, $part, $part_id, $mat_typ, $dichte, $etyp, $contact_thickness, $thickness_sacle);
my $zeile;
open (DAT, "< demo.txt");
while(defined($zeile=<DAT>)){
if($zeile =~/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/){
$n=3;
undef($part_id);
}
$zeile=~/(\w+)/, $part=$1 if($n==0);
$zeile=~/$such_zahl/, $part_id=$1 if($zeile=~/Part ID/);
$zeile=~/$such_zahl/, $mat_typ=$1 if($zeile=~/material type/);
$zeile=~/$such_zahl/, $dichte=$1*1e6 if($zeile=~/den /);
$zeile=~/$such_zahl/, $etyp=$1 if($zeile=~/element type/);
$zeile=~/$such_zahl/, $contact_thickness=$1 if($zeile=~/contact thickness/);
if($zeile=~/thickness scale/){
$zeile=~/$such_zahl/;
$thickness_sacle=$1;
%bom=($part_id => {'pname' => $part,
'mat_typ' => $mat_typ,
'dichte' => $dichte,
'etyp' => $etyp,
'contact_thickness' => $contact_thickness,
'thickness_sacle' => $thickness_sacle,
});
}
$n-=1;
}
close (DAT);
print %bom;
print "\n\n";
my @anzahl;
my $anzahl;
foreach (keys %bom){
push @anzahl,$_;
$anzahl=@anzahl;
print $_ ."\n";
print $bom{$_};
print "\n";
print $bom{$_}->{pname} ."\n";
}
__CODE__
__demo.txt__
*******************************************************
RB_shell
Part ID ......................... 11
material type .............. 20
den .............................. = 7.8500E-06
element type ..................... = 0
optional contact thickness ....... = 0.0000E+00
optional thickness scale factor... = 0.0000E+00
**************************************************
RB_SOLID
Part ID ......................... 898
material type .............. 20
den .............................. = 7.8500E-06
element type ..................... = 0
optional contact thickness ....... = 0.0000E+00
optional thickness scale factor... = 0.0000E+00
__d3hsp__
print $anzahl ."\n";;__demo.txt__