由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - PERL问题
相关主题
怎么非ASCII字符就过滤不了呢?[Perl]stl Compare为何需要重载()?
问个Perl的简单问题现在还有人猛钻研c++模板编程,generic programming, 甚至meta-programming么 模板编程简单用用还可以 我现在工作中能用到一点点。不过也是属于组里大牛搭好了架子的 我
perl problem这个是undefined的吗?
问个perl的程序what's wrong with this scripts?variable passing?
Perl: How to return 2 dimention array pls ?C# HtmlElement.InvokeMember at Amazon.com
How to write "ip address => integer" in perl, python, Javascript etc. ?how to sed from grep output in c shell? (转载)
perl能不能一次把一个str中的a替换成x,b替换成y? (转载)a linux disk IO question (转载)
也问个regular expression的问题这里的人用BOOST都是用来做什么?
相关话题的讨论汇总
话题: perl话题: year话题: map话题: years话题: write
进入Programming版参与讨论
1 (共1页)
s*******t
发帖数: 2896
1
请问这个在perl里有没有简单写法?
$d="";
foreach (@years) {$d=$d." YEAR$_";}
S**I
发帖数: 15689
2
$d = ' YEAR'.join(' YEAR',@years);

【在 s*******t 的大作中提到】
: 请问这个在perl里有没有简单写法?
: $d="";
: foreach (@years) {$d=$d." YEAR$_";}

d****p
发帖数: 685
3

$d = map " YEAR$_", @years;

【在 s*******t 的大作中提到】
: 请问这个在perl里有没有简单写法?
: $d="";
: foreach (@years) {$d=$d." YEAR$_";}

t****t
发帖数: 6806
4
i believe this is not what he wanted, you get the element count of @year
only.

【在 d****p 的大作中提到】
:
: $d = map " YEAR$_", @years;

d****p
发帖数: 685
5
right. map returns a list. should be joined.

【在 t****t 的大作中提到】
: i believe this is not what he wanted, you get the element count of @year
: only.

s*******t
发帖数: 2896
6
@years=qw(01 02 03);
print join " " , map "YEAR".$_ , @years;
That's cool. Thank you!
s*******t
发帖数: 2896
7
又有个问题,就不开新贴了,免得斑竹说我刷屏。
是这样:我在regular expression匹配时用了/m,所以^和$代表行开始和行结束。我现
在还想匹配整个字符串结束,怎么办呢?
t****t
发帖数: 6806
8
you may use \A and \Z and \z.

【在 s*******t 的大作中提到】
: 又有个问题,就不开新贴了,免得斑竹说我刷屏。
: 是这样:我在regular expression匹配时用了/m,所以^和$代表行开始和行结束。我现
: 在还想匹配整个字符串结束,怎么办呢?

g*****e
发帖数: 172
9
m//g

【在 s*******t 的大作中提到】
: 又有个问题,就不开新贴了,免得斑竹说我刷屏。
: 是这样:我在regular expression匹配时用了/m,所以^和$代表行开始和行结束。我现
: 在还想匹配整个字符串结束,怎么办呢?

s*******t
发帖数: 2896
10
perl能不能用list做index存取array?比如$arr[(1..3,4,8)]=5;
相关主题
How to write "ip address => integer" in perl, python, Javascript etc. ?stl Compare为何需要重载()?
perl能不能一次把一个str中的a替换成x,b替换成y? (转载)现在还有人猛钻研c++模板编程,generic programming, 甚至meta-programming么 模板编程简单用用还可以 我现在工作中能用到一点点。不过也是属于组里大牛搭好了架子的 我
也问个regular expression的问题这个是undefined的吗?
进入Programming版参与讨论
t****t
发帖数: 6806
11
yes, you can. but use @ to indicate slices, and use repetition operation to
repeat RHS (this is not like matlab, where scalars are automatically
expanded to match vector/matrix size)
@arr[(1..3, 4, 8)] = (5) x 5;

【在 s*******t 的大作中提到】
: perl能不能用list做index存取array?比如$arr[(1..3,4,8)]=5;
s*******t
发帖数: 2896
12
那perl能不能对list做component-wise运算,比如
@a=(1..5);
@b=(2..6);
print @a*@b; # get 25
我想算(1*2,2*3,...,5*6),有省事的办法吗?或者用字符串运算也行。
t****t
发帖数: 6806
13
@a=map { $_*($_+1) } (1..5);
but this is not generic component-wise calculation.
you may, though, write
@c = map { $a[$_] * $b[$_] } (0..4);
but this is dumb.
BTW, if you write in perl, think in perl. don't think in matlab and write
perl. you can translate literally, but you will result in dumb code.

【在 s*******t 的大作中提到】
: 那perl能不能对list做component-wise运算,比如
: @a=(1..5);
: @b=(2..6);
: print @a*@b; # get 25
: 我想算(1*2,2*3,...,5*6),有省事的办法吗?或者用字符串运算也行。

s*******t
发帖数: 2896
14
多谢!准备先用这个
map {$a[$_]*$b[$_]} (0..@a-1)
要是0..@a-1能简写就好了。满脑袋都是R,seq(along=a),thinking不好改啊,跟问题
相关。
a***y
发帖数: 2803
15
print map { $a[$_] * $b[$_] } 0..$#a;

【在 s*******t 的大作中提到】
: 那perl能不能对list做component-wise运算,比如
: @a=(1..5);
: @b=(2..6);
: print @a*@b; # get 25
: 我想算(1*2,2*3,...,5*6),有省事的办法吗?或者用字符串运算也行。

1 (共1页)
进入Programming版参与讨论
相关主题
这里的人用BOOST都是用来做什么?Perl: How to return 2 dimention array pls ?
请问如何在球体表面均匀分布N个点(赠送包子) (转载)How to write "ip address => integer" in perl, python, Javascript etc. ?
[合集] 问个土问题 printf, 别Pengperl能不能一次把一个str中的a替换成x,b替换成y? (转载)
[合集] perl symbol tables 一问也问个regular expression的问题
怎么非ASCII字符就过滤不了呢?[Perl]stl Compare为何需要重载()?
问个Perl的简单问题现在还有人猛钻研c++模板编程,generic programming, 甚至meta-programming么 模板编程简单用用还可以 我现在工作中能用到一点点。不过也是属于组里大牛搭好了架子的 我
perl problem这个是undefined的吗?
问个perl的程序what's wrong with this scripts?variable passing?
相关话题的讨论汇总
话题: perl话题: year话题: map话题: years话题: write