摘要: # 读写文件.#/usr/bin/perl -wuse 5.010; # Use 'say'.# Read from file.open F, "<data.txt" or die "fail: open()";my @arr = <F>; # Read all data to array.close F;# Write to file.open F, ">res.txt" # Use ">>" if you want to append at end. or d 阅读全文
posted @ 2011-07-17 14:59 walfud 阅读(855) 评论(0) 推荐(0) 编辑
摘要: $$: 当前进程号.$!: 上一条命令出错, 所返回的错误信息.$?: 存储前一次 system 或者 反引号全音的命令的返回值.$#arr: 为数组 @arr 的最后一个索引值.$@: eval 捕获到的错误信息.%ENV: 是环境变量%SIG: 是信号量哈希Perl 中的正则表达式: 用 /i 来进行大小写无关的匹配. 用 /s 来使 . 可以匹配换行符. 用 /x 使匹配模式的书写变为松散格式. 用 /m 使 ^ 和 $ 可以匹配字符串内的换行. 把 m 当成 multiple lines 会比较好记.捕获变量: $` 保存了正则表达式引擎在找到匹配段落之前略过的部分. $& 模 阅读全文
posted @ 2011-07-11 22:01 walfud 阅读(216) 评论(0) 推荐(0) 编辑
摘要: 不推荐这样的用法, 因为很容易写错而且难于发现. 对于有 else if 的结构更是难于阅读. 老 C/Perl 程序员通常都会因为效率等因素选择此写法. 这里介绍此用法是为了阅读而不是为了让它出现在你的代码里. 阅读全文
posted @ 2011-07-03 20:18 walfud 阅读(372) 评论(0) 推荐(0) 编辑
摘要: 有表如下:有如下查询:Select id, COUNT(*) from t1 group by id ;将 Select 结果插入表:-- 将其插入新的临时表 #tSelect id, COUNT(*) as cnt into #t from t1 -- 每个列都要有个列名, 因此 COUNT 后要加 as. group by id ; -- 因为首次插入建立新表, 所以 into 写在 Select 中-- 将数据插入已存在的临时表Insert into #t -- 对已存在的表插入 Select 的结果 Select id, COUNT(*) from t1 -- 列不必有列名 group 阅读全文
posted @ 2011-07-02 00:17 walfud 阅读(3952) 评论(0) 推荐(0) 编辑
摘要: Use test ;Select * from t1 ;-- Select 会返回结果集Declare @temp int ;Select @temp = COUNT(*) from t1 ;-- 不返回结果集 这不是摆弄, 而是当你在程序中写 SQL 语句并期待数据库返回结果集的时候非常有用. 因为同时执行多个 Select 语句返回多个结果集, 对程序的分析增加了不必要的复杂性. 阅读全文
posted @ 2011-07-01 23:50 walfud 阅读(255) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2011-06-26 21:25 walfud 阅读(307) 评论(0) 推荐(0) 编辑
摘要: if ((2 & 2) > 1) // (2 & 2) 一定要加括号 阅读全文
posted @ 2011-06-25 16:53 walfud 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2011-06-11 10:19 walfud 阅读(215) 评论(0) 推荐(0) 编辑
摘要: There are many funny stories or reasons for why things going this way 阅读全文
posted @ 2011-06-09 19:35 walfud 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 阅读全文
posted @ 2011-06-09 11:12 walfud 阅读(2247) 评论(0) 推荐(0) 编辑
摘要: 当引用类型内的枚举时,无需指定枚举的名称。 文件范围的枚举定义相当于常量,也不需要限定名。 阅读全文
posted @ 2011-06-08 21:44 walfud 阅读(1098) 评论(0) 推荐(0) 编辑
摘要: 书, 看过了, 未必记住了; 即使记住了, 未必掌握了; 即便掌握了, 又未必能融会成能力. 阅读全文
posted @ 2011-06-01 13:01 walfud 阅读(993) 评论(0) 推荐(0) 编辑
摘要: 应该都是我自己看过的书, 走过的路, 发现路标错了, 真恨不得拆了它! 不过还得感谢它让我对问题记忆更深, 了解更深, 否则也不会发现错误. 阅读全文
posted @ 2011-05-26 09:23 walfud 阅读(727) 评论(0) 推荐(0) 编辑
摘要: 引子不同的古老的或现代些的书籍... 阅读全文
posted @ 2011-05-24 15:51 walfud 阅读(331) 评论(0) 推荐(0) 编辑
摘要: From <The C Programming Language>(p.53)OPERATORSASSOCIATIVITY ( ) [ ] -> .Left to right ! ~ ++ -- + - * & ( type ) sizeofRight to left * / %Left to right + -Left to right << >>Left to right < <= > >=Left to right == !=Left to right &Left to right ^Left to rig 阅读全文
posted @ 2011-05-18 22:21 walfud 阅读(907) 评论(3) 推荐(0) 编辑
摘要: 一个比较全面的二叉查找树 阅读全文
posted @ 2011-05-17 20:05 walfud 阅读(308) 评论(0) 推荐(0) 编辑
摘要: 红黑树是一种二叉查找树, 但在每个基点上增加一个存储位表示结点的颜色, 可以说是 RED 或 BLACK. 通过对任何一条从跟到叶子的路径上各个结点着色方式的限制, 红黑树确保没有一条路径会比其他路径长出两倍, 因而是接近平衡的. 阅读全文
posted @ 2011-05-17 10:41 walfud 阅读(3867) 评论(1) 推荐(0) 编辑
摘要: // Tree.h//#ifndef TREE#define TREE#include <stddef.h>struct Node{ int key ; Node *p ; // Pointer to parent Node *l ; // Pointer to left child Node *r ; // Pointer to right child Node(int key) { this->key = key ; p = l = r = NULL ; } // Bitwise copy constructor is good enough // Replace is 阅读全文
posted @ 2011-05-16 16:14 walfud 阅读(517) 评论(0) 推荐(0) 编辑
摘要: cout 是一个强大的对象, 虽说目前的使用率很低, 但是当你需要到它的时候, 它就在这里. 阅读全文
posted @ 2011-05-15 21:08 walfud 阅读(78312) 评论(0) 推荐(4) 编辑
摘要: 当一个条件语句过于冗长, 需要被 divided into multi-line 时, 我们应该把优先级操作符放在什么位置呢? I suggest that when a condition statement need divided into multi-line, we'd better put Priority operator at the beginning of the newline. 来看看为什么吧! 阅读全文
posted @ 2011-05-15 10:02 walfud 阅读(204) 评论(0) 推荐(0) 编辑
摘要: In C++ Primer:inline Function: The inline specification is only a request to the compiler. The compiler may choose to ignore this request. ... Unlike other function definitions, inlines should be defined in header files. To expand the code of an inline function at the point of call, the compiler mus 阅读全文
posted @ 2011-05-14 20:21 walfud 阅读(388) 评论(0) 推荐(0) 编辑
摘要: 当在类外定义一个静态成员是, 我们不能重复指定 static 关键字. 这个关键字只能出现在类中的声明中. 阅读全文
posted @ 2011-05-14 19:45 walfud 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 让 gcc 自动为你解决依赖关系 阅读全文
posted @ 2011-05-14 15:32 walfud 阅读(166) 评论(0) 推荐(0) 编辑
摘要: 你知道它们错在哪里了么? cout (true ? 0, 1 : 0, 2) endl ; // Cause a warning cout (false ? 0, 1 : 0, 2) endl ; // Cause a warning 整个的三元表达式都无效! 阅读全文
posted @ 2011-05-13 14:04 walfud 阅读(866) 评论(0) 推荐(1) 编辑
摘要: 在 SQL Server 中 --读取库中的所有表名 --读取指定表的所有列名 阅读全文
posted @ 2011-05-13 13:07 walfud 阅读(268) 评论(0) 推荐(0) 编辑
摘要: Vim Shorthand! Come on, let's complete and extend it. And then, it will become yours! But don't forget to leave me a message to share your wisdom! Spread without any constains! 阅读全文
posted @ 2011-05-11 20:13 walfud 阅读(626) 评论(2) 推荐(0) 编辑
摘要: // main.cpp// Find the N-th minimum value, based on Partition#include <iostream>#include <iterator>#include <algorithm>using namespace std ;int Minimum_N(int arr[], int s, int e, int n){ // Partition int j = s ; for (int i = s ;i < e-1 ;i++) { // Exchage two integer if (arr[i] & 阅读全文
posted @ 2011-05-06 16:18 walfud 阅读(1315) 评论(0) 推荐(0) 编辑
摘要: 问题在于copy(arr, arr + sizeof(arr), out) ; 一个指针 + 一个整数 的结果是指针偏移值加上整数所代表其元素的偏移值. 阅读全文
posted @ 2011-05-05 19:34 walfud 阅读(259) 评论(0) 推荐(0) 编辑
摘要: memcpy(&arr[0], &arr[1], 6) ; 这句话有问题, memcpy 是内存拷贝函数, 第三个参数以 byte 为单位进行复制, 然而一个 int 占用 4个byte , 因此, 拷贝的结果是错误的. 阅读全文
posted @ 2011-05-05 19:15 walfud 阅读(542) 评论(0) 推荐(0) 编辑
摘要: 快排是一种不稳定排序, 其最差时间复杂度是 n^2. 但快排是通常排序的最佳实践选择. 因为其平均期望运行时间是 nlog(n). 阅读全文
posted @ 2011-04-27 10:46 walfud 阅读(332) 评论(1) 推荐(0) 编辑
摘要: #include <iostream> #include <iterator> #include <algorithm> using namespace std ; ostream_iterator output(cout, " ") ; // 关联cout,设置分隔符 copy(vec.begin(), vec.end(), output) ; // 元素拷贝到ostream_iterator所指向的对象cout cout <<endl ; // 别忘了加一个换行 阅读全文
posted @ 2011-04-27 09:52 walfud 阅读(777) 评论(0) 推荐(1) 编辑
摘要: 还在为 const 关键字苦恼么? 来看看这篇文章吧 阅读全文
posted @ 2011-04-19 18:12 walfud 阅读(191) 评论(0) 推荐(0) 编辑
摘要: 此算法优秀在最多比较了 3*n / 2 次就完成了任务. 并且将待分析数组分别以奇数和偶数处理, 从而大大降低了分析的难度. 阅读全文
posted @ 2011-04-17 09:18 walfud 阅读(977) 评论(0) 推荐(0) 编辑
摘要: 堆排序为什么美? 记得在 coolshell.cn看到一个文章, 是一个日本人做的排序算法的演示程序, http://coolshell.cn/articles/3933.html, 很是不错, 当你看到堆排序时, 就会被那魔法般的变幻所吸引... 后来仔细思考堆排序, 堆排序为什么美? 堆排序是一个迭代的过程, 每次子排序对于整个带排序的数组是以 2^n 的前进速度进行的, 所以建堆完成后, 排序的时间复杂度是 nlog(n). 面对这个公式我曾经很淡定, 但是当我看到 n > 200 甚至更多的时候, 我变得敏感起来. 什么是优秀, 优秀是在思想上下功夫, 不是用时间来补拙劣. 阅读全文
posted @ 2011-04-15 13:06 walfud 阅读(551) 评论(2) 推荐(0) 编辑
摘要: #define cat(x,y) x ## y#define xcat(x, y) cat(x,y)....// 有如下调用int main(){ ... cat(1, 2) ; // OK , 这是没问题的 cat(cat(1, 2), 3) ; // Error , 这里就有问题了, 据说会解析成 'cat ( 1 , 2 )3' xcat(cat(1, 2), 3) ; // OK , 这又是问什么呢? 加了一层就好了? ... return 0 ;}解答:#与##在宏定义中的--宏展开#include <stdio.h>#define f(a,b) a##b 阅读全文
posted @ 2011-04-08 13:37 walfud 阅读(280) 评论(0) 推荐(0) 编辑
摘要: 读者最好能养成按照字符来理解正则表达式的习惯.(p.8) 如果连字符出现在字符组的开头, 他表示的就是一个普通字符, 而不是一个范围. 同样的道理, 问号和点号通常被当作元字符处理, 但在字符组中则不是如此(说明白一点就是, [0-9A-Z_!.?]里面, 真正的特殊字符只有那两个连字符).(p.9) 请记住, 排除行字符组表示"匹配一个未列出的字符(match a character that... 阅读全文
posted @ 2011-04-02 19:00 walfud 阅读(415) 评论(0) 推荐(0) 编辑
摘要: verb. Upper case in First character : Select , Group , Having , Create , Drop , Insert , Delete ...prep. lower case in all characters : where , as , and , or , by ...System Function. Upper case in all characters : GETDATE , YEAR , COUNT ... 阅读全文
posted @ 2011-03-26 10:54 walfud 阅读(85) 评论(0) 推荐(0) 编辑
摘要: The range of both int and float depends onthe machine you are using;(p.9) If an arithmetic operator has integer operands, an integer operation is performed. If an arithmetic operator has one floating-point operand nad one integer operand, however, the integer will be converted to floating point bef. 阅读全文
posted @ 2011-03-24 17:14 walfud 阅读(696) 评论(0) 推荐(0) 编辑
摘要: 异或操作是个伟大的发现. 它不丢失任何一个操作数.     首先, a^b的结果中以一种组合方式保存了a与b的值.     通过 (a^b)^a即可从组合中还原出b原来的值. 同理, 再次从组合a中还原出b, 将结果赋给a即可实现互换. 阅读全文
posted @ 2011-03-23 20:34 walfud 阅读(300) 评论(2) 推荐(2) 编辑
摘要: size_t Count(int x){ size_t uiCount =0; while (0 != x) { ++uiCount ; x &= x-1; //x &= x-1 ; deletes the rightmost 1-bit in x } return uiCount ;}每次 x - 1 都会导致 x 的二进制表示里最右侧的 1 与 x 原来的二进制表示 相反.x = 10010110x - 1 = 10010101x &= x-1 -> 10010100 // 至此, 最右侧的 1-bit 被delete掉了. 如此循环往复, 统计所有 ... 阅读全文
posted @ 2011-03-23 20:32 walfud 阅读(122) 评论(0) 推荐(0) 编辑