[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] Perl spørgsmål



Michael Rasmussen <sslug@sslug> writes:

> 1) Hvilke fordele/ulemper er der ved at have en attribute (variabel i
> objekt scope) i forhold til en my-defineret i modul scope. Altså:
> $self->{my_var}
> my $var

En variabel defineret i modulescope er global for alle objekter af
klassen. Så hvis du skal kunen bruge flere samtidige instanser af
samme klasse med forskellige værdier, så er en variabel i modulscope
et stort no-go.

Hvis du antager at der altid kun vil være en instans, så sørg for at
det bliver håndhævet, enten ved at lave en singleton-klasse eller ved
at lade konstruktoren fejle hvis der allerede findes en instans af
klassen.

> 2) I ovenstående eksempel ville jeg gerne ændre på default sortering.
> Altså
> sub compare {
>     my ($key1, $key2) = @_;
>     lc $key1 cmp lc $key2 ||
>     $key1 cmp $key2;
> }
>
> $DB_BTREE{'compare'} = \&compare;

Mon ikke dit problem skyldes at du ikke gøre ligesom i dokumentationen? 

DB_File eksporterer ifølge dokumentationen en hashref der hedder
$DB_BTREE. Du sætter en nøgle i en hash der hedder %DB_BTREE. I
eksemplerne står der også tydeligt:

  $DB_BTREE->{'compare'} = \&compare;

DB_File har i øvrigt et gysligt interaface. Her du overevejet at bruge
BerkeleyDB istedet. Det er noget bedre og giver dig mulighed for at
definere en sammenligningsfunktion når du kalder tie og ikek som
global tilstandsvariabel.

//Makholm


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2008-01-01, 17:38 CET [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *