
почти работает!
не работает:
Код: Выделить всё
#!/usr/bin/perl
sub i { return {666 => 666} }
print %&i;
Код: Выделить всё
Bareword found where operator expected at ./perlp.pl line 5, near "%&i"
(Missing operator before i?)
syntax error at ./perlp.pl line 5, near "%&i"
Execution of ./perlp.pl aborted due to compilation errors.
так работает:
Код: Выделить всё
#!/usr/bin/perl
sub i { return {666 => 666} }
print %{&i};
Код: Выделить всё
$ ./perlp.pl
666666$
как не пробовал не работает:
Код: Выделить всё
#!/usr/bin/perl
sub i {
my $h;
$h->{[666]} = 666;
return {$h}
}
local *i = sub { return '666' }
print %&i;
еще можно сделать на русском:
Код: Выделить всё
#!/usr/bin/perl
sub open_data {
my $handle = shift;
local $/ = ''; # Включить режим чтения абзацев
return <$handle>;
}
sub rus {
for (@_[0]) {
s{печатаем}{print}ig;
s{если}{if}ig;
}
return @_[0];
}
eval rus open_data(*DATA);
die "Exception error: $!" if $@;
# real code:
__DATA__
$i = 5;
печатаем "666" если ($i>4);
еще подсказали так:
Код: Выделить всё
$ cat t.pl
#!/usr/bin/env perl
use utf8;
my $переменная = функция();
print $переменная;
sub функция {
my $один = 1;
my $два = 2;
$один + $два;
}
$ perl -l t.pl
3
может еще как-то можно написать?