| ���������� | ����������� | �������� | ������
| ����� 1 | ����� 2 | ����� 3 | ����� 4 | ����� 5 | ����� 6 | ����� 7 | ����� 8 | ����� 9 | ����� 10
| ����� 11 | ����� 12 | ����� 13 | ����� 14 | ����� 15 | ����� 16 | ����� 17 | ����� 18 | ����� 19
| ���������� � | ���������� � | ���������� � | ���������� � |

���������� �

    � ���� �����:


������ � �����������

� ���� ���������� ���� ������ � �����������, ���������� � ����� ������ �����.

����� 2 "��������� ������"

1. ��� ���� �� �������� ������� ���� ������:

$pi = 3.141592654;

$result = 2 * $pi * 12.5;

print "radius 12,5 is circumference $result\n";

������� �� ����������� ��������� (����� �) ��������� ���������� $pi. ����� �� ��������� ����� ����������, ��������� �������� $pi � ���������, �, �������, ������� ���������, �������� ������, ���������� ������ �� ����.

2. ��� ���� �� �������� ������� ���� ������:

print "What is the radius: ";

chomp($radius = <STDIN>) ;

$pi = 3.141592654;

$result = 2 * $pi * $radius;

print "radius $radius is circumference $result\n";

��� ������ �� ���������� ������, �� ����� �� ��������� ������������, ������������ ��������� (�������� ��� ������ ����������� �������� print), ������ ��������. ���������� ������ � ��������� �������������� ����������� �������� <stdin>.

���� �� �� ������ ��������� ������� chomp, �� �������� �� ������� ���������� ������ ������ ����� ������. ����� ��� ����� ������� ��������� ���� ������ �� ������.

3. ��� ���� �� �������� ������� ���� ������:

print "First number: "; chomp($a = <STDIN>) ;

print "Second number: "; chomp($b = <STDIN>) ;

$c = $a * $b; print "Answer is $c.\n";

������ ������ ������ ��� ����: ���������� ��� ������ �����, ��������� ������ �� ������������ �����, � ����� ����������� �� ����������� ������� ����� ������. ��������� �� ���������� �������� $� ������ ��� �����, ������� chomp ����� ����� ��������, ������ ��� � �������� ��������� 45\n � ��� 45. ������ ����� ��������� ���������������� ����� ������������ ���������� �������������� (��������, ���� ����� ����� �������� $� � ���������).

������ ������ ������ �� �� ����� �� ������ ������ � �������� ��� � ��������� ���������� $�.

������ ������ ����������� ��� ��� ����� � ������� ���������. �������� ����� ������� ������� ����� ������ � ����� ������ (����� ��� � ������ ���� ������� �� �����������). ������ ��� ��������� � ��� �����������, � ����� �� ������� ������������ ������ ������ ����� � ��� �� ������. ��������� ��������� � ��� ��������; ���� �� �� ��������� ������ ����� ������, �� ����� �� �� ���������� ��������� �� ����������� shell. He �����-�� ������.

4. ��� ���� �� �������� ������� ���� ������:

print "String: "; $� = <STDIN>;

print "Number of times: "; chomp($b = <STDIN>) ;

$c = $a x $b; print "The result is:\n$c";

��� � ���������� ����������, ������ ��� ������ ����������� �������� ���� ���������� � ��������� ��. ������ ����� �� �� ����������� ������ ����� ������, ������ ��� �� ��� �����! ������ ������ �������� ��������� �������� � ��������� ��� ���� �������� ������������� ���������� �����, � ����� ������� �����. �������� �������� �� ��, ��� �� ����������� ���������� $� � ��������� print ��� ������� ����� ������, ��������� �� �������, ��� $� � ����� ������ ������������� ���� ��������.

����� 3 "������� � ��������� ������"

1. ��� ���� �� �������� ������� ���� ������:

print "Enter the list of strings:\n";

@list = <STDIN>;

Sreverselist = reverse @list;

print @reverselist;

������ ������ ���������� ������ ������. ������ ������ ��������� ��� ������ � ����������-������. ������ ������ ��������� ������ � �������� �������� ������������ ��������� � ������� ��� � ������ ����������. ��������� ������ ������� ���������.

��������� ��� ������ ����� ����������:

print "Enter the list of strings:\n";

print reverse <STDIN>;

���� ��� �������� ���������� �����������, ��� ��� �������� print ������� ����� ������, � �������� reverse ���������� ������. ����� �������� reverse ����� ������ �������� ��� ��������������, � �������� <stdin>, ����������� � ��������� ���������, ���������� ������ ����� � � ��� �������� �����������!

2. ��� ���� �� �������� ������� ���� ������:

print "Enter the line number: "; chomp($a = <STDIN>) ;

print "Enter the lines, end with "D:\n"; @b = <STDIN>;

print "Answer: $b[$a-l]";

������ ������ ���������� ������ �����, ��������� ��� �� ������������ ����� � ������� ���������� ������ ����� ������. ������ ������ ����������� ������ �����, � ����� � ������� �������� <stdin> � ��������� ��������� ��������� ��� ��� ������ (�� ��������� �������� ����� �����) � ����������-������. ��������� �������� ������� �����, ��������� ��� ������ ��������������� ������ ������ �� ������. �������� ��������:

��� �� ����� ��������� ������ ����� ������ � �����, ������ ��� ������, ��������� �� ������� @�, ��� ������������� ����� ��������.

���� �� ���������� ��������� ��� ��������� � ���������, ������������������ ����� ������� �������, ��� ����� ����� ������ ������� [Ctrl+D], ����� ���������� ����� �����.

3. ��� ���� �� �������� ������� ���� ������:

srand;

print "List of strings: "; @b = <STDIN>;

print "Answer: $b[rand (@b)]";

 

������ ������ ��������� ��������� ��������� �����. ������ ������ ��������� ������ �����. ������ ������ �������� ��������� ������� �� ���� ������ � ������� ��� �� �����.

����� 4 "����������� ���������"

1. ��� ���� �� �������� ������� ���� ������:

print "What temperature is it? ";

chomp($temperature �� <STDIN>);

if ($temperature > 72) {

print "Too hot!\n";

} else (

print "Too cold!\n";

>

������ ������ ���������� ������ �����������. ������ ������ ��������� ��������� �������� �����������. �������� if � ��������� ���� ������� �������� ��� ������ ���� �� ���� ��������� � ����������� �� �������� ���������� $temperature.

2. ��� ���� �� �������� ������� ���� ������:

print "What temperature is it? ";

chomp($temperature = <STDIN>) ;

if ($temperature > 75) (

print "Too hot!\n";

} elsif ($temperature < 68) (

print "Too cold!\n";

) else {

print "Just right!\n";

1

����� �� �������������� ���������, ����� �������������� �����. ������� ����������� ������������ �� ��������� 75, ����� �� ��������� 68. �������� ��������: ��� ������ ������� ��������� ����� ����������� ������ ���� �� ���� ���������.

3. ��� ���� �� �������� ������� ���� ������:

print "Enter a number (999 to quit): ";

chomp($n = <STDIN>) ;

while ($n != 999) f

$sum += $n;

print "Enter another number (999 to quit): ";

chomp($n = <STDIN>);

1 print "the sum is $sum\n";

 

������ ������ ���������� ������ ������ �����. ������ ������ ��������� ��� ����� � ���������. ���� while ���������� ����������� �� ��� ���, ���� ����� �� ������ ������ 999.

�������� += ����������� ����� � ���������� $sum. �������� ��������:

��������� �������� ���� ���������� � undef, ��� ����� ������ ��� ���������, ������ ��� ������ ������������ �������� ����� ���������� ������������ � ���� (�������, ��� ��� ������������� � �������� ����� undef ����� ����).

� ���� ����� �� ������ ����������� � ��������� ��� ���� �����, ����� �������� � ������ ����� ������������� �� ����� ���������� �����.

����� ������ �� ����� ��������� ������� ����������� ����������.

���� ����� �� ������ 999, �� �������� ���������� $sum ����� ����� �� ����, � ������ ������ � �.�. �������� undef � ��������� ���������. ���� �� ������, ����� ��������� � ���� ������ �������� ����, ����� � ������ ��������� ���������������� �������� $s urn ��������� $ sum = 0.

4. ��� ���� �� �������� ������� ���� ������:

print "Enter some strings, end with "D:\n";

@strings = <STDIN>;

while (Ostrings) (

print pop @strings;

}

������� ��������� ����������� ������. ��� ������ ����������� � ����������-������� @strings (�� ����� �� �������).

����������� ��������� ����� while � Sstrings. ��� ����������� ��������� ���� ������ ���� �������� ("������" ��� "����"), ������� ��������� ��������� � ��������� ���������. ��� ������� (����� ��� @ strings) ��� ������������� � ��������� ��������� ������������ ����� ���������� ���������, ����������� � ������� � ������� ������. ��������� ������ �� ����, ��� ����� �� ����� ���� �, �������������, ����� �������� "������". ��� ������ ����� ������ ������������ � Perl, ��� ������������� �������� "������ ���, ���� ������ �� ����".

���� ����� ������� ��������, ���������� ����� "������������" �������� ������ �������� �������. �������������, ��������� ���� ������� ���������, ��� ������ ���������� ����� ������ ���������� �� ���� ������� ������.

��������, ��� ������ � ������ ����� ������������ ��� ������� ������ ������ �������. �������������, ��� ������ ����� ������ ����������� ���������, ������ � ���������� ��������� Perl-������� ������� ����������� �����, ��� ����� ������ ��������� ������ �����.

 

5. ��� ���� �� �������� ������� ���� ������ ��� ������������� ������:

for ($number = 0; $number <= 32; $number++) {

$square = $number * $number;

printf "%5g %8g\n", $number, $square;

}

� ��� ��� ����� ������ ������ � ������� ������:

foreach $number (0..32) (

$square = $number * $number;

printf "%5g %8g\n", $number, $square;

}

� ����� �������� ����������� ����� � �������������� ���������� for � foreach. ���� ���� ������ ���������, ������ ��� � ����� �������� �������� ���������� $ number ��� ������ �������� ���������� �� 0 �� 32.

� ������ ������� ����������� ������������ �-�������� �������� for. ������ ��������� ������������� ���������� $number � 0, ������ ���������, ������ �� $number, ��� 32, � ������ �������������� $number ��� ������ ��������.

�� ������ ������� ����������� �������� foreach, �������� ������������ ��������� C-shell. � ������� ������������ ������ ��������� ������ �� 33 ��������� (�� 0 �� 32). ����� ���������� $number ���������� ������������� ��������, ������ ���� ���������.

����� 5 "����"

1. ��� ���� �� �������� ������� ���� ������:

%map = qwfred apple green leaves blue ocean);

print "A string please: "; chomp($some_string = <STDIN>);

print "The value for $some_string is $map($some_string(\n";

������ ������ ������� ��� �� ��������� ��� ����-��������. ������ ������ �������� ������, ������ ������ ����� ������. ������ ������ ������� �� ����� ��������� ������ � ��������������� �� ��������.

���� ��� ����� ������� � � ������� ����� ��������� �������� ������������:

$map('red') = 'apple';

$map('green'( = 'leaves';

$map('blue'} = '�����',-

2. ��� ���� �� �������� ������� ���� ������:

chomp(Swords = <STDIN>); # ������ ����� ����� ������� ����� ������ foreach $word (@words) (

$count{$word} = $count($word} + 1; # ��� $count{$word}++ t foreach $word (keys %count) {

print "$word was seen $count($word) times\n";

}

������ ������ ��������� ������ � ������ @ words. ���������: � ���������� ���������� ���� �������� ������ ������ ���������� ��������� ��������� �������, ������ ������ ����� ������ ��������� ����������.

� ��������� ������� ������� �������������� ����� �������, ��� ���� $word �������������� �� ������� ������ ������. ������� chomp �������� ������ ����� ������, � ����� ���������� ����������. ������ ����� ������������ ��� ���� ����. �������� ��������, ���������� �� ����� ����� (�����), ������������ ����� �������� �������� ���������� ������� ����� �� �������� �������. ������� � ���� ��������� ���, ������� ���� ����� wild ����������� � ������ ������, �� $count {"wild"} ����� ��������� undef. ��� �������� undef ���� ������� ����������� ������ ���� ���� �������, �� ���� �������. (��������, ��� ��� ������������� � �������� ����� undef �������� ����.) ��� ��������� ������� � ��� ����� ������� ���� �������, ��� ���, � �.�.

������ ���������������� ������ ������� ���� �������� ����������-������� �������� � �����������. ������� Perl-������������ ������ ���������� �������� (�� �������� ��� "����������") � ������� �� ����� ���� � �� �� ������ �� ��� � ����� ������ �������� ������������, ���� ����� �������� ����������������������.

����� �������� ���� � ��������� ���������� ������� ��������� �������������� �������� ���� � ����������� ��������� ���� ��� ������. ����� ���������� ���������� �������� ��� ���� � ��������������� ��� �������� ��������� �� �����.

���� � ������ �������, ������������ �� ���������� ������ ���, ��� ����� ������ keys � ������� � ����� ������ ��������� �������� sort. ��� ���������� �������� ���������� ��������� ��������� ������� ��������� � ���������������. ����� ���������� ��� ��������������� � ���������� �������������. (����� � ����� ��������� �������� keys ��� ����������; ��� ������� �������� sort ��������������� ����� keys ��������� ��������� ����� � ��� �� ��� ������� ������ ���� ������������ ����������.)

 

����� 6 "������� �������� �����-������^

1. ��� ���� �� �������� ������� ���� ������:

print reverse �;

���, ����� ����, ������ ��������� ����� ������, �� ��, ��� �� �����, �����. ��� ��� �������� ���� ��������:

�) ������� ������� reverse ���� ������ ����� ����������. ��� ������, ��� �������� "����" (�) ����������� � ��������� ���������. �������������, ��� ������ ������, ��������� ��� ��������� ��������� ������ (��� ������, ����������� �� ������������ �����, ���� ���������� ���), ����������� � ������������� � ������, ������ ������� �������� ������� �� ����� ������.

�) ����� ������� reverse ������ ������� ���������� ��������� ������ �� ��������.

