恩,离2012又近了。
版权声明:可以任意转载,但转载时必须标明原作者charlee、原始链接http://tech.idv2.com/2008/05/29/perl-one-liner/以及本声明。
哦……Perl真的是太博大精深了。尤其是它的One-Liner程序,每一行都是优美的杰作啊。
下面搜集了一些很有用的One-Liner。大部分资料来自于 这里、 这里、 这里。
替换
将所有C程序中的foo替换成bar,旧文件备份成.bak
@_@生活总需要一些梯子!永久网址:http://114er.blogspot.com
data=0:31
data =
Columns 1 through 17
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Columns 18 through 32
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
>> sum(data.^3)
ans =
246016
总计 96424
-rwx------ 1 Jack Ubuntu 91197 Dec 14 09:07 binutils-2.20.1-or32-1.0rc1.patch.bz2
-rwx------ 1 Jack Ubuntu 17501436 Dec 14 09:07 binutils-2.20.1.tar.bz2
-rwx------ 1 Jack Ubuntu 74807 Dec 14 09:35 gcc-4.5.1-or32-1.0rc2.patch.bz2
-rwx------ 1 Jack Ubuntu 66121821 Dec 14 09:35 gcc-4.5.1.tar.bz2
-rwx------ 1 Jack Ubuntu 106992 Dec 14 09:19 newlib-1.18.0-or32-1.0rc1.patch.bz2
-rwx------ 1 Jack Ubuntu 13598301 Dec 14 09:19 newlib-1.18.0.tar.gz
-rwx------ 1 Jack Ubuntu 1225317 Dec 14 08:58 or1ksim-0.5.0rc2.tar.bz20 : wb_dat_o <= 32'h18000000;
1 : wb_dat_o <= 32'h18800000;
2 : wb_dat_o <= 32'ha8840100;
3 : wb_dat_o <= 32'h44002000;
4 : wb_dat_o <= 32'h15000000;`timescale 1ns/1ns
module UART(rst_n,clk50M,txd);
input rst_n,clk50M;
output txd;
reg txd_start;
reg [7:0] txd_data;
wire txd_busy;
async_transmitter async_transmitter(
.rst_n(rst_n),
.clk(clk50M),
.txd_start(txd_start),
.txd_data(txd_data),
.txd_busy(txd_busy),
.txd(txd)
);
always@(negedge rst_n,posedge clk50M)
begin
if(!rst_n)
begin
txd_data<=8'h0;
txd_start<=1'b0;
end
else
if((txd_busy==1'b0) &&(txd_start==1'b0))
begin
txd_start<=1'b1;
txd_data<=txd_data+8'h1;
end
else
txd_start<=1'b0;
end
endmodule module BMX(out, x2, a, s, m1, m0);
output out;input x2, a, s, m1, m0;reg out;wire [2:0] mux_w;
assign mux_w = {x2, a, s};
always @(mux_w or m1 or m0) case(mux_w) 3'b010 : out = ~m1; 3'b001 : out = m1; 3'b110 : out = ~m0; 3'b101 : out = m0; 3'b011 : out = 0; 3'b111 : out = 0; 3'b000 : out = 1; 3'b100 : out = 1; endcase
endmodule
function [genpoly,t] = rsgenpoly(N, K, varargin)
%RSGENPOLY Generator polynomial of Reed-Solomon code.
% GENPOLY = RSGENPOLY(N,K) returns the narrow-sense generator polynomial of a
% Reed-Solomon code with codeword length N and message length K. The codeword
% length N must have the form 2^m-1 for some integer m between 3 and 16. The
% output GENPOLY is a Galois row vector that represents the coefficients of
% the generator polynomial in order of descending powers. The narrow-sense
% generator polynomial is (X-alpha)*(X-alpha^2)*...*(X-alpha^(N-K)), where
% alpha is a root of the default primitive polynomial for the field GF(N+1).
%
% GENPOLY = RSGENPOLY(N,K,PRIM_POLY) is the same as the syntax above, except
% that PRIM_POLY specifies the primitive polynomial for GF(N+1) that has alpha
% as a root. PRIM_POLY is an integer whose binary representation indicates
% the coefficients of the primitive polynomial in order of descending powers.
% To use the default primitive polynomial, set PRIM_POLY to [].
%
% GENPOLY = RSGENPOLY(N,K,PRIM_POLY,B) returns the generator polynomial
% (X-alpha^B)*(X-alpha^(B+1))*...*(X-alpha^(B+N-K-1)), where B is an integer
% and alpha is a root of PRIM_POLY.
%
% [GENPOLY,T] = RSGENPOLY(...) returns T, the error-correction capability of
% the code.
%
% Examples:
% g = rsgenpoly(7,3) % Narrow-sense generator polynomial
% g2 = rsgenpoly(7,3,13) % Narrow-sense generator polynomial,
% % with respect to primitive polynomial
% % D^3+D^2+1
% g3 = rsgenpoly(7,3,[],4) % Use b=4
%
% See also GF, RSENC, RSDEC.
% Copyright 1996-2007 The MathWorks, Inc.
% $Revision: 1.4.4.2 $ $Date: 2007/09/14 15:57:43 $
% Initial checks
error(nargchk(2,4,nargin,'struct'));
% Number of optional input arguments
nvarargin = nargin - 2;
% Error-correcting capability
t = floor((N-K)/2);
t2 = N-K;
m = log2(N+1);
def_primpoly = 1;
b = 1; % Default : narrow-sense
if any([~isscalar(N) | ~isscalar(K) | floor(N)~=N | floor(K)~=K])
error('comm:rsgenpoly:InvalidNK','N and K must be positive scalar integers.');
end
if t2<1
error('comm:rsgenpoly:NLessThanK','N must be larger than K.');
end
if m~=floor(m) | m<3 | m>16
error('comm:rsgenpoly:InvalidN','N must equal 2^m-1 for some integer m between 3 and 16.')
end
if ~isempty(varargin)
prim_poly = varargin{1};
% Check prim_poly
if isempty(prim_poly)
if ~isnumeric(prim_poly)
error('comm:rsgenpoly:InvalidDefaultPrim_Poly','To use the default PRIM_POLY, it must be marked by [].');
end
else
if ~isscalar(prim_poly)
error('comm:rsgenpoly:Prim_PolyNotScalar','PRIM_POLY must be a scalar integer.');
end
% ZZZ add isprimitive once it's available
def_primpoly = 0;
end
if nvarargin==2
b = varargin{2};
if ~isscalar(b) | floor(b)~=b
error('comm:rsgenpoly:BNotAnInt','B must be an integer scalar.');
end
end
end
% Alpha is the primitive element of this GF(2^m) field
if def_primpoly == 1
alpha = gf(2,m);
else
alpha = gf(2,m,prim_poly);
end
genpoly = 1;
for k=mod(b+[0:t2-1],N)
evalc('genpoly = conv(genpoly,[1 alpha.^(k)]);');
end