Menu

  • Home
  • Work
    • AI
    • Cloud
      • Virtualization
      • IaaS
      • PaaS
    • Architecture
    • BigData
    • Python
    • Java
    • Go
    • C
    • C++
    • JavaScript
    • PHP
    • Others
      • Assembly
      • Ruby
      • Perl
      • Lua
      • Rust
      • XML
      • Network
      • IoT
      • GIS
      • Algorithm
      • Math
      • RE
      • Graphic
    • OS
      • Linux
      • Windows
      • Mac OS X
    • Database
      • MySQL
      • Oracle
    • Mobile
      • Android
      • IOS
    • Web
      • HTML
      • CSS
  • Life
    • Cooking
    • Travel
    • Gardening
  • Gallery
  • Video
  • Music
  • Essay
  • Home
  • Work
    • AI
    • Cloud
      • Virtualization
      • IaaS
      • PaaS
    • Architecture
    • BigData
    • Python
    • Java
    • Go
    • C
    • C++
    • JavaScript
    • PHP
    • Others
      • Assembly
      • Ruby
      • Perl
      • Lua
      • Rust
      • XML
      • Network
      • IoT
      • GIS
      • Algorithm
      • Math
      • RE
      • Graphic
    • OS
      • Linux
      • Windows
      • Mac OS X
    • Database
      • MySQL
      • Oracle
    • Mobile
      • Android
      • IOS
    • Web
      • HTML
      • CSS
  • Life
    • Cooking
    • Travel
    • Gardening
  • Gallery
  • Video
  • Music
  • Essay

Category Work

Work

Eclipse知识集锦

常用快捷键
快捷键 说明
Ctrl + Shift + T 打开一个类型,甚至是位于JAR中的类文件,依据文件名搜索
Ctrl + Shift + R 打开任意一个文件,依据文件名搜索
Ctrl + 1   快速修复 
Ctrl + Shift + O 清理Java impo…
阅读全文
16 years ago
0
Java

JProfiler学习笔记

剖析视图
内存视图(Memory Views)
该视图专注于对象的内存分配情况,包含以下选项卡:
 All Objects 显示堆中实时的对象情况:显示某种类型(聚合级别可以是类、包等)对象的数量(Instance Count)、浅尺寸(Shallow size)…
阅读全文
16 years ago
0
Architecture

原型模式

模式定义

使用原型实例指定创建对象的种类,并通过拷贝这些原型对象创建新的对象。 在GOF95中原型模式被分类为创建型模式。

模式结构与说明

patterns_PrototypePattern

  1. Prototype:声明一个克隆自身的接口,用来约束想要克隆自己的类,让它们都要实现这里定义的克隆方法
  2. ConcretePr…
阅读全文
16 years ago
0
C, Linux

Linux进程间通信

管道

当从一个进程连接数据流到另外一个进程时,使用术语“管道”。通常是把一个进程的输出通过管道连接到另外一个进程的输入。Shell命令通过管道字符可以实现命令的连接:

Shell
1
2
3
4
5
cmd1 | cmd2
 
#cmd1的标准输入来自终端键盘
#cmd1的标准输出传递给cmd2,作为它的标准输入
#cmd2的标准输出连接到终端屏幕
popen函数

Linux提供了类似的API,允许通过编程的方式,利用管道在两个程序之间传递数据。在两个程序之间进行数据传递的最简单方式是使用popen/pc…

阅读全文
16 years ago
0
C, Linux

Linux信号、进程和会话

进程

进程和信号是Linux操作环境的基础部分,控制着Linux和其它类UNIX系统的几乎所有活动。

UNIX标准对进程的定义:其中运行着一个或者多个线程的地址空间,以及这些线程需要的系统资源。Linux系统的进程是非常轻量级的。

进程基础知识

每个Linux进程…

阅读全文
16 years ago
0
Linux, Work

SVN知识集锦

常用命令
服务器端命令
创建SVN版本库

命令格式: svnadmin create 路径 --fs-type fsfs|bdb

具体可以参考:Ubuntu下安装subversion服务器 

客户端命令
签出:从版本库下载带有svn元数据的副本

