Skip to content

Perl_ref

Derek Lamb edited this page Sep 19, 2015 · 3 revisions

Perl ref

A ref in Perl acts like a pointer in C: it describes the location rather than the value of the object it points to. Perl objects include a reference count mechanism, so that objects that are no longer pointed to are garbage-collected automatically. FLUX structured data ("C" structures) can be accessed via a glue layer of refs. Hence you can traverse all the fluxels in a fluxon with a simple Perl loop:

# traverse all the fluxels in a fluxon: for( $fluxel = $fluxon->{start};       defined $fluxel;       $fluxel=$fluxel->{next} ) {    # do something here }

The glue code handles reference counting, so that FLUX simulation data are allocated and de-allocated just as Perl variables would be. Thus, you don't have to handle deallocation -- FLUX variables are cleaned up by the Perl garbage collector just as normal Perl variables would be.