```{index} single: store_fd; Storable function ``` ```{index} single: Storable::store_fd; Perl function ``` # store_fd Serialise a referenced structure in native byte order and write it to an open filehandle. ## Synopsis ```perl use Storable qw(store_fd fd_retrieve); open my $fh, ">", "data.bin" or die $!; store_fd(\%data, $fh); close $fh; ``` ## What you get back Returns `1` on success. Writes a 4-byte length prefix followed by the serialised payload, so multiple frozen structures can be concatenated on the same stream and separated by matching `fd_retrieve` calls. ## Examples Stream multiple records through one filehandle: ```perl open my $fh, ">", "log.bin" or die $!; store_fd($_, $fh) for @events; close $fh; ## reader side: open my $r, "<", "log.bin" or die $!; while (my $ev = fd_retrieve($r)) { ... } ``` ## Edge cases - First argument must be a reference; croaks with `Not a reference` otherwise. - `$fh` must be an open filehandle with a real underlying file descriptor. A closed or non-file handle writes nothing. - Bytes are native-order; use `nstore_fd` for portability. ## Differences from upstream - Upstream writes a header then raw payload; pperl prefixes each payload with a 4-byte little-endian length, enabling concatenation on the same stream. Readers on the pperl side (`fd_retrieve`) understand this framing; upstream readers do not. Pinned by `t/81-xs-native/Storable/080-fd.t`. ## See also - `fd_retrieve` — matching reader. - `nstore_fd` — portable (network-order) variant. - `store` — write to a path instead of an open handle. - `freeze` — return bytes to the caller instead of writing.