命令格式:

svn  [co|checkout]  协议://版本库路…

阅读全文
16 years ago
0
Java

Maven POM文件配置示例

排除传递性依赖
XHTML
1
2
3
4
5
6
7
8
9
10
11
12
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>2.5.0</version>
    <exclusions>
        <exclusion>
            <!-- CXF对Spring-web的依赖被排除 -->
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
        </exclusion>
    </exclusions>
</dependency>
指定资源文件目录并过滤
XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<build>
    <directory>target</directory>
    <outputDirectory>target/classes</outputDirectory>
    <testOutputDirectory>target/test-classes</testOutputDirectory>
    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>
    <resources>
        <resource>
            <!-- 在这里可以指定多个资源文件目录 -->
            <directory>src/main/java</directory>
            <excludes>
                <!--注意该配置从本应当是源代码的目录中过滤掉Java文件,其他文件作为资源文件 -->
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
        </testResource>
    </testResources>
</build>
指定额外的源代码目录
过滤资源文件
配置目录链接(Linked Folder)
打包时生成*–sources.jar
打包时生成*–javadoc.jar
指定编译级别
启用对AspectJ的支持
指定源代码、资源文件的编码方式
打包时拷贝所有依赖包
打包生成可执行的jar文件
打uber-jar另一种方法

maven-shade-plugin也支持将依赖打包进JAR,这类似于maven-assembly-plugin。但是后者存在BUG,会导致Unable to locate Spring NamespaceHandler for XML schema na…

阅读全文
16 years ago
0
Java

Hibernate基于XML的配置文件样例

Hibernate 3.0配置文件
XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                                         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="cpdb">
  <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  <property name="hibernate.connection.password">CASTOR</property>
  <property name="hibernate.connection.url">jdbc:oracle:thin:@RD-DB-5.sparknet.com.cn:1522:CPDB</property>
  <property name="hibernate.connection.username">CASTOR</property>
  <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
  <property name="hibernate.jdbc.batch_size">20</property>
  <property name="hibernate.show_sql">true</property>
  <property name="hibernate.format_sql">true</property>
  <property name="hibernate.generate_statistics">true</property>
  <property name="hibernate.current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>
XRM配置文件样例

XRM是Hibernate3里面的一个试验性功能,用于在数据库和XML文件之间进行映射