�) �������, ������� print �������� ������-��������� � ������� ���. �. ��� ���� �� �������� ������� ���� ������:

print "List of strings:\n";

chomp(@strings = <STDIN>) ;

foreach (@strings) (

printf "%20s\n", $_;

)

������ ������ ���������� ������ ������ �����.

��������� ������ ��������� ��� ������ � ���� ������ � ����������� �� �������� ����� ������.

� ����� foreach �������������� ������ �� ����� ������� � ����������� ���������� $_ �������� ������ ������.

������� printf �������� ��� ���������. ������ �������� ���������� ������ "%20s\n", ������� �������� 20-���������� ������� � ������������� ������ � ������ ����� ������.

3. ��� ���� �� �������� ������� ���� ������:

print "Field width: ";

chomp($width = <STDIN>) ;

print "List of strings:\n";

chomp(@strings = <STDIN>);

foreach (@strings) (

printf "%$(width}s\n", $_;

}

� �������, ������ � ���������� ������, �� �������� ����������� ������ ������ ���� � ����� �� ����.

���� ��� ���� ���������: ������ ������� printf ������ �������� ������ �� ����������. �������� ���������� $width ���������� � ��� ������ �� ����, ��� printf ���������� ������ ������. �������, ��� �� �� ����� �������� ��� ������ ���

printf "%$widths\n", $_; #WRONG

������ ��� ����� Perl ����� �� ���������� � ������ $ widths, � �� ���������� � ������ $width, � ������� �� ���������� ����� s. ��-������� ��� ����� �������� ���:

printf "%$width"."s\n", $_; * RIGHT

������ ��� ������ ����� ������ ��������� ����� ��� ����������, ������� ��������� ������ �� ������������� � �����.

����� 7 "���������� ���������"

1. ��� ��������� ��������� �������:

�) /�+�*/

�) /\\*\**/ (��������, ��� �������� ����� ����� �������� �������� ���������� �� ��� ������������ �������.)

�) / ($whatever) {3} / (�� �������� ��� ������� ������, ����� ��������� ����� ����������� ������ �� ��������� ������ $whatever; ���� ������� �� �������� ����� � ��� ������, ���� $whatever �������� ����������� �������.)

�) /[\000-\377] (5}/ ��� /(. |\�) (5)/ (������������ ����� ��� �������������� ������ ����� ������, ������ ��� ��� �� ������������� ������� ����� ������.)

�) / ( l \s) (\s+) (\s+\2)+ (\s | $) / (\s � ��� �� ���������� ������, � \2 � ������ �� ���, ��� ���� "�����"; ���� " ��� �������������� ���������� ������ �����������, ��� \s+ ���������� �� ������� ����������� �������.)

2. �) ��� ���� �� �������� ������� ���� ������:

while (<STDIN>) {

if (/a/i && /e/i &S /i/i &S /o/i && /u/i) ( print;

)

����� � ��� ��������� ���������, ��������� �� ���� �������� �������������. ��� ��� �������� ��������� ���������� ���������� $_, ���� ����������� ��������� ����� while �������� ������ ������. ��������� ���� �������� "������" ���� � ��� ������, ���� ����� ������� ��� ���� �������.

�������� ��������: ���� ����� �� ���� ������� �� ��������������, ��������� ����� ��������� ������������, ������ ��� �������� && �� ��������� ���� ������ ��������, ���� �������� ������ ��������� � "����".

�) ��� ���� ������:

while (<STDIN>) (

if (/a.*e.*i.*o.*u/i) ( print;

} )

���� �����, ��� �����������, �����. ����� � ��� � ��������� if ������������ ����� ������� ���������� ���������, ������� ���� ���� ������� � ��������� ������������������, ����������� ����� ����������� ��������.

�) ��� ���� �� �������� ������� ���� ������:

while �STDIN� (

if (/"[eiou]*a[iou]*e[aou]*i[^aeu]*o[aei]*u["aeio]*$/i) ( print;

> )

�������� ��������, �� ��������. ����� �������� �����, ������ ���������: "��� ����� ������ ����� ������� ������ � ������ ������ �?", � ����� "��� ����� ������ ����� ������ ������ � � ������ ������ �?". � ����� ������ ��� ������� ����, �� ��� ����������� ������� ������.

3. ��� ���� �� �������� ������� ���� ������:

while (<STDIN>) {

chomp;

($user, $gcos) = (split /:/)[0,4];

($real) = split (/,/, $gcos) ;

print "$user is $real\n";

}

�� ������� ����� while ������������ ���������� �� ����� ������ �� ����� ������� � ���������� $_. �� ���������� ��������� ������ ���� �����������.

������ ������ ���� ����� while �������� ��������� ������ �� ��������� ���������� � �������������� � �������� ����������� ���������. ��� �� ���� ���� �������� ��������� � ��������� ��������� ���������� � �������� ����� (�� ��������) �������.

���� GCOS (����� ����) ����� ����������� �� ����� � �������������� � �������� ����������� ������� �������, � ������-��������� ������������� ����� ��������� ����������, ����������� � ������� ������. ��� ������ ������ ������ ���� � ��� ���������, ��� �������� ������������ ������ ���� �� ���������, � ��� �������. ��������� ���������� $���1 �������� ������ ������� ������-����������, � ��������� �������� �������������.

�������� print ����� ������� ���������� �� �����.

4. ��� ���� �� �������� ������� ���� ������:

while (<STDIM>) (

chomp;

($gcos) = (split /:/)[4];

($real) =split(/,/, $gcos);

($first) � split(/\s+/, $real);

$seen($first>++;

} foreach (keys %seen) (

if ($seen($_) > 1) {

print "$_ was seen $seen($_) times\n";

) }

���� while �������� �� ������ ��� ��, ��� ���� while �� ����������� ����������. ������ �������� ������ �� ���� � ���� GCOS �� �������� ��� (� ������ ����������), � ���� ����� �������������� ����� ��������� ��������� ����� �� ���������� ��� � ��������� �����. ����� ����������� ����� ������� ���� � %seen ����������������, ������� ��� ����, ��� �� ����� ���������� ���. �������� ��������: �������� print � ���� ����� �� ������������.

� ����� foreach �������������� ������ �� ���� ������ ���� %seen (������ �� ����� �������) � ������������� ������� �� ��� �� ������� ���������� $_. ���� ��������, ���������� � %seen �� ������� �����, ������ 1, ������, ��� ��� ��� �����������. �������� if ���������, ��� �� ���, � ��� ������������� ������� ��������������� ���������.

5. ��� ���� �� �������� ������� ���� ������:

while (<STDIN>) (

chomp;

($user, $gcos) = (split /:/)[0,4];

($real) = split /,/, $gcos;

($first) = split (/\s+/, $real);

$seen($first) .= " $user";

}

foreach (keys %names) (

$this == $names{$_);

if ($this =~ /. /) {

print "$_ is used by:?this\n";

} }

 

��� ��������� ������ �� ����� � ����������� ����������, �� ������ ���� ����� ������ ������������, ������� ��� � ��� ����������� ������������ ���, �� ������������ ��������������� ��� ������������ � �������� ���� % names, �������� ��� � �������� �����. ���, ��� ����� �������� (��������������� ��� mrrogers) $names {"Fred"} ���������� ������ " mrrogers", � ����� ���������� ���� ���������� (��������������� ��� fred), $names ( "Fred" } ���������� ������ " mrrogers fred". ����� ���������� ����� � ��� ������� ������ ���� � ������ ��������������� ���� ���� ������� ������ ��� �������������.

� ����� foreach, ��� � � ������ � ����������� ����������, �������������� ������ �� ����������� � ���������� ����, �� ������ ����, ����� ���������, ������ �� ������� �������� �������� ����, �� ������ ���������, ���� �� � ���� �������� ����� ������ ���������������� �����. ��� ����� ����� ������� �������� � ��������� ���������� $this � ����������, ���� �� � ��� ����� ������-������ ������� ������. ���� ����, �� ������ ��������� ����� ������������� ��������� ��������������� ����, ������� � ����������� � ���������� � ���������� ���������.

����� 8 "�������"

1. ��� ���� �� �������� ������� ���� ������:

sub card {

my %card_map;

@card_map(l..9} = qw (

one two three four five six seven eight nine );

my($num) = @_;

if ($card_map($num}) {

return $card_map($num};

) else (

return $num;

) } # driver routine:

while (0) {

chomp;

print "card of $_ is ", &card($ ), "\n";

)

������������ scard (��������� ��� ������, ��� ��� ���������� �������� �� ���������� ����� ��� ������� �����) ���������� � ������������� ����-���������, ������� ���������� %card_map. �������� ��� ������������� ���, ���, ��������, $card_map {6} ����� six; ��� ������ �������������� ���������� �������.

� ������� ��������� if �� ����������, ����������� �� �������� ��������� ���������, ��������� ��� ����� � ����: ���� � ���� ������� ��������������� �������, �������� ���� �������� "������", � ������ �������, ���������� ��������������� ������ ������������, ������������. ���� ���������������� �������� ��� (��������, ����� $num ����� 11 ��� -4), �� ����� � ���� ���������� �������� undef � ����������� ����� else ��������� if, ��������� �������� �����. ���� ����, ���������� ���������� if, ����� �������� ����� ����������:

$card map($num) || $num;

���� �������� ����� �� | | �������, �� ��� � �������� ����� ���������, ������� ����� � ������������. ���� ��� ����� (��������, ����� �������� ���������� $num �������� �� ���������), �� ����������� ������ ����� �������� | |, ��������� �������� $num.

������������-������� ��������������� �������� ������, �������� ������� ����� ������ � �������� �� �� ����� � ��������� &card, ������ ���������.

2. ��� ���� �� �������� ������� ���� ������:

sub card ( ...; } # �� ����������� ������ print "Enter first number: ";

chomp($first = <STDIN>) ;

print "Enter second number: "; , chomp($second = <STDIN>) ;

$message = card($first) . " plus " .

card($second) . " equals " .

card($first+$second) . ".\n";

print "\u$message";

������ ��� ��������� print ���������� ������ ��� �����, � ���������, ��������� ����� �� �� ����, ��������� ��� �������� � $first � $second.

����� ����� ������������ ������ &card � �� ������ ���� ��� ������� �������� � ���� ��� ��� ����� � ����������� ������ $message.

����� ������������ ��������� ��� ������ ������ � ������� �������� \� ����������� � ������� �������. ����� ��������� ��������� �� �����.

3. ��� ���� �� �������� ������� ���� ������:

sub card f

my %card_map;

@card_map(0..9} = qw (

zero one two three four five six seven eight nine );

my($num) = @_;

my($negative) ;

if ($num < 0) {

$negative = "negative ";

$num = - $num;

) if ($card_map($num)) (

return $negative . $card_map($num};

} else (

return $negative . $num;

)

����� �� �������� ������ %card_map, ����� �������� ��� ��������.

������ �������� if ����������� ���� ���������� $num � ����������� ���������� $negative � �������� �������� ����� negative, ���� ���������� � �������� ��������� ����� ������ ����. ����� �������� ��������� if �������� $num ������ ���������������, �� ��� ���� � ���������� $negative ������������ ������ negative, ������� � ���������� ������������ ��� �������.

������ �������� if ����������, ��������� �� �������� ���������� $num (������ �������������) � ����. ���� ��, �� ���������� � ���������� �������� ���� �������������� � ��������, ������� �������� � $ negative, � ������������. ���� ���, �� ��������, ������������ � $negative, �������������� � ��������� �����.

��������� �������� if ����� �������� ����������:

$negative . ($card_map{$num) || $num) ;

����� 9 "������������� ����������� ��������� "

1. ��� ���� �� �������� ������� ���� ������:

sub card (} # �� ����������� ����������

while � ( ## ����� ##

print "Enter first number: ";

chomp($first = <STDIN>) ;

last if $first eq "end"; ## ����� ##

print "Enter second number: ";

chomp($second = <STDIN>) ;

last if $second eq "end"; ## ����� ##

$message = Scard ($first) . " plus " .

card($second) . " equals " .

card($first+$second) . ".\n";

print "\u$message";

} ## ����� ##

�������� �������� �� ��������� ����� while � ���� �������� last. ��� ���-��!

����� 10 "����������� ������ � �������� ������"

1. ��� ���� �� �������� ������� ���� ������:

print "What file? ";

chomp($filename = <STDIN>);

open(THATFILE, "$filename") ||

die "cannot open Sfilename: $!";

while (<THATFILE>) (

print "$filename: $_"; # ��������������, ��� $ ������������� \� }

� ������ ���� ������� ������ ����������� ������ ��� �����, ������� ����� ����������� � ������������ � hat file. ���������� ����� ����� ����������� � ������� ����������� � ��������� � stdout.

2. ��� ���� �� �������� ������� ���� ������:

print "Input file name: ";

chomp($infilename = <STDIN>);

print "Output file name: ";

chomp($outfilename = <STDIN>);

print "Search string: ";

chomp($search = <STDIN>);

print "Replacement string: ";

chomp($replace = <STDIN>);

open(IN,$infilename) II

die "cannot open $infilename for reading: $!";

## �������������� �������� ������������� �����

## $outfilename

die "will not overwrite $outfilename" if -e $outfilename;

open (OUT,"$outfilename") ||

die "cannot create $outfilename: $!";

while (<IN>) { # ������ ������ �� ����� IN � $_

s/$search/$replace/g; # change the lines

print OUT $_; # ������� ��� ������ � ���� OUT ) close (IN);

close (OUT) ;

��� ��������� �������� �� ��������� ����������� ������, ��������� ���� � ���� �����. � ����� ������������ ����� ��������� ����������� ������� ������ � ������� ����������� � �������� ����� while, � ����� �������� ����������� ����������� ��� ������������� �����.

�������� �������� �� ��, ��� �������� ������ � ���������� ��������� ��������, � ��� ��������� � ������ � ���������� ������ � ���.

3. ��� ���� �� �������� ������� ���� ������:

while (�) (

chomp; t ������� ������ ����� ������

print "$_ is readable\n" if -r;

print "$_ is writable\n" if -w;

print "$_ is executable\n" if -x;

print "$_ does not exist\n" unless -e;

}

��� ������ ���������� ����� while �������� ��� �����. ����� �������� ������� ����� ������ ���� ����������� (� ������� ��������� ����������) �� ������� ��������� ���� �������.

4. ��� ���� �� �������� ������� ���� ������:

while (<>) (

chomp;

$��� = -�;

if ($oldest_age < $���) ( $oldest_name = $_;

$oldest_age = $���;

} > print "The oldest file is $oldest_name ",

"and is $oldest age days old.\n";

������� �� ��������� ���� ��� ������� ������������ ����� �����. ������ ����� ������ �������������, � ����� � ������� �������� -� ����������� ������� ����� � ����. ���� ������� ��������� ������� ������ ������� �� ������, ������� �� �� ��� ��� ������, �� ���������� ��� ����� � ��� �������. ������������� $oldest_age = 0, ������� �� ������������ �� ��, ��� ������� ���� �� ���� ����, ������� �������� ������ 0 ����.

�� ���������� ����� �������� print ������ �����.

����� 11 "�������"

1. ��� ���� �� �������� ������� ���� ������:

open(PW,"/etc/passwd") II die "How did you get logged in?";

while (<PW>) (

($user,$uid,$gcos) = (split /:/)[0,2,4];

($real) � split /,/,$gcos;

write;

(

format STDOUT =

@�<�� @>��> @���������������

$user, $uid, $real

 

������ ������ ��������� ���� �������. � ����� while ���� ���� �������������� ���������. ��� ���� ����� ����� ���� ��������� ��������� ����������, ������ ������ ����������� �� �����; � �������� ����������� ������������ ���������. �������� ��� ������������ ���������� �� ���� GCOS. ��������� �������� ����� while �������� ������� write ��� ������ ���� ������.

������ ����������� ����� stdout ���������� ������� ������ � ����� ������. �� �������� ������� �� ���� ��������� ����������, �������� ������� ������������� � ����� while.

2. ��� ���� �� �������� ������� ���� ������:

# ��������� � ��������� �� ������ ������... format STDOOT_TOP = Username User ID Real Name

���, ��� ����� ��� ���������� � ���������� ��������� ���������� �������,� ��� �������� ������ ������ ��������. ��������� ���������� �� �������� ��������� � �������.

����� ��������� �������, �� ����������� ����� ������� stdout �, ��������� � ����� ��������� ��������� ����� ������, �������� ���� @<� ������� ====.��� ����� ������� ��������� ������������� ������������� ������������ ����� �������� � ���������� �����������.

3. ��� ���� �� �������� ������� ���� ������:

# ��������� � ��������� �� ������ ������.. . format STDOUT_TOP = Page @<� $%

Username User ID Real Name

����� ��� ��������� ���������� ������� �� �����-���� ����� ������ ������ ��������. ���� ������ �������� ����� ������ �� ���������� $%, ������� ������������� ����������� �������� �����.

����� 12 "������ � ���������"

1. ��� ���� �� �������� ������� ���� ������:

print "Where to? ";

chomp($newdir = <STDIN>) ;

chdir($newdir) II die "Cannot chdir to $newdir: $!";

foreach (<*>) { print "$_\n";

}

� ������ ���� ������� ������������� � ����������� ��� ��������.

� ������� ������� ������ �� �������� ������� � ������� � ��������� ������. � ������ ������� ��������� �������� �����������.

� ����� foreach �������������� ������ �� ������. �� ��� ��� �� ������? ��� ������������� � ��������� ���������, � ���������� �������� �� ������� ������ ���� ���� ������, ����������� � �������� (� ������ ������ �� ����� ��� *).

2. ��� ���� �� �������� ������� ���� ������ � � ������� ����������� ��������:

print "Where to? ";

chomp ($newdir = <STDIN>) ;

chdir($newdir) ||

die "Cannot chdir to $newdir: $!";

opendir(DOT,".") |I

die "Cannot opendir . (serious dainbramage): $!";

foreach (sort readdir(DOT)) { print "$_\n";

) closedir(DOT) ;

��� ��, ��� � ���������� ���������, �� ����������� ����� �������. ������� � ���� ����������� ������� chdir, �� ��������� �������, �������� ���������� �������� dot. � ����� foreach ������, ������������ �������� readdir (� ��������� ���������) �����������, � ����� ��������������� � ������������� ���������� $_ �������� ������� ��������.

� ��� ��� ������� ��� � ������� �������������:

print "Where to? ";

chomp($newdir = <STDIN>) ;

chdir($newdir) || die "Cannot chdir to $newdir: $!";

foreach (sort <* .*>) ( print "$_\n";

)

��, ���, �� ���� ����, ��� ���� ��������� �� ����������� ����������, �� �� �������� ����� ��������� ������������� �������� sort � ��������� ������� ��������� .*, ����� ����� �����, ����� ������� ���������� � �����. �������� sort ��� ����� �� ��� �������, ��� ���� !fred ������ ������ ����� ��������� �������, a barney ������ ���, �� �������� �������, ������������ ���������� �� � ����� ������� ��� ������ shell, ���.

����� 13 "��������������� ������� � ����������ff

1. ��� ���� �� �������� ������� ���� ������:

unlink @ARGV;

��, ������ ���. ������ @argv � ��� ������ ����, ���������� ��������. �������� unlink �������� ������ ����, ������� ��� ����� ���� ��������� ��� ���� ����������, � ���� �������.

�������, ����� �� ���������� �� �������� ����������� �� �������, �� ����� -f � -i, �� ������ �������� ����, �� ��� ���� �� ��� ������� ��������. ���� �� ��� ������� � �������!

2. ��� ���� �� �������� ������� ���� ������:

($old, $new) � @ARGV; # ������� ��

if (-d $new) ( # ����� ��� � �������, ��� ����� ���������������� ($basename = $old) =~ s#.*/##s; # �������� �������� ����������

# �������� $old $new .= "/$basename"; # � �������� ��� � ������ ����� > rename($old,$new) [| die "Cannot rename $old to $new: $!";

������� ������� � ���� ��������� � ��������� ������, �� ��� ��������� ���� ����� �� ��� ������, ���� ����� ��� ����������� ��������.

������� �� ���� ��������� ����� ���� ��������� ������� oargv. �����, ���� ��� $new � �������, ��� ����� ���������������� ���, ������� � ����� ������ ����� ���������� ��� �������� $old. ��� ������, ��� �������������� /usr/src/fred/etc ���������� �������� � �������������� /usr/src/fred/etc/fred.

�������, ����� ���������� ���������� ����� �������� �� ��������� ������ ������� rename.

3. ��� ���� �� �������� ������� ���� ������:

($old, $new) = 3ARGV; # ������� ��

if (-d $new) ( # ����� ��� � �������, ��� ����� ���������������� ($basename = $old) =~ s#.*/##s; # �������� �������� ����������

# �������� $old $new .= "/$basenaroe"; # � �������� ��� � ������ ����� } link($old,$new) || die "Cannot link $old to $new: $!";

��� ��������� ��������� ���������� ��������� �� ����������� ����� ��������� ������, ������ ��� �� ������� ������, � �� ��������� ��������������.

4. ��� ���� �� �������� ������� ���� ������:

if ($ARGV[0] eq "-s") ( # ����� ������������� ������ ;

$symlink++; # ��������� shift(@ARGV); # � ��������� ���� -s

> � � ! � .. , . ' .' . ($old, $new) = @ARGV; * ������� ��

if (-d $new) ( # ����� ��� � �������, ��� ����� ����������������

($basename = $old) =~ s#.*/##s; # �������� �������� ���������� # �������� $old

$new .= "/$basename"; # � �������� ��� � ������ ����� > if ($symlink) ( # wants a symlink

symlink($old,$new) ;

) else ( # ����� ������� ������

link($old,$new); , )

������� ����� ���� ��������� � ����� ��, ��� � ���������� ���� �����������. ����� ����� � ��������� ������ � ��������� ��������� �����.

� ������ ������� �������������� �������� ������� ��������� ���������. ���� ���� �������� ����� -s, �� ��������� ���������� $ symlink ����������������, ������� � ���������� �������� 1. ����� ����������� ����� ������� @argv, � ���������� ���� ��������� ���� -s. ���� ���� -s �����������, �� ������ �� �������� � $symlink �������� ������ undef. ����� ������� @argv ����������� ���������� �����, ������� ��� ������� @argv �������� ���������� ������� shift �� ���������; �� ���� ������

shift(@ARGV) ;

�� ����� �� ��������

shift;

��������� ��������� ����� ��������� �������� $symlink. ��� ����� ����� ���� 1, ���� undef, � �� ��������� ����� ��� ������ ����������� ���� �������� symlink, ���� link.

5. ��� ���� �� �������� ������� ���� ������:

foreach $f (<*>) {

print "$f -> $where\n" if defined($where =� readlink($f));

}

��������� ���������� $f ������������� �� ������� ������ �� ���� ������ �������� ��������. ��� ������� ����� ���������� $where ������������� ��������, ���������� � ���������� ���������� ������� readlink () ��� ������� �����. ���� ��� � �� ������������� ������, �� �������� readlink ���������� undef, ����� �������� "����" �

�������� if, a print ������������. ���� �� �������� readlink ���������� �����-�� ��������, �� print ������� �������� ������������� ������ � ��� ����� ��� ����������, �� ������� ��� ���������.

����� 14 "���������� ����������"

1. ��� ���� �� �������� ������� ���� ������:

if ('date' =~ /"S/) (

print "Go play!\n";

} else (

print "Get to work!\n";

}

�����������, ������� date ������� ����� s � �������� ������� ������� ������ �� �������� (Sat ��� sun), ��� ������ ������ �����������. �� �������� date, ����� � ������� ����������� ��������� �������, �������� �� ������ ������ ������ s. �� ��������� ���������� �� ������� ���� ��������� ��� ������.

2. ��� ���� �� �������� ������� ���� ������:

open(PW,"/etc/passwd") ;

while (<PW>) {

chomp;

($user,$gcos) = (split /:/)[0,4];

($real) = split (/,/, $gcos); '

$real($user) = $real;

)� close(PW);

open(WHO,"who I") || die "cannot open who pipe";

while (<WHO>) (

($login, $rest) =/" (\S+) \s+(.*)/;

$login = $real($login) if $real($login);

printf "%-30s ts\n",$login,$rest;

}

� ������ ����� ��������� ��� %real, ����� �������� � ��������������� �����, � �������� � ��������������� �������� �����. ���� ��� ������������ � ��������� ����� ��� ������ ���������������� ����� �� ��������.

�� ������ ����� �������������� �������� ���������� ���������� ������� who, ������� ������� ��� ������ ����������� �����. ������ ������ ����������� � ���������� ��������� ����������� ����� ������������� � ���������� ���������� � ��������� ���������. ������ ����� ������ (��������������� ���) ���������� �������� ������ �� ����, �� ������ ���� ��� ����������. ����� ����� ����� � ������� ������� printf ��������� ���������� � stdout.

�������� �������� ����������� ����� � ������ ����� ����� �������� �������

foreach $_ ('who') (

� ��� �� �����������. ������������ �������� ������� � ���, ��� ������� ��������� � �������������� ����������� ����� ����� ���������� � ������, ��� ������ who ������ �������� �������, ����� ��� � �������� � �������� who � �������� �������� �������� ����� ���������� ���������� ������� who.

3. ��� ���� �� �������� ������� ���� ������:

open(PW,"/etc/passwd");

while (<PW>) (

chomp;

($user,$gcos) = (split /:/)[0,4];

($real) = split(/,/, $gcos);

$real($user} �= $real;

} close(PW) ;

open(LPR,"1Ipr") I I die "cannot open LPR pipe";

open (WHO,"who]") || die "cannot open who pipe";

while (<WHO>) {

# ��� �������� ���������� ��� ������ �� foreach $_ ('who') (

($login, $rest) = / (\S+) \s+(.*)/;

$login = $real($loginl if $real($login} ;

printf LPR "%-30s %s\n",$login,$rest;

}

������� ����� ���� ���������� � ���������� �� ����������� ���������� ������� � ���, ��� �� �������� ���������� ����� lpr, �������� ��� �������� Ipr, � �������������� �������� printf ���, ����� �� ������� ������ �� � stdout, � � ���� ����������.

4. ��� ���� �� �������� ������� ���� ������:

sub mkdir f

'system "/bin/mkdir", @_;

}

����� ������� mkdir �������� ��������� ����� �� ���������� ������������. ������ ������������ �������� ������ ������������� �������� ����������� ���������, ������ ��� ��������� ��� ������ �� system ������ ���� ������������ � �������� "����" ��� ���������� Perl-���������.

5. ��� ���� �� �������� ������� ���� ������:

sub mkdir (

my($dir, $mode) = 8_;

('system "/bin/mkdir", $dir) && chmod($mode, $dir) ;

1

 

������� �� ��������� ��������� ��������� ���� ������������ � $dir � $ mode. ����� �� �������� mkdir ��� �������� � ������ $dir. � ������ ������ �������� chmod ����������� ����� �������� ��������������� ����� �������.

����� 15 "������ �������� �������������� ������ "

1. ��� ���� �� �������� ������� ���� ������:

while (�) { chomp;

$slash = rindex ($_,"/");

if ($slash > -1) (

$head = substr($_,0,$slash);

$tail = substr($_,$slash+l);

} else (

($head,$tail) = ("", $_) ;

) print "head = '$head', tail = '$tail'\n";

>

������ ������, ����������� ��������� "����", ������� ������������ ����� �������� chomp, ������� ������� ������ ����� ������. ����� � ������� rindex () �� ���� � ���� ������ ������� ������ ����� �����. ��������� ��� ������ ��������� ������ �� �����, ��������� substr (). ���� ����� ����� ���, �� ��������� rindex ����� -1, � ���� ������� �� �� �������������. ��������� ������ ����� ������� ���������.

2. ��� ���� �� �������� ������� ������ ������:

chomp(@nums = <STDIM>); # �������� �������� �� ������ ������

# ������������� chomp @nuros = sort ( $� <=> $b } @nums;

foreach (@nums) (

printf "%30g\n", $_;

}

� ������ ������ � ������ @nums �������� ��� �����. �� ������ ������ ���� ������ ����������� � �������� �������, ��� ���� ������������ ���������� ��������. ���� foreach ������������ ����� �����������.

3. ��� ���� �� �������� ������� ���� ������:

open(PW,"/etc/passwd") || die "How did you get logged in?";

while �PW� (

chomp;

($user, $gcos) = (split /:/)[0,4];

($real) = split!/,/, $gcos) ;

$real($user} = $real;

($last) = (split /\s+/, $real)[-l];

$last{$user} = "\L$last";

} close(PW) ;

for (sort by_last keys %last) (

printf "%30s %8s\n", $real($_}, $_;

>

sub by_last ( ($last($a} cmp $last($b}) || ($a cmp $b). }

� ������ ����� ��������� ��� %last, ����� �������� � ��������������� �����, � ��������������� �� �������� � ������� �������������, � ��� %���1, ���������� ������ �������� ����� �������������. ��� ������� ����������� � ������ �������, �����, � �������, FLINT-STONE, Flintstone � flintstone ������ ����� ���� � ������.

�� ������ ����� ��������� %���1, ������������� �� ��������� %iast. ��� �������� � �������������� ����������� ����������, ���������������� ������������� by_last.

4. ��� ���� �� �������� ������� ���� ������:

while (<>) (

substr($_,0,I) =~ tr/a-z/A-Z/;

substr($_,!) � tr/A-Z/a-z/;

print;

1

��� ������ ������, ����������� ��������� "����", �� ���������� ��� �������� tr � �� ����� ��� ������ ������ ������. ������ �������� tr ��������� ������ ������ ������ � ������� �������, � ������ ��������� ��� ��������� ������� � ������ �������. ��������� ���������.

��� ������ �������, � �������������� ������ ��������� �������� � �������� ���������:

while (�) {

print "\u\L$_";

}

���� �� �������������� ����� ��� �������, ��������� ���� ������������� ���� ������.

����� 16 "������ � ��������� ����� ������ff

1. ��� ���� �� �������� ������� ���� ������:

while (@pw == getpwent) {

($user, $gid, $gcos) - @pw(0,3,6);

($real) = split /,/, $gcos;

$real($user) = $real;

$members($gid} .= " $user";

($last) = (split /\s+/, $real)(-l);

51ast($user) " "\L$last";

)

while (@gr - getgrent) (

($gnarae, $gid, $meinbers) = @gr[ 0,2,3);

$rnembers( $gid) .=� " $merabers";

$gname($gid) - $gname;

)

for $gid (sort by_gname keys %gname) (

tall = ();

for (split (/\s+/, $members($gidl)) ( $all{$_)++ if length $_;

1

Omembers = () ;

foreach (sort by_last keys %all) (

push(@members, "$real($_} ($_)");

}

$meinberlist = join(", ", @members);

write;

)

sub by_gname ( $gname($al cmp $gname($bl; ) sub by_last ( ($last(a) cmp $last($b)) || ($a cmp $b); )

format STDOUT = @<<<< @<<<< A<<<<<<<<<<<<<<<<<<<

$gname($gid), "($gid)", $memberlist

^<<<<<<<<<<<<<<<<<<<

$memberlist

��, � ���� �� ��� ������ �����������, �� ��� ��� �������� ������� ��������������, ����� ��������� ��������� ������.

����� 17 "������ � ����������������� ������ ������"

1. ��� ���� �� �������� ������� ���� ������:

dbmopen(%ALIAS, "/etc/aliases", undef) II

die "No aliases!: $!";

while (($key,$value) - each(tALIAS)) (

chop($key,$value) ;

print "$key $value\n";

1

 

������ ������ ��������� DBM �����������. (� ����� ������� DBM ����������� ����� ���������� � �������� /usr/lib/aliases � ���������� ���� �������, ���� ��� �� ���������.) � ����� while �������������� ������ �� DBM-�������. ������ ������ ����� ������ ��� �������� ������� NUL, ������� ����������� ���� � ��������. ��������� ������ ����� ������������ ����� ����������.

2. ��� ���� �� �������� ������� ���� ������:

# program 1:

dbmopen(%WORDS,"words",0644) ;

while (�) {

foreach $word (split(/\W+/)) ( $WORDS($word)++;

> } dbmclose(%WORDS) ;

������ ��������� (������������) ��������� DBM words � ������� ��������, �������� ����� words, dirwords.pag. ���� while �������� ������ ������, ��������� �������� "����". ��� ������ ����������� � ������� �������� split � ����������� /\w+/, ������� ���������� ����������� �������. ����� ������������ ������� ���� ����, ��������� � DBM-�������, ������ ��� ������������� ������� � ����� �� ���� ������ ������������ �������� foreach.

# program 2:

dbmopen(%WORDS,"words",undef) ;

foreach $word (sort { SWORDS)$b} <=> SWORDS($a[ } keys %WORDS) ( print "Sword SWORDS(Sword)\n";

1 dbmclose(%WORDS) ;

������ ��������� ����� ��������� DBM words � ������� ��������. ������� �� ������ ������ ������ foreach ������ ����� ��� "�������" ������. ��� ������ ���������� ����� ���������� $word � �������� �������� ����� ������������� ��������� ������� ������. ���� ������ ������� �� ������ ���� %words, ���������������� �� �� ��������� (�.�. ���������� ����������) � ��������� �������. ��� ������� �������� ������ �� ������� ����� � ���������� ��� ����������.

����� 18 "�������������� ������ �������� � Perl-��������� "

1. ��� ���� �� �������� ������� ���� ������:

for (;;) (

($user,$home) = (getpwent)[0,7];

last unless $user;

next unless open(N,"$home/.newsrc");

next unless -M N < 30; ## added value :-) while (<N>) f

if (/^comp\ . lang\ .perl\ .announce: /) { print "$user is a good person, ", "and reads comp.lang.peri.announce!\n");

last;

} } }

����� ������� ���� � ��� ���� for, ������� ����������� "�����";

����� �� ����� ����� �������������� ����������� �������� last, ������� ������ ����. ��� ������ ���������� ����� �������� getpwent �������� ����� �������� ���������� $user (��� ������������) � ���������� $home (��� ��������� �������).

���� �������� $user �����, �������������� ����� �� ����� for. ��������� ��� ������ ���� ��������� ���� .newsrc � ��������� �������� ������������. ���� ���� ���� ������� ������ ��� ���� �� ��������� ������� �����, ����������� ��������� �������� ����� for.

� ����� while �������������� ������ �� ����� ������ �� ����� .newsrc. ���� ������ ���������� � comp.lang.perl.announce:, �� �������� print �������� �� ����, � �������������� ��������������� ����� �� �����

while.

����� 19 "CG1-����������������"

1. ��� ���� �� �������� ������� ���� ������:

use strict;

use CGI qw (:standard);

print header(), start_html("Add Me"It-print hi("Add Me") ;

if (paramO) {

my $nl = param('fieldl');

my $n2 = param('field2');

my $n3 = $n2 + $nl;

print p("$nl + $n2 = <strong>$n3</strong>\n") ;

} else (

print hr(), start_form();

print pC'First Number:", textfield("fieldl"));

print p("Second Number:", textfield("field2"));

print p(submit("add"), reset ("clear"));

print end_form(), hr () ;

} print end_html();

 

���� ������� ������ ���, �� ������ ��������� ����� � ����� ���������� ������ (��� ������ ������ textfield). ��� ������� ������� ���������� �� ���������� ��� ���� � ������� ���������.

2. ��� ���� �� �������� ������� ���� ������:

use strict;

use CGI qw(:standard);

print header(), start_html("Browser Detective");

print hi("Browser Detective"), hr();

my $browser = $ENV('HTTP_USER_AGENT'};

$_ '" $browser;

BROWSER:(

if (/msie/i) (

msie($_) ;

) elsif (/mozilla/i) (

netscape($_) ;

) elsif (/lynx/i) (

lynx($_);

1 else (

default($_) ;

> >

print end_html() ;

sub msie)

print pC'Internet Explorer: @_. Good Choice\n") ;

}

sub netscape (

print pC'Netscape: @_. Good Choice\n") ;

t

sub lynx {

print p("Lynx: @_. Shudder...");

(

sub default (

print pC'What the heck is a @_?");

}

������� ������ ����� � �������� ���������� ����� HTTP_USER_ AGENT �� ������� ������� ������ �� ��������, ������������ ��������� ��� �������� (MS Internet Explorer, Netscape Navigator, Lynx). ����� �������� ���������� �� �� ���� ��������, �� �� ����������� �� ���. ��� ������� ������ ������������ ���������� ������������� ���������, ��������������� �� ����������� ����������� ��������. �������� ��������: ����� ����������, ����� ������ ������� ����������� �������������, �� ��������� ������ ����������� ��������� ������������� (��� ����� ��������).

 




|     �����     |     ������     |


| ���������� | ����������� | �������� | ������
| ����� 1 | ����� 2 | ����� 3 | ����� 4 | ����� 5 | ����� 6 | ����� 7 | ����� 8 | ����� 9 | ����� 10
| ����� 11 | ����� 12 | ����� 13 | ����� 14 | ����� 15 | ����� 16 | ����� 17 | ����� 18 | ����� 19
| ���������� � | ���������� � | ���������� � | ���������� � |