1

1.In clion:

use strict;
use warnings FATAL => 'all';
use Scalar::Util qw(looks_like_number);
my $todlist="GOTO  /  -71.42857,  -16.00000,  -49.48717,-0.866025, 0.000000,-0.500000";
my @do = split( /\/|,|\s/, $todlist);
my @str=round_num03(@do);
print(@str);
#foreach my $element (@str) {
#    print ($element);
#}
sub round_num03{
    foreach (@_) {
        if ( looks_like_number($_) )
        {
            $_ = sprintf( "|%.3f", $_);
        }
    }
    return @_;
}

I get result:GOTO|-71.429|-16.000|-49.487|-0.866|0.000|-0.500

2.In my emaces org mode,

#+BEGIN_SRC perl  :results value :exports results both
use strict;
use warnings FATAL => 'all';
use Scalar::Util qw(looks_like_number);
my $todlist="GOTO  /  -71.42857,  -16.00000,  -49.48717,-0.866025, 0.000000,-0.500000";
my @do = split( /\/|,|\s/, $todlist);
my @str=round_num03(@do);
#print(@str);
#foreach my $element (@str) {
#    print ($element);
#}
return @str;
sub round_num03{
    foreach (@_) {
        if ( looks_like_number($_) )
        {
            $_ = sprintf( "|%.3f", $_);
        }
    }
    return @_;
}
#+END_SRC

#+RESULTS:
: 16

The result is 16,may be the size of the array.why? And how to return the string .

3
  • Have you tried tangling the code and looking at the diff between the tangled code and your "code". My guess is that there is a difference between both. If not, you may want to check a difference between interpreters
    – Joafigue
    Nov 16, 2017 at 12:56
  • I have resolve it ,just use return "@str" ,and return the whole string.
    – andrew
    Nov 16, 2017 at 13:08
  • Then you hould create a proper solution and accep it for the comunnity's sake
    – Joafigue
    Nov 16, 2017 at 20:59

1 Answer 1

1

I have resolved it .Use

return "@str"

to replace

return @str

Press C-c C-c,It is return the string.

#+BEGIN_SRC perl  :results value :exports results both
use strict;
use warnings FATAL => 'all';
use Scalar::Util qw(looks_like_number);
my $todlist="GOTO  /  -71.42857,  -16.00000,  -49.48717,-0.866025, 0.000000,-0.500000";
my @do = split( /\/|,|\s/, $todlist);
my @str=&round_num03(@do);
return "the reslut is:"."@str";
sub round_num03{
    foreach (@_) {
        if ( looks_like_number($_) )
        {
            $_ = sprintf( "|%.3f", $_);
        }
    }
    return @_;
}
#+END_SRC

#+RESULTS:
| the reslut is:GOTO | -71.429 | -16.0 | -49.487 | -0.866 | 0.0 | -0.5 |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.