XHTML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="sparknet.traing.hxm.model">
    <class entity-name="Corp" node="corp" table="T_CORP">
        <comment>
            <![CDATA[
                Corporation basic information
            ]]>
        </comment>
        <!-- 复合主键的映射 -->
        <composite-id name="id" node="-">
            <key-property name="org" node="org" type="long">
                <column name="ORG" sql-type="NUMBER(8)">
                    <comment>database Code</comment>
                </column>
            </key-property>
            <key-property name="id" node="id" type="long">
                <column name="ID" sql-type="NUMBER(8)">
                    <comment>corporation identifier</comment>
                </column>
            </key-property>
            <key-property name="seqId" node="seq-id" type="long">
                <column name="SEQ_ID" sql-type="NUMBER(8)">
                    <comment>changing sequence</comment>
                </column>
            </key-property>
            <generator class="foreign">
                <param name="property">corpOther</param>
            </generator>
        </composite-id>
        <!-- 普通属性的映射 -->
        <property name="corpName" node="corp-name" type="string" unique="true" unique-key="UK_CORP_NAME">
            <column name="CORP_NAME" sql-type="VARCHAR(64)">
                <comment>corporation name</comment>
            </column>
        </property>
        <property name="regCapi" node="reg-capi" type="currency">
            <column name="REG_CAPI" sql-type="NUMBER(14,2)">
                <comment>registered capital</comment>
            </column>
        </property>
        <property name="startDate" node="start-date" type="fmt_date">
            <column name="START_DATE" sql-type="DATE">
                <comment> corporation start date</comment>
            </column>
        </property>
        <property name="startTime" node="start-time" type="fmt_time">
            <column name="START_TIME" sql-type="DATE">
                <comment> corporation start time</comment>
            </column>
        </property>
        <!-- 组件映射 -->
        <component name="address" node="addr" lazy="true">
            <property name="street" node="street" type="string">
                <column name="STREET" sql-type="VARCHAR2(128)">
                    <comment>address of street</comment>
                </column>
            </property>
            <property name="building" node="building" type="string">
                <column name="BUILDING" sql-type="VARCHAR2(128)">
                    <comment>building</comment>
                </column>
            </property>
            <property name="zipCode" node="zip-code" type="int">
                <column name="ZIP" sql-type="NUMBER(6)">
                    <comment>zip code</comment>
                </column>
            </property>
        </component>
        <!-- 共享主键的一对一关联,目前这个版本,会导致当前Class的主键不能映射到XML中? -->
        <one-to-one name="corpOther" entity-name="AdvancedCorpInfo" node="corp-other-info" constrained="true" cascade="all" />
        <!-- 多对一映射 -->
        <many-to-one name="city" entity-name="City" embed-xml="true" node="city-code" cascade="all">
            <column name="CITY_ID" sql-type="NUMBER(8)">
                <comment>address of city</comment>
            </column>
        </many-to-one>
        <many-to-one name="gongShangOrg" node="belong-dist-org" entity-name="GongShangOrg" cascade="all">
            <column name="GS_ORG" sql-type="NUMBER(8)"></column>
            <column name="GS_ID" sql-type="NUMBER(8)"></column>
            <column name="GS_SEQ_ID" sql-type="NUMBER(8)"></column>
        </many-to-one>
        <!-- 基于连接表的一对多双向关联,One端-->
        <list name="stocks" embed-xml="true" node="stocks-of-corp" cascade="all,delete-orphan" batch-size="20" table="T_M_CORP_STOCK">
            <key not-null="true" foreign-key="FK_CORP_STOCK">
                <column name="CORP_ORG" sql-type="NUMBER(8)" />
                <column name="CORP_ID" sql-type="NUMBER(8)" />
                <column name="CORP_SEQ_ID" sql-type="NUMBER(8)" />
            </key>
            <list-index>
                <column name="ORD">
                    <comment>list index</comment>
                </column>
            </list-index>
            <many-to-many unique="true" entity-name="Stock" node="stock" embed-xml="true">
                <column name="STOCK_ORG" sql-type="NUMBER(8)" />
                <column name="STOCK_ID" sql-type="NUMBER(8)" />
                <column name="STOCK_SEQ_ID" sql-type="NUMBER(8)" />
            </many-to-many>
        </list>
        <!-- 基于外键的一对多关联,One端 -->
        <set name="oldStocks">
            <key>
                <column name="CORP_ORG" sql-type="NUMBER(8)" />
                <column name="CORP_ID" sql-type="NUMBER(8)" />
                <column name="CORP_SEQ_ID" sql-type="NUMBER(8)" />
            </key>
            <one-to-many entity-name="stock"/>
        </set>
        <property name="timestamp" node="timestamp" type="fmt_date_time">
            <column name="STATE_DATE">
                <comment>Version column</comment>
            </column>
        </property>
    </class>
    <class entity-name="Stock" node="Stock" table="T_STOCK">
        <composite-id name="id" node="identifier">
            <key-property name="org" node="org" type="long">
                <column name="ORG" sql-type="NUMBER(8)">
                    <comment>database Code</comment>
                </column>
            </key-property>
            <key-property name="id" node="id" type="long">
                <column name="ID" sql-type="NUMBER(8)">
                    <comment>stock identifier</comment>
                </column>
            </key-property>
            <key-property name="seqId" node="seq-id" type="long">
                <column name="SEQ_ID" sql-type="NUMBER(8)">
                    <comment>changing sequence</comment>
                </column>
            </key-property>
            <generator class="assigned" />
        </composite-id>
        <property name="stockName" node="stock-name" not-null="true" type="string">
            <column name="NAME" sql-type="VARCHAR2(64)">
                <comment>stock's name</comment>
            </column>
        </property>
        <property name="stockType" node="stock-type" type="string">
            <column name="STOCK_TYPE" sql-type="VARCHAR2(64)">
                <comment>type of a stock</comment>
            </column>
        </property>
        <property name="stockRegCapi" node="stock-registered-capital" type="double">
            <column name="STOCK_REG_CAPI" sql-type="NUMBER(12,2)">
                <comment>registered capital of a stock</comment>
            </column>
        </property>
        <property name="stockActualCapi" node="stock-actual-capital" type="double">
            <column name="STOCK_ACTUAL_CAPI" sql-type="NUMBER(12,2)">
                <comment>actual capital of a stock</comment>
            </column>
        </property>
        <property name="capiType" node="captial-type" type="string">
            <column name="CAPI_TYPE" sql-type="VARCHAR2(64)">
                <comment>capi type of a stock</comment>
            </column>
        </property>
        <!-- 基于连接表的一对多双向关联,Many端 -->
        <join table="T_M_CORP_STOCK" inverse="true" optional="true">
            <key not-null="true" foreign-key="FK_CORP_STOCK">
                <column name="STOCK_ORG" sql-type="NUMBER(8)" />
                <column name="STOCK_ID" sql-type="NUMBER(8)" />
                <column name="STOCK_SEQ_ID" sql-type="NUMBER(8)" />
            </key>
            <!-- 注意:在本Sample中,如果下行embed-xml设置为true则导致循环引用,XML处理出错 -->
            <many-to-one name="corp" embed-xml="false" entity-name="Corp" node="corp-ref">
                <column name="CORP_ORG" sql-type="NUMBER(8)" />
                <column name="CORP_ID" sql-type="NUMBER(8)" />
                <column name="CORP_SEQ_ID" sql-type="NUMBER(8)" />
            </many-to-one>
        </join>
    </class>
    <class entity-name="GongShangOrg" node="org" table="T_DICT_ORG">
        <composite-id name="id" node="-">
            <key-property name="org" node="org" type="long">
                <column name="ORG" sql-type="NUMBER(8)">
                    <comment>database Code</comment>
                </column>
            </key-property>
            <key-property name="id" node="id" type="long">
                <column name="ID" sql-type="NUMBER(8)">
                    <comment>gong shang org identifier</comment>
                </column>
            </key-property>
            <key-property name="seqId" node="seq-id" type="long">
                <column name="SEQ_ID" sql-type="NUMBER(8)">
                    <comment>changing sequence</comment>
                </column>
            </key-property>
            <generator class="assigned" />
        </composite-id>
        <property name="orgName" node="org-name" type="string">
            <column name="NAME" sql-type="VARCHAR2(64)">
                <comment>city name</comment>
            </column>
        </property>
    </class>
    <class entity-name="AdvancedCorpInfo" node="adv-corp-info" table="T_CORP_OTHER">
        <composite-id name="id" node="-">
            <key-property name="org" node="org" type="long">
                <column name="ORG" sql-type="NUMBER(8)">
                    <comment>database Code</comment>
                </column>
            </key-property>
            <key-property name="id" node="id" type="long">
                <column name="ID" sql-type="NUMBER(8)">
                    <comment>corporation identifier</comment>
                </column>
            </key-property>
            <key-property name="seqId" node="seq-id" type="long">
                <column name="SEQ_ID" sql-type="NUMBER(8)">
                    <comment>changing sequence</comment>
                </column>
            </key-property>
            <generator class="assigned" />
        </composite-id>
        <property name="webSite" node="web-site" type="string">
            <column name="WEB_URL" sql-type="VARCHAR2(128)">
                <comment>web site url</comment>
            </column>
        </property>
        <property name="citySign" node="city-or-village" type="boolean">
            <column name="CITY_SIGN" sql-type="NUMBER(1)">
                <comment>city village flag</comment>
            </column>
        </property>
    </class>
    <class entity-name="City" node="City" table="T_DICT_CITY">
        <comment>
            <![CDATA[
                City dictionary
            ]]>
        </comment>
        <!-- 简单主键映射 -->
        <id name="cityId" node="-" type="long" >
            <column name="CITY_ID" sql-type="NUMBER(8)">
                <comment>city identifier</comment>
            </column>
            <generator class="sequence">
                <param name="sequence">SEQ_HXM</param>
            </generator>
        </id>
        <property name="cityName" node="-" type="string">
            <column name="NAME" sql-type="VARCHAR2(64)">
                <comment>city name</comment>
            </column>
        </property>
        <property name="cityCode" node="." type="int">
            <column name="CODE" sql-type="NUMBER(4)">
                <comment>city code</comment>
            </column>
        </property>
    </class>
