This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
язык_программирования_perl [2014/10/10 08:43] val [Пример 5] |
язык_программирования_perl [2024/11/03 09:50] (current) val [Пример 3] |
||
---|---|---|---|
Line 57: | Line 57: | ||
my ($ip) = @ARGV; | my ($ip) = @ARGV; | ||
- | if (not defined $ip) { | + | unless($ip) { |
die "Need ip\n"; | die "Need ip\n"; | ||
} | } | ||
Line 125: | Line 125: | ||
$sth = $dbh->prepare(qq{insert into table1 (b) values ($b)}); | $sth = $dbh->prepare(qq{insert into table1 (b) values ($b)}); | ||
+ | #print $sth->{Statement}; | ||
$sth->execute() or next MAINLOOP; | $sth->execute() or next MAINLOOP; | ||
$sth = $dbh->prepare(qq{select LAST_INSERT_ID()}); | $sth = $dbh->prepare(qq{select LAST_INSERT_ID()}); | ||
$sth->execute() or next MAINLOOP; | $sth->execute() or next MAINLOOP; | ||
- | (my $a)=$sth->fetchrow_array(); | + | my ($a)=$sth->fetchrow_array(); |
print "a = $a; b = $b\n"; | print "a = $a; b = $b\n"; | ||
Line 157: | Line 158: | ||
* Использование UTF8 | * Использование UTF8 | ||
- | * Работа с XML форматом | + | * Работа с XML форматом ([[https://stackoverflow.com/questions/46167194/get-value-of-elements-using-xmldom|Get value of elements using XML::DOM]]) |
=== Исходный файл === | === Исходный файл === | ||
Line 201: | Line 202: | ||
foreach my $node (@nodes) { | foreach my $node (@nodes) { | ||
+ | |||
+ | # print $node->toString; | ||
+ | | ||
my $uuid = $node->getAttributeNode ("uuid")->getValue; | my $uuid = $node->getAttributeNode ("uuid")->getValue; | ||
my $lastname = $node->getAttributeNode ("lastname")->getValue; | my $lastname = $node->getAttributeNode ("lastname")->getValue; | ||
Line 208: | Line 212: | ||
} | } | ||
</code> | </code> | ||
- | |||
==== Пример 5 ==== | ==== Пример 5 ==== | ||
- | * Работа с Communigate | + | * [[http://www.communigate.ru/CGPerl/|CommuniGate Pro Perl Interface]] |
+ | * [[https://www.communigate.ru/main/purchase/scriptrepository.html|Библиотека скриптов для CommuniGate Pro (бесплатно)]] | ||
<code> | <code> | ||
- | # wget http://www.stalker.com/CGPerl/CLI.pm | + | # wget https://www.communigate.ru/CGPerl/CLI.pm |
# mv CLI.pm /etc/perl/ | # mv CLI.pm /etc/perl/ | ||
- | # cat adduser.pl | + | # cat addcgpuser.pl |
</code><code> | </code><code> | ||
#!/usr/bin/perl | #!/usr/bin/perl | ||
Line 225: | Line 229: | ||
use CLI; | use CLI; | ||
+ | my ($AccountName,$RealName,$Password) = @ARGV; | ||
my $cli = new CGP::CLI( { PeerAddr => '127.0.0.1', | my $cli = new CGP::CLI( { PeerAddr => '127.0.0.1', | ||
PeerPort => 106, | PeerPort => 106, | ||
- | login => 'postmaster@corp20.un', | + | login => 'postmaster', |
password => 'Pa$$w0rd' | password => 'Pa$$w0rd' | ||
} ) | } ) | ||
Line 235: | Line 240: | ||
my $UserData; | my $UserData; | ||
- | @$UserData{'RealName'}='Сидоров Сидор Сидорович'; | + | @$UserData{'RealName'}=$RealName; |
- | @$UserData{'Password'}='cpassword3'; | + | @$UserData{'Password'}=$Password; |
- | $cli->CreateAccount(accountName => 'user3', | + | $cli->CreateAccount(accountName => $AccountName, |
settings => $UserData) | settings => $UserData) | ||
|| die "Can't create account: ".$CGP::ERR_STRING."\n"; | || die "Can't create account: ".$CGP::ERR_STRING."\n"; | ||
Line 245: | Line 250: | ||
exit; | exit; | ||
+ | </code><code> | ||
+ | mail# ./addcgpuser.pl user3 'Сидор Сидорович Сидоров' password3 | ||
</code> | </code> | ||
+ | |||
+ | ==== Пример 6 ==== | ||
+ | |||
+ | * Perl CGI | ||
+ | * http://....hello.pl?name=ivanov | ||
+ | |||
+ | <code> | ||
+ | $ cat hello.pl | ||
+ | </code><code> | ||
+ | #!/usr/bin/perl | ||
+ | |||
+ | use strict; | ||
+ | use CGI; | ||
+ | |||
+ | my $q=new CGI(); | ||
+ | my $name=$q->param('name'); | ||
+ | print qq| | ||
+ | <html> | ||
+ | <body> | ||
+ | <h1>Hello $name</h1> | ||
+ | </body> | ||
+ | </html> | ||
+ | |; | ||
+ | </code> | ||
+ | |||
+ | ==== Ссылки ==== | ||
+ | |||
+ | * [[http://codecry.com/perl/random-password-generator|Random Password Generator in Perl]] | ||
+ | * [[http://www.xgu.ru/wiki/%D0%A2%D1%80%D0%B0%D0%BD%D1%81%D0%BB%D0%B8%D1%82|Транслит]] |