my $seg = new Net::HL7::Segment("PID");

$seg->setField(3, "12345678"); print $seg->getField(1);


The Net::HL7::Segment class represents segments of the HL7 message.


$seg = new Net::HL7::Segment($name, [$fields])

Create an instance of this segment. A segment may be created with just a name or a name and a reference to an array of field values. If the name is not given, no segment is created. The segment name should be three characters long, and upper case. If it isn't, no segment is created, and undef is returned. If a reference to an array is given, all fields will be filled from that array. Note that for composed fields and subcomponents, the array may hold subarrays and subsubarrays. Repeated fields can not be supported the same way, since we can't distinguish between composed fields and repeated fields.

setField($index, $value)

Set the field specified by index to value, and return some true value if the operation succeeded. Indices start at 1, to stay with the HL7 standard. Trying to set the value at index 0 has no effect. The value may also be a reference to an array (that may itself contain arrays) to support composed fields (and subcomponents).

To set a field to the HL7 null value, instead of omitting a field, can be achieved with the Net::HL7::NULL type, like:

  $segment->setField(8, $Net::HL7::NULL);

This will render the field as the double quote (""). If values are not provided at all, the method will just return.


Get the field at index. If the field is a composed field, you might ask for the result to be an array like so:

my @subfields = $seg->getField(9)

otherwise the thing returned will be a reference to an array.


Get the string representation of the field


Get the number of fields for this segment, not including the name

getFields([$from, [$to]])

Get the fields in the specified range, or all if nothing specified. If only the 'from' value is provided, all fields from this index till the end of the segment will be returned.


Get the name of the segment. This is basically the value at index 0


D.A.Dokter <>


Copyright (c) 2002 D.A.Dokter. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 248:

You forgot a '=back' before '=head1'