</hibernate-mapping>
阅读全文
16 years ago
0
Perl

Perl知识集锦

语言
快速参考
Perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/perl
# 启用严格模式
use strict;
# 启用内建的警告功能
use warnings FATAL => 'all';
 
 
#####   其它           #####
 
# 老地方变量 $_,自动根据上下文推导此变量指向谁
foreach (qw/Alex Meng Cai/){
    print $_;  # 自动打印当前元素
}
$_ = "Hello\n";
print;  # 自动打印老地方变量
 
# 读取一行标准输入
my $line = <STDIN>;
 
# 在不产生歧义的前提下,函数调用的括号是可选的
chomp $line;  # 去除尾部的换行符
 
#####   标量数据类型   #####
 
# 数字,在内部总是以双精度浮点数来表示
my $num = 94605;      # my关键字创建词法变量,其作用域为当前代码块
$num = 6.02;
$num = 6.02e23;
# 可以使用下划线作为千分隔符
$num = 94_605;
# 非十进制整数
$num = 0b101010;
$num = 0777;
$num = 0xFF;
# 数字支持的操作符包括 + - * / %
$num = 10 % 3;
 
# 字符串
# 单引号字符串,总是字面含义
my $str = 'Hello \n World';
print $str; # Hello \n World
# 双引号字符串,支持转义字符
my $name = 'Alex';
my multiline = "
支持多行字符串
";
# 支持变量内插
print "Hello $name ${name} \n"; # Hello Alex!
# 字符串支持的操作符:
# 字符串连接
my $hello = 'Hello ' . $name;
# 字符串重复,重复次数非整数则向下取整,重复次数为0则生成空串
my $hello3 = $hello x 3; # HelloHelloHello
 
# 字符串和数字的自动转换
print 5 . 5;            # 只要是.操作符,就都认为是字符串,输出55
print 5 * "5";          # 只要是算术操作符,就认为是整数,输出25
# 甚至是 "5哈哈" * 5 也可以得出25
 
 
#####   标量变量   #####
# 标量变量必须以 $ 开头
# 支持双目赋值操作符
$num += 1;
$num *= 1;
# 未经明确初始化的变量,其初值未undef,可以转换为数字0
while ($n < 10) {
    print($n++)   # 12345678910
}
# 下面的函数用于判断一个变量是否被初始化
$isdefined = defined($n);
 
#####   控制结构   #####
 
# 裸块,可以用于控制变量作用域
{
    my i = 0;
}
 
# if分支
# 对于字符串来说,''和'0'的值为假
# 对于数字来说, 0的值为假
# 其它类型,先转换为数字或字符串再判断
# 支持取反操作符 !
if ($name eq 'Alex') {
    # 字符串比较操作符 eq ne lt gt le ge
}
elsif ($num == 0) {
    # 数字比较操作符 == != < > <= >=
}
else {}
 
# 后缀式条件修饰词
print "$n is zero" if $n == 0;
 
# unlese结构,当表达式不满足的时候执行
unless (0 == 1) {
    print "Of course!";
}
else {}
 
# until循环,直到表达式不满足时才退出循环
until (0 == 1) {
    print "天荒地老";
}
 
# while循环
my $count = 0;
while ($count < 10) {
    $count++;
}
 
# foreach循环
foreach $user (qw/Alex Meng Cai/){
    print $user;
}
 
# for循环
# 使用嵌套循环时,可以用标签
LABEL: for (my $i = 0; $i < 10; $i++) {
    # 下面三个关键字,后面的标签都是可选的
    last LABEL; # 中止循环,类似于其它语言的break
    next LABEL; # 进行下一轮迭代,类似于其它语言的continue
    redo LABEL; # 重新进行本轮迭代
}
 
#####   数组   #####
 
# 列表直接量,使用()包围
# 数组变量,使用@作为前导
@empty = ();
@nums = (1, 2, 3);
@nums = (1 .. 100); # 100个数字的列表
# $#nums表示获取数组nums的最后一个元素的索引值,即长度-1
$num_count = $#nums + 1;
# 字符串的列表
@users = ('Alex', 'Meng', 'Cai');
@users = qw(Alex Meng Cai);  # 等价于上面,空格分隔元素
# qw简写可以使用任何界定符
qw{};
 
# 列表式赋值:
($alex, $meng) = ('Alex', 'Meng');
# 互换两个元素的值
# 注意引用数组元素时需要标量前缀$
($nums[ 0 ], $nums[ 1 ]) = ($nums[ 1 ], $nums[ 0 ]);
 
# 将数组作为栈来操作
$num = pop @nums;
push @nums, 0;
 
# pop/push是在数组的尾部操作,shift/unshift则是在头部
@nums = (0, 1, 2);
shift @nums;
unshift @nums,0;
unshift @nums,-1;
print @nums;  # -1012
 
# 数组在字符串中的内插,元素之间自动加空格
print "\n@nums";  # -1 0 1 2
 
# 反转操作符,获得列表的逆序
@nums_r = reverse @nums;
 
# 排序操作符,以ASCII序排列
sort @nums_r;
 
 
#####   哈希   #####
 
%users = ('Alex', 30, 'Meng', 27);
 
# 胖箭头语法:
%users = (
 
    'Alex' => 30,
    'Meng' => 27
);
 
#CRUD操作
$users{'Alex'} = 32;
$users{'Meng'} = 28;
$users{'Cai'} = 3;
print $users{'Ya'};   # 获取不存在的键会得到undef
exists  $users{'Ya'}; # 判断指定的键是否存在
delete $users{'Ya'};  # 删除指定的键
 
# 哈希可以和列表相互转换,转换为列表是,键值都作为列表元素
# 但是转换后,键值对的顺序不能保证
@users = %users;
print scalar @users; # 6
 
# 获得键列表和值列表
my @keys = keys %users;
my @vals = values %users;
 
# each函数,每次调用,返回下一个键值对(的列表)类似于其它语言中的迭代器
while (($k, $v) = each %users) {
    printf "%s = %d\n", $k, $v;
}
 
# %ENV存放环境变量
printf "$ENV{PATH}\n"
 
 
#####   子程序   #####
use feature 'state';
sub add {
    # 参数存放在名为@_的数组中,注意$_[0]和老地方变量$_毫无关系
    $_[0] + $_[1];
    # 最后一个表达式的结果,作为子程序的返回值,你也可以使用 return 语句随时返回
}
# 调用子程序,使用&表达式
$result = &add(1, 2);
print $result;  # 3
# 对于已经知晓子程序定义的地方,可以省略&
print add(1, 2); # 3
# 如果子程序和Perl内置函数同名,不得省略&
sub chomp {print('chomp')};&chomp();
 
sub counter {
    # 持久性局部变量,跨越多次子程序存在,但是作用域限定在子程序内部
    state $count = 0;
    $count++;
    print $count;
}
counter counter counter; # 123
模块
Perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 引入模块以使用
# 在编译阶段,遇到下面的语句后会自动查找相关的代码并加载到当前脚本中
# /usr/share/perl/5.18/File/Basename.pm
use File::Basename;
 
# 你可以仅仅导入模块中特定的函数
use File::Basename qw/basename/;
 
my $fname = '/usr/bin/perl';
# 调用导入的函数
print basename $fname; # perl
 
# 不导入任何函数
use File::Basename qw//;
# 但是你仍然可以用全限定名称调用之
File::Basename::basename($fname)
上下文

在Perl中,相同的表达式,出现不同的地方(上下文)时,具有完全不同的意义。上下文包括标量上下文、列表上下文,在标量上下文中,Perl表达式的期望结果是标量,否则是列表。例如下面这段代码:

表达式@users在列表上下文中,会产生数组元素的列表,在标量上下文中则返回元素个数: 

某个具体表达式在不同上下文中的返回值是什么,各有不同,例如:

表达式 标量上下文 列表上下文…
阅读全文
16 years ago
0
C, Linux

POSIX线程编程

基本知识
什么是线程

一个程序中可以有多个代码指向序列,这每个序列就是一个线程(Thread),线程是进程内部的一个控制序列。一个进程至少具有一个执行线程。

Linux中通过fork创建的新进程,与Phtead API创建的线程是具有很大不同的:

  1. fork出的进程…
阅读全文
16 years ago
0
更多文章

Recent Posts

  • 人工智能知识 - 编程(二)
  • 人工智能知识 - 编程(一)
  • 人工智能知识 - 智能体
  • 人工智能知识 - Transformers和大模型
  • 人工智能知识 - 主要应用领域
ABOUT ME

汪震 | Alex Wong

江苏淮安人,现居北京。目前供职于腾讯云,专注国际化和AI落地。

GitHub:gmemcc

Git:git.gmem.cc

Email:gmemjunk@gmem.cc@me.com

ABOUT GMEM

绿色记忆是我的个人网站,域名gmem.cc中G是Green的简写,MEM是Memory的简写,CC则是我的小天使彩彩名字的简写。

我在这里记录自己的工作与生活,同时和大家分享一些编程方面的知识。

GMEM HISTORY
v2.00:微风
v1.03:单车旅行
v1.02:夏日版
v1.01:未完成
v0.10:彩虹天堂
v0.01:阳光海岸
MIRROR INFO
Meta
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
Recent Posts
  • 人工智能知识 - 编程(二)
    这一篇承接人工智能知识 - 编程(一)。前一篇已经梳理 AI 训练与推理编程的横向工程栈;本篇进入重点框架详解与 ...
  • 人工智能知识 - 编程(一)
    这一篇专门处理 AI 训练、微调、推理与部署中的编程栈问题。前几篇分别讲了机器学习基础、任务版图、Transfo ...
  • 人工智能知识 - 智能体
    这一篇处理模型之外的系统层问题,包括上下文工程、Harness Engineering、检索增强生成(RAG)与 ...
  • 人工智能知识 - Transformers和大模型
    这一篇聚焦现代大模型主线,内容从 Transformer 架构出发,延伸到语言模型、多模态模型、预训练与微调,以 ...
  • 人工智能知识 - 主要应用领域
    这一篇从常用算法进入机器学习基础概念、经典机器学习与神经网络,重点讨论“模型如何被构造、训练、评估与正则化”。前 ...
  • 人工智能知识 - 算法和机器学习
    这一篇从常用算法进入机器学习基础概念、经典机器学习与神经网络,重点讨论“模型如何被构造、训练、评估与正则化”。前 ...
  • 人工智能知识 - 数学基础
    这一篇整理 AI 所需的数学基础,包括基础数学、线性代数、微积分与概率论统计。它回答的核心问题是:模型里的向量、 ...
  • 人工智能知识 - 简介
    这一篇作为整套 AI 总纲的导论,先回答更根本的问题,不急于进入公式和具体模型细节:什么叫智能,人工智能究竟在试 ...
  • 多语言敏感信息检测模型训练日志
    这篇文章记录一个多语言敏感信息识别项目的完整训练日志。它关注的是工程路径本身:原始 AI 合成语料如何被清洗成可 ...
  • DevPod on Kubernetes: turning devcontainer.json into a persistent remote workspace
    DevPod is an open source workspace manager ...
  • OpenClaw: Architecture, Components, and Deployment Notes
    Four Months, 343,000 Stars On November 24, 2025, ...
  • Replacing Docker Desktop with Colima on macOS
    Colima is one of the cleanest ways ...
  • Kubernetes GPU Sharing
    GPU sharing in Kubernetes depends on what ...
  • Investigating and Solving the Issue of Failed Certificate Request with ZeroSSL and Cert-Manager
    In this blog post, I will walk ...
  • A Comprehensive Study of Kotlin for Java Developers
    Introduction Purpose of the Study Understanding the Mo ...
  • LangChain: Architecture, LCEL, Agents, LangGraph, Retrieval, and Production Patterns
    LangChain is no longer best understood as ...
  • Kubernetes Migration
    Migrating a Kubernetes cluster from one cloud ...
  • Terraform: a practical guide to infrastructure as code
    Terraform is an infrastructure-as-code tool. You describ ...
