Thread View: pl.comp.lang.perl
1 messages
1 total messages
Started by Piecia aka dracorp
Wed, 25 Feb 2015 07:32
tie hash i wantarray dla FETCH
Author: Piecia aka dracorp
Date: Wed, 25 Feb 2015 07:32
Date: Wed, 25 Feb 2015 07:32
32 lines
1841 bytes
1841 bytes
Witam
Mam związany hash z klasą za pomocą tie. Wartości dla tego hasha to tablica dwuelementowa. Pytanie dlaczego dla wantarray* nigdy nie zwraca true dla postaci:
#v+
my @array = $hash{klucz};
#v-
Jedyny sposób żeby pobrać tablicę to:
#v+
tied(\%hash)->FETCH('klucz');
#v-
Na początku myślałem że to wina starego Perla, 5.8.8 ale na nowym jest to samo.
*)
#v+
sub FETCH {
my ( $self, $key ) = @_;
if ( exists $self->{$key} ){
if ( wantarray ){
return @{$self->{$key}};
}
else {
return $self->{$key}->[VALUE];
}
}
return;
}
#v-
--
Pozdrawiam Piotr
piecia aka dracorp
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads