use strict;
use Inline 'SLang';

my $s = get_struct("foo");
print "get_struct() returned a $s - and ref(\$s) = " . ref($s) . "\n\n";
print "Structure contents:\n";

# you can treat $s as a reference to a hash array in most respects, except:
# - the order of the keys in the array matches that of the
#   original S-Lang structure
#
while ( my ( $key, $value ) = each %{$s} ) {
  print "  key $key\t has a value of $value\n";
}
print "\n";

$$s{afield} = 'a changed field value';
print "Key afield now has a value of [$$s{afield}]\n";

__END__
__SLang__

define get_struct(x) {
  variable out = struct { xfield, afield };
  out.xfield = x;
  out.afield = strlen(x);
  return out;
}