Документ взят из кэша поисковой машины. Адрес оригинального документа : http://hea-www.harvard.edu/~dburke/perl-slang/struct_example
Дата изменения: Fri May 9 18:22:50 2003
Дата индексирования: Tue Oct 2 02:33:41 2012
Кодировка:

Поисковые слова: туманность андромеды
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;
}