Ответы на упражнения к главе 2.

1

#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;

use constant PI => 3.141592654;

my $radius = 12.5;
say 2 * PI * $radius;

2

#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;

use constant PI => 3.141592654;

say ‘Input radius:’;

chomp(my $radius = <STDIN>);

say 2 * PI * $radius;

3

#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;

use constant PI => 3.141592654;

say ‘Input radius:’;

chomp(my $radius = <STDIN>);

my $circ = 2 * PI * $radius;

if($radius < 0){
$circ = 0;
}

say $circ;

4

#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;

say ‘input one number:’;

chomp(my $one = <STDIN>);

say ‘input second number:’;

chomp(my $second = <STDIN>);

my $result = $one * $second;

say «$one * $second = $result»;

5

#!/usr/bin/env perl

use strict;
use warnings;
use 5.010;

say ‘input one string:’;

chomp(my $string = <STDIN>);

say ‘input repeat number:’;

chomp(my $number = <STDIN>);

my $result = $string x $number;

say «result is $result»;

Особо запомнилась конструкция вида:

chomp(my $radius = <STDIN>);

Читайте еще:

Рубрики: Разработка