TOPLINKS
  • Zitahli's blue 91 people like this
  • 梦中的婚礼 64 people like this
  • 汪静好 61 people like this
  • 那年我一岁 36 people like this
  • 为了爱 28 people like this
  • 小绿彩 26 people like this
  • 彩虹姐姐的笑脸 24 people like this
  • 杨梅坑 6 people like this
  • 亚龙湾之旅 1 people like this
  • 汪昌博 people like this
  • 2013年11月香山 10 people like this
  • 2013年7月秦皇岛 6 people like this
  • 2013年6月蓟县盘山 5 people like this
  • 2013年2月梅花山 2 people like this
  • 2013年淮阴自贡迎春灯会 3 people like this
  • 2012年镇江金山游 1 people like this
  • 2012年徽杭古道 9 people like this
  • 2011年清明节后扬州行 1 people like this
  • 2008年十一云龙公园 5 people like this
  • 2008年之秋忆 7 people like this
  • 老照片 13 people like this
  • 火一样的六月 16 people like this
  • 发黄的相片 3 people like this
  • Cesium学习笔记 90 people like this
  • IntelliJ IDEA知识集锦 59 people like this
  • Bazel学习笔记 38 people like this
  • 基于Kurento搭建WebRTC服务器 38 people like this
  • PhoneGap学习笔记 32 people like this
  • NaCl学习笔记 32 people like this
  • 使用Oracle Java Mission Control监控JVM运行状态 29 people like this
  • Ceph学习笔记 27 people like this
  • 基于Calico的CNI 27 people like this
Tag Cloud
ActiveMQ AspectJ CDT Ceph Chrome CNI Command Cordova Coroutine CXF Cygwin DNS Docker eBPF Eclipse ExtJS F7 FAQ Groovy Hibernate HTTP IntelliJ IO编程 IPVS JacksonJSON JMS JSON JVM K8S kernel LB libvirt Linux知识 Linux编程 LOG Maven MinGW Mock Monitoring Multimedia MVC MySQL netfs Netty Nginx NIO Node.js NoSQL Oracle PDT PHP Redis RPC Scheduler ServiceMesh SNMP Spring SSL svn Tomcat TSDB Ubuntu WebGL WebRTC WebService WebSocket wxWidgets XDebug XML XPath XRM ZooKeeper 亚龙湾 单元测试 学习笔记 实时处理 并发编程 彩姐 性能剖析 性能调优 文本处理 新特性 架构模式 系统编程 网络编程 视频监控 设计模式 远程调试 配置文件 齐塔莉
Recent Comments
  • xdemo on 人工智能知识 - 编程(二)
  • 杨松涛 on snmp4j学习笔记
  • kaka on Cilium学习笔记
  • JackZhouMine on Cesium学习笔记
  • 陈黎 on 通过自定义资源扩展Kubernetes
  • qg on Istio中的透明代理问题
  • heao on 基于本地gRPC的Go插件系统
  • 黄豆豆 on Ginkgo学习笔记
  • cloud on OpenStack学习笔记
  • 5dragoncon on Cilium学习笔记
  • Archeb on 重温iptables
  • C/C++编程:WebSocketpp(Linux + Clion + boostAsio) – 源码巴士 on 基于C/C++的WebSocket库
  • jerbin on eBPF学习笔记
  • point on Istio中的透明代理问题
  • G on Istio中的透明代理问题
  • 绿色记忆:Go语言单元测试和仿冒 on Ginkgo学习笔记
  • point on Istio中的透明代理问题
  • 【Maven】maven插件开发实战 – IT汇 on Maven插件开发
  • chenlx on eBPF学习笔记
  • Alex on eBPF学习笔记
  • CFC4N on eBPF学习笔记
  • 李运田 on 念爷爷
  • yongman on 记录一次KeyDB缓慢的定位过程
©2005-2026 Gmem.cc | Powered by WordPress | 京ICP备18007345号-2