[Cologne-pm] 2 hashreferenzen von einer subrutine bearbeiten

Cem Sakaryali cem.sakaryali at easi.de
Fri Sep 23 00:40:11 PDT 2005


Ja das war mein Fehler. Danke Jens :)

Gruss
Cem

On Thu, 2005-09-22 at 22:13 +0200, Jens Gassmann wrote:
> Hi,
> 
> deine subroutinen geben keine Referenzen zurück,
> 
> 
>  > sub CreateHash1 {
>  > $hash1{aa}{bb}=cc;
>  > $hash2{dd}{ee}=ff;
>  > return (%hash1,%hash2);
>  > }
> 
> nach
> 
>   sub CreateHash1 {
>   	
> 	$hash1{aa}{bb}=cc;
> 	$hash2{dd}{ee}=ff;
>   	return ( \%hash1, \%hash2);
>   }
> 
> 
> 
> Dann sollte es auch gehen, und immer beachten! das du Hashes nur als 
> Referenzen übergeben kannst also immer \%hash und nicht %hash, das 
> gleich gibt dir ein Subroutinenaufruf zurück, also auch $hashref !
> 
> Grüsse
> Jens
> 
> Cem Sakaryali wrote:
> > Hallo Jens,
> > 
> > ich bekomme den Inhalt des Hashes nicht geprintet
> > wenn ich 2 hashreferenzen von der sub bekomme.
> > Auch durch Deine Lösung konnte ich den Inhalt nicht
> > printen.
> > 
> > 
> > Gruss
> > Cem
> > 
> > 
> > 
> > Ich habe mal ein beispiel gemacht:
> > 
> > 
> > sub CreateHash1 {
> > $hash1{aa}{bb}=cc;
> > $hash2{dd}{ee}=ff;
> > return (%hash1,%hash2);
> > }
> > 
> > sub CreateHash2 {
> > $hash1{aa}{bb}=cc;
> > return (%hash1);
> > }
> > 
> > 
> > #####################################################funktioniert nicht
> >  ($parameter,$include) = CreateHash1 ($ARGV[0]);
> > 
> >  %hash = %$parameter;
> > 
> >     foreach my $i (keys %hash) {
> >         print "Runname: $i\n";
> >         foreach my $ii (sort keys  %{$hash{$i}}) {
> > 	    print "$ii $hash{$i}{$ii}\n";
> >         }
> >     }
> > 
> > 
> > ########################################################funktioniert
> >  (%hash) = CreateHash2 ($ARGV[0]);
> > 
> >     foreach my $i (keys %hash) {
> >         print "Runname: $i\n";
> >         foreach my $ii (sort keys  %{$hash{$i}}) {
> > 	    print "$ii $hash{$i}{$ii}\n";
> >         }
> >     }
> > 
> > 
> > 
> > 
> > On Thu, September 22, 2005 21:25, Jens Gassmann wrote:
> > 
> >>Hi,
> >>
> >>mir ist noch nicht ganz klar was nun nicht läuft?! Wichtig ist das du
> >>von der Subroutine immer nur Hash-Referenzen zurück bekommst.
> >>
> >>
> >>
> >> >  %hash = %$parameter;
> >> >
> >> >     foreach my $i (keys %hash) {
> >> >         print "Runname: $i\n";
> >> >         foreach my $ii (sort keys  %{$hash{$i}}) {
> >> > 	    print "$ii $hash{$i}{$ii}\n";
> >> >         }
> >> >     }
> >> >
> >>
> >>kannst du auch so schreiben
> >>
> >>      foreach my $i (keys %$parameter) {
> >>
> >>          print "Runname: $i\n";
> >>
> >>          foreach my $ii (sort keys  %{$parameter->{$i}}) {
> >>
> >>		print "$ii $parameter->{$i}{$ii}\n";
> >>          }
> >>      }
> >>
> >>Grüsse
> >>jens
> >>
> >>Cem Sakaryali wrote:
> >>
> >>>Hallo alle,
> >>>
> >>>ich versuche gerade 2 hash referenzen die von einer
> >>>subrutine kommen zu bearbeiten aber es funtioniert leider
> >>>nicht. Dabei handelt es sich um 2dim. hashes die ich in einer
> >>>sub erzeuge.
> >>>
> >>>
> >>># aufruf der sub funktion. Zurück kommen 2 hashes
> >>> ($parameter,$include) = ReadMatrix ($ARGV[0]);
> >>>
> >>> %hash = %$parameter;
> >>>
> >>>    foreach my $i (keys %hash) {
> >>>        print "Runname: $i\n";
> >>>        foreach my $ii (sort keys  %{$hash{$i}}) {
> >>>	    print "$ii $hash{$i}{$ii}\n";
> >>>        }
> >>>    }
> >>>
> >>>
> >>>Die Schleife von oben funktioniert aber wenn ich nur ein hash
> >>>zurückgebe.
> >>>
> >>> (%hash) = ReadMatrix ($ARGV[0]);
> >>>
> >>>   foreach my $i (keys %hash) {
> >>>        print "Runname: $i\n";
> >>>        foreach my $ii (sort keys  %{$hash{$i}}) {
> >>>	    print "$ii $hash{$i}{$ii}\n";
> >>>        }
> >>>    }
> >>>
> >>>
> >>>Hat einer von euch eine Idee, was ich falsch mache?
> >>>
> >>>Gruss
> >>>Cem
> >>>
> >>>_______________________________________________
> >>>Cologne-pm mailing list
> >>>Cologne-pm at pm.org
> >>>http://mail.pm.org/mailman/listinfo/cologne-pm
> >>
> >>_______________________________________________
> >>Cologne-pm mailing list
> >>Cologne-pm at pm.org
> >>http://mail.pm.org/mailman/listinfo/cologne-pm
> >>
> > 
> > 
> > 
> > _______________________________________________
> > Cologne-pm mailing list
> > Cologne-pm at pm.org
> > http://mail.pm.org/mailman/listinfo/cologne-pm
> 
> _______________________________________________
> Cologne-pm mailing list
> Cologne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/cologne-pm



More information about the Cologne-pm mailing list