| Dati :: Transformer. attraversare una struttura di dati, alterandola in posizione |
Scarica ora |
Dati :: Transformer. Classifica e riepilogo
- Licenza:
- Perl Artistic License
- Nome editore:
- Baldur Kristinsson
- Sito web dell'editore:
- http://search.cpan.org/~baldur/Cache-BerkeleyDB-0.03/lib/Cache/BerkeleyDB.pm
Dati :: Transformer. Tag
Dati :: Transformer. Descrizione
Attraversare una struttura dei dati, alterandola in posizione Dati :: Trasformatore č un modulo Perl per attraversare una struttura dati, alterandolo in place.synopsis Utilizzare i dati :: Trasformatore; # A: Semplice utilizzo: # Trim Extra Space da stringhe normali all'interno di TA. My $ TRIM = SUB {LOCALE ($ _) = shift; $$ _ = ~ s / ^ s * //; $$ _ = ~ s / s / s / s * $ //; }; My $ T = Data :: Trasformatore-> Nuovo (normale => $ Trim); $ T-> Traverse (TA); # B: utilizzo pił complesso: # (a) maiuscolo tutti i tasti in tutti gli hash contenuti in $ dati # e (b) convertire eventuali array in hashes: my $ uc_hash = sub {my $ h = shift; My @Keys = Keys% h; foreach (@Keys) {My $ UC = UC ($ _); Se ($ UC NE $ _! Esiste ($ h -> {$ uc})) {$ h -> {$ uc} = $ h -> {$ _}; Elimina $ h -> {$ _}; } Elsif ($ UC NE $ _) {Die "Bad Key $ _:" $ UC "esiste gią"; }}}; My $ AR_CONV = SUB {MY% H = @ {$ _ }; restituire sub {\% h}; }; My $ T = Dati :: Trasformatore-> Nuovo (hash => $ UC_HASH, ARRAY => $ AR_CONV, NODE_LIMIT => 500_000); EVAL {$ T-> Traverse ($ dati)}; Warn "Impossibile completare la trasformazione: $ @" Se $ @; # C: traversata non distruttiva # Non devi effettivamente cambiare nulla ... My $ Dimensione = 0; My $ T = Data :: Trasformatore-> Nuovo (normale => Sub {$ Dimensione + = lunghezza ($ {$ _ })}, hash => sub {$ Dimensione + = lunghezza ($ _) per i tasti% { $ _ }},); i miei $ nodi = $ T-> Tranverse (TA); Stampa "Numero di nodi: $ nodi "; Stampa" Dimensione dei tasti + valori: $ Dimensione "; # D: oggetti all'interno di una struttura dati # influenzano gli oggetti utilizzando il nome della classe come chiave: My $ T = Dati :: Trasformatore-> Nuovo ('My :: Class' => Sub {shift-> set_foo (' bar ')}); Requisiti: · Perl.
Dati :: Transformer. Software correlato