??xml version="1.0" encoding="utf-8" standalone="yes"?>
-65e24
-12e-12
-1.2E-23
十进制整敎ͼ
61298040283768 #q里整数到底有多位看不太清
61_298_040_283_768 #q样清楚了Q?br />
非十q制整数Q?br /> 0377 #八进制数
0xff #十六q制?br /> 0b1111111 #二进制数
注:有两个进制{换函敎ͼoct()和hex().
oct(144); #q里把一个八q制数{换ؓ10q制?br /> 100
hex(64); #q里把一个十六进制数转换?0q制?br /> 100
数字操作W:
perl会自动识别计结果是整数q是点数?br /> 例:10.2 / 0.3 #整数34
10 / 3 #点?.3333333.....
2 ** 3 #q里的阶乘很有用的!
8
注:复数可以查找CPAN Math::Complex模块?br />
文本
单引?br /> 注:单引L字符串不能用{义和变量?br /> 例:'hello\n'
hello\n
双引号用的转义W?br /> 形式 转义
\n newline
\r 回R
\t tab
\f 换纸
\b 退格键
\a bell
\e Escape?br /> \007 八进制数
\x7F 十六q制?br /> \cC 控制字符
\\ \
\" "
\l 下一个字W{换ؓ写
\L 到\El束的所有的字符转换为小?br /> \u 下一个字W{换ؓ大写
\U 到\El束的所有的字符转换为大?br /> \Q 到\El束的所有的字符中不是英文单词的加{义符?br /> 例:print "a \Qfd d %\E";
a fd\ d\ \%
\E \L,\U,\Q的结束符?img src ="http://www.aygfsteel.com/ivanwan/aggbug/42222.html" width = "1" height = "1" />
]]>
@lines = `perldoc -u -f atan2`;
上面的代码可以调用perl的perldoc工具q且q回所有的pȝ信息。真是太了Q?img src ="http://www.aygfsteel.com/ivanwan/aggbug/42206.html" width = "1" height = "1" />
]]>
## 获取有关钱币Q时_W号的信息?br />$locale_values = localeconv();
for (sort keys %$locale_values) {
printf "%-20s = %s\n", $_, $locale_values->{$_};
}
## 获取语言的所有信?br />
## 有LC_ALL, LANGUAGE, LC_CTYPE, LC_COLLATE,
## LC_MONETARY, LC_NUMBERIC, LC_TIME,
## LANGq个要捕捉错?因ؓ有的pȝ没有?
$old_locale = setlocale(LC_ALL);
print $old_locale;
open(F, ">:utf8", "utf.txt"); # 自动~码成utf8.
print F @lines;
close(F);
q样可以省得再打开以后在编码?/p>
## q里发觉只有使用Wx,Encode,Encode::CN,File::Globq四个模块才能通过perl2exe~译?br />
## 但是q有把wxbase26u_gcc_custom.dllQwxmsw26u_adv_gcc_custom.dllQwxmsw26u_core_gcc_custom.dll
## 拷到目录下才能运行?br />
use strict;
use Wx;
use Encode;
use Encode::CN;
#use PerlIO;
#use POSIX;;
#use Getopt::Std;
use File::Glob;
# every program must have a Wx::App-derive class
package MyApp;
use vars qw(@ISA);
@ISA = qw(Wx::App);
# this is called automatically on object creation
sub OnInit {
my( $this ) = shift;
# create a new frame
my( $frame ) = MyFrame->new();
# set as top frame
$this->SetTopWindow( $frame );
# show it
$frame->Show( 1 );
}
package MyFrame;
use vars qw(@ISA);
@ISA = qw(Wx::Frame);
use Wx::Event qw(EVT_PAINT);
# this imports some constants
use Wx qw(wxDECORATIVE wxNORMAL wxBOLD);
use Wx qw(wxDefaultPosition);
use Wx qw(wxWHITE);
sub new {
# new frame with no parent, id -1, title 'Hello, world!'
# default position and size 350, 100
my( $this ) = shift->SUPER::new( undef, -1, 'Hello, world!',
wxDefaultPosition , [350, 100] );
# create a new font object and store it
$this->{FONT} = Wx::Font->new( 40, wxDECORATIVE, wxNORMAL, wxBOLD, 0 );
# set background colour
$this->SetBackgroundColour( wxWHITE );
$this->SetIcon( Wx::GetWxPerlIcon() );
# declare that all paint events will be handled with the OnPaint method
EVT_PAINT( $this, \&OnPaint );
return $this;
}
sub OnPaint {
my( $this, $event ) = @_;
# create a device context (DC) used for drawing
my( $dc ) = Wx::PaintDC->new( $this );
# select the font
$dc->SetFont( $this->font );
# darw a friendly message
$dc->DrawText( 'Hello, world!', 10, 10 );
}
sub font {
$_[0]->{FONT};
}
package main;
# create an instance of the Wx::App-derived class
my( $app ) = MyApp->new();
# start processing events
$app->MainLoop();
# Local variables: #
# mode: cperl #
# End: #
我现在还不知是ؓ什么。如果有哪位高手知道Q告诉小弟一声?br />
谢谢Q?/p>
![]() |
|
Unix 用户非常熟悉Z文本?UI 模型。设x一?Perl E序Q让我们先看一下这个模型用于该E序的简单实现。标准的 Getopt::Std 模块化了命o行参数的解析。这个程序仅仅ؓ了说?Getopt::Std 模块Q没有实际用途)? 请参阅本文后面的参考资料?/p> 使用 Getopt::Std 的命令行开?/b>
#!/usr/bin/perl -w
use strict; # always use strict, it's a good habit
use Getopt::Std; # see "perldoc Getopt::Std"
my %options;
getopts('f:hl', \%options); # read the options with getopts
# uncomment the following two lines to see what the options hash contains
#use Data::Dumper;
#print Dumper \%options;
$options{h} && usage(); # the -h switch
# use the -f switch, if it's given, or use a default configuration filename
my $config_file = $options{f} || 'first.conf';
print "Configuration file is $config_file\n";
# check for the -l switch
if ($options{l})
{
system('/bin/ls -l');
}
else
{
system('/bin/ls');
}
# print out the help and exit
sub usage
{
print <<EOHIPPUS;
first.pl [-l] [-h] [-f FILENAME]
Lists the files in the current directory, using either /bin/ls or
/bin/ls -l. The -f switch selects a different configuration file.
The -h switch prints this help.
EOHIPPUS
exit;
}
#!/usr/bin/perl # sum - compute 16-bit checksum of all input files $checksum = 0; while (<>) { $checksum += unpack("%16C*", $_) } $checksum %= (2 ** 16) - 1; print "$checksum\n";
Here's an example of its use:
% perl sum /etc/termcap 1510
If you have the GNU version of sum, you'll need to call it with the —sysv option to get the same answer on the same file.% sum --sysv /etc/termcap 1510 851 /etc/termcap
一个详l的例子Q?br />
#!/usr/bin/perl # slowcat - emulate a s l o w line printer # usage: slowcat [-DELAY] [files ...] $DELAY = ($ARGV[0] =~ /^-([.\d]+)/) ? (shift, $1) : 1; #q里[.]取消?的特D性。其ؓ一般意义。shiftU除了@ARGVW一个变量和长度减一? $| = 1; #不ؓ0强行清I出或打印? while (<>) { #<>为@ARGV指定的文件句? for (split(//)) { print; select(undef,undef,undef, 0.005 * $DELAY); #select函数讄屏幕输出。这里是讄延迟? } }
perlcn - 体中?Perl 指南
Ƣ迎来到 Perl 的天?
?5.8.0 版开? Perl 具备了完善的 Unicode (l一? 支援, 也连带支援了许多拉丁语系以外的编码方? CJK (中日? 便是其中的一部䆾. Unicode 是国际性的标准, 试图늛世界上所有的字符: 西方世界, 东方世界, 以及两者间的一?(希腊? 叙利亚文, 亚拉伯文, 希伯来文, 印度? 印地安文, {等). 它也容纳了多U作业系l与q_ (?PC 及麦金塔).
Perl 本n?Unicode q行操作. q表C?Perl 内部的字W串数据可用 Unicode 表示; Perl 的函式与符 (例如正规表示式比? 也能?Unicode q行操作. 在输入及输出? Z处理?Unicode 之前的编码方式存攄数据, Perl 提供?Encode q个模块, 可以让你L地读取及写入旧有的编码数?
Encode 延模块支援下列体中文的~码方式 ('gb2312' 表示 'euc-cn'):
euc-cn Unix 延字符? 也就是俗U的国标?br /> gb2312-raw 未经处理?(低比? GB2312 字符?br /> gb12345 未经处理的中国用J体中文~码
iso-ir-165 GB2312 + GB6345 + GB8565 + 新增字符
cp936 字码?936, 也可以用 'GBK' (扩充国标? 指明
hz 7 比特逸出?GB2312 ~码
举例来说, ?EUC-CN ~码的档案{?Unicode, 需键入下列指o:
perl -Mencoding=euc-cn,STDOUT,utf8 -pe1 < file.euc-cn > file.utf8
Perl 也内附了 ``piconv'', 一支完全以 Perl 写成的字W{换工L? 用法如下:
piconv -f euc-cn -t utf8 < file.euc-cn > file.utf8
piconv -f utf8 -t euc-cn < file.utf8 > file.euc-cn
另外, 利用 encoding 模块, 你可以轻易写Z字符为单位的E序? 如下所C?
#!/usr/bin/env perl
# 启动 euc-cn 字串解析; 标准输出入及标准错误都设?euc-cn ~码
use encoding 'euc-cn', STDIN => 'euc-cn', STDOUT => 'euc-cn';
print length("骆驼"); # 2 (双引可C字W?
print length('骆驼'); # 4 (单引可C字?
print index("谆谆教诲", "蛔唤"); # -1 (不包含此子字W串)
print index('谆谆教诲', '蛔唤'); # 1 (从第二个字节开?
在最后一列例子里, ``?' 的第二个字节?``?' 的第一个字节结合成 EUC-CN 码的 ``?'; ``?' 的第二个字节则与 ``?' 的第一个字节结合成 ``?'. q解决了以前 EUC-CN 码比对处理上常见的问?
请参?Perl 内附的大量说明文?(不幸全是用英文写?, 来学习更多关? Perl 的知? 以及 Unicode 的用方? 不过, 外部的资源相当丰?
the Encode manpage, the Encode::CN manpage, the encoding manpage, the perluniintro manpage, the perlunicode manpage
Jarkko Hietaniemi <jhi@iki.fi>
Autrijus Tang (唐宗? <autrijus@autrijus.org>
$dir = shift(@ARGV) || "/tmp"; #如果没有参数,,p?/tmp".
$dir = defined($ARGV[0]) ? shift(@ARGV) : "/tmp";
2.shift函数:
UdW一个数l元?q返?
$string = q[Jon 'Maddog' Orwant]; # literal single quotes
$string = q{Jon 'Maddog' Orwant}; # literal single quotes
$string = q(Jon 'Maddog' Orwant); # literal single quotes
$string = q<Jon 'Maddog' Orwant>; # literal single quotes
3.Ҏ字符包括 "\n" (新行), "\033" (八进制数的字W?3), "\cJ" (Ctrl-J), "\x1B" (十六q制的字W?br /> 0x1B).
4.直接输入多行:
$a = <<"EOF"; #指明了EOF为结束符
This is a multiline here document
terminated by EOF on a line by itself
EOF
5.prinf函数
$char = chr(0x394);
$code = ord($char);
printf "char %s is code %d, %#04x\n", $char, $code, $code; # %#04x表示占四位十六进制数的话用0补齐
charDis code 916, 0x394