#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use open qw/:std :utf8/;
my $text = "Как найти слова с двумя гласными?";
my @words = split /\s+/, $text;
my ($count, @result, $tmp_word);
for my $word (@words) {
$tmp_word = $word;
$count = ($word =~ s/[уеёыаоэяию]//g);
push @result, $tmp_word if $count == 2;
}
for (@result) {
print $_, "\n";
}
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
my %ttys;
open my $WHO, '-|', '/bin/who' or die "open() error: $!\n";
while (<$WHO>) {
my ($user, $tty) = split;
push @{$ttys{$user}}, $tty;
}
close $WHO;
#print Dumper(\%ttys);
foreach my $user (sort keys %ttys) {
print "$user: @{$ttys{$user}}\n";
}
#!/usr/bin/perl
use strict;
use warnings;
use threads;
use Thread::Queue;
use Data::Dumper;
my @myarray = (1 .. 1000);
#print Dumper (\@myarray);die;
my $count = shift || 10;
print "Number of threads: $count\n";
my $q = Thread::Queue->new;
my @threads;
for (0 .. $count - 1)
{
push @threads, async {
while (defined (my $f = $q->dequeue))
{
some_process ($f);
}
};
}
for (@myarray)
{
$q->enqueue ($_);
}
# Tell workers they are no longer needed.
$q->enqueue (undef) for @threads;
# Wait for workers to end
$_->join for @threads;
print "Complete\n";
1;
sub some_process
{
my $element = shift;
my $tid = threads->self->tid;
#my $count = threads->list (threads::running);
#print "Running threads: $count\n";
print "Thread $tid started\n";
open my $F, '>>', $tid . '.txt';
print $F 'TID: ', $tid, ', element: ', $element, "\n";
close $F;
print "Thread $tid stopped\n";
}
open my ($ip) = (IPlist, "iplist" or die "can't open iplist: $!");
my ($username) = 'admin';
while (@ lines = "<IPlist>")
($fsname, $fstype) = m/\S+ (\S+) (\S+)/;
#!/usr/bin/perl
use strict;
use warnings;
use JSON;
open my $F, '<', '/proc/mounts' or die "open() error: $!\n";
my ($fsname, $fstype, %result);
while (<$F>)
{
($fsname, $fstype) = (split /\s+/)[1, 2];
#$fsname =~ s!/!\\/!g;
push @{$result{'data'}}, {'{#FSNAME}' => $fsname, '{#FSTYPE}' => $fstype};
}
close $F;
print JSON->new->pretty->encode (\%result);