亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 2032 | 回復(fù): 14
打印 上一主題 下一主題

有關(guān)數(shù)組 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2012-12-11 23:52 |只看該作者 |倒序瀏覽
我想問個問題,比如我有一個數(shù)組@a=(aa,bb,cc,dd,ee,ff,ad,fe,ag,hh,ssd,ffg,h,j,k,l,asdfag)可能有上百個,現(xiàn)在我這么操作
for($i=0;$i<=$#a;$i++)
{
   if($a[$i]=~/ee/)
  {
     $a = $i;
  }
  elsif($a[$i]=~/j/)
{
   $b = $i;
}  
}
大致是這樣。我想要的是提取dd到k之間的所有元素放到新的數(shù)組中(包括dd和k)并且將他們在元數(shù)組中刪除。。我應(yīng)該怎么做。
我最初的想發(fā)是push(@number,$a[$a-1..$b+1]);不過好像這樣操作是無效的。。
誰會的話請指教下。謝謝

論壇徽章:
2
射手座
日期:2014-10-10 15:59:4715-16賽季CBA聯(lián)賽之上海
日期:2016-03-03 10:27:14
2 [報告]
發(fā)表于 2012-12-12 00:56 |只看該作者
回復(fù) 1# zlzty
  1. perl -le '
  2. @a=(aa,bb,cc,dd,ee,ff,ad,fe,ag,hh,ssd,ffg,h,j,k,l,asdfag);
  3. map{$i++;if(/dd/../k/){push @b,$_;splice(@a,--$i,1)}}@a;
  4. print "@b","\n","@a"'
  5. dd ee ff ad fe ag hh ssd ffg h j k
  6. aa bb cc l asdfag
復(fù)制代碼

論壇徽章:
0
3 [報告]
發(fā)表于 2012-12-12 02:26 |只看該作者
  1. #!/usr/bin/perl

  2. use strict;
  3. use warnings;

  4. my @arr = qw(aa bb cc dd ee ff ad fe ag hh ssd ffg h j k l asdfag);
  5. my @filtered = grep { /^dd$/../^k$/ } @arr;

  6. my %final;
  7. @final{@arr} = ();
  8. delete @final{@filtered};
  9. my @output = keys %final;
  10. print "@output";
復(fù)制代碼

論壇徽章:
0
4 [報告]
發(fā)表于 2012-12-13 14:34 |只看該作者
3Q回復(fù) 3# iLRainyday


   

論壇徽章:
0
5 [報告]
發(fā)表于 2012-12-13 14:34 |只看該作者
3Q回復(fù) 2# yinyuemi


   

論壇徽章:
6
卯兔
日期:2013-11-26 14:52:02丑牛
日期:2014-02-19 18:01:25卯兔
日期:2014-05-20 20:34:06白羊座
日期:2014-05-23 13:39:232015亞冠之大阪鋼巴
日期:2015-08-07 20:57:582015亞冠之大阪鋼巴
日期:2015-09-02 14:09:09
6 [報告]
發(fā)表于 2012-12-13 15:56 |只看該作者
yinyuemi 發(fā)表于 2012-12-12 00:56
回復(fù) 1# zlzty

請問下怎么把握$i的變化,我重寫成foreach的形式就不對了

論壇徽章:
0
7 [報告]
發(fā)表于 2012-12-13 17:15 |只看該作者
請問splice(@a,--$i,1)這里的1是做什么用的。我記得splice(@a,--$i)這個應(yīng)該是$i是多少,就刪除@a中第幾個元素是嗎?那1是做什么用的。。我刪了1,好像1到最后的元素就都沒了回復(fù) 2# yinyuemi


   

論壇徽章:
6
卯兔
日期:2013-11-26 14:52:02丑牛
日期:2014-02-19 18:01:25卯兔
日期:2014-05-20 20:34:06白羊座
日期:2014-05-23 13:39:232015亞冠之大阪鋼巴
日期:2015-08-07 20:57:582015亞冠之大阪鋼巴
日期:2015-09-02 14:09:09
8 [報告]
發(fā)表于 2012-12-13 17:20 |只看該作者
就是一次取出1個元素回復(fù) 7# zlzty


   

論壇徽章:
6
卯兔
日期:2013-11-26 14:52:02丑牛
日期:2014-02-19 18:01:25卯兔
日期:2014-05-20 20:34:06白羊座
日期:2014-05-23 13:39:232015亞冠之大阪鋼巴
日期:2015-08-07 20:57:582015亞冠之大阪鋼巴
日期:2015-09-02 14:09:09
9 [報告]
發(fā)表于 2012-12-13 17:22 |只看該作者
yinyuemi 發(fā)表于 2012-12-12 00:56
回復(fù) 1# zlzty
  1. for(@a){
  2.        $i++;
  3.     if(/dd/../k/){
  4.         
  5.           #say "$i";
  6.         splice(@a,--$i,1);
  7.            push @b,$_;
  8.         say "@a","\n","@b";
  9.     }
  10. }
復(fù)制代碼
哪里不對了。。

論壇徽章:
2
射手座
日期:2014-10-10 15:59:4715-16賽季CBA聯(lián)賽之上海
日期:2016-03-03 10:27:14
10 [報告]
發(fā)表于 2012-12-14 00:59 |只看該作者
回復(fù) 6# 只是一個紅薯


    [code]The foreach loop iterates over a normal list value and sets the variable VAR to be each element of the list in turn. If the variable is preceded with the keyword my, then it is lexically scoped, and is therefore visible only within the loop. Otherwise, the variable is implicitly local to the loop and regains its former value upon exiting the loop. If the variable was previously declared with my, it uses that variable instead of the global one, but it's still localized to the loop. This implicit localization occurs only in a foreach loop.

The foreach keyword is actually a synonym for the for keyword, so you can use either. If VAR is omitted, $_ is set to each value.

If any element of LIST is an lvalue, you can modify it by modifying VAR inside the loop. Conversely, if any element of LIST is NOT an lvalue, any attempt to modify that element will fail. In other words, the foreach loop index variable is an implicit alias for each item in the list that you're looping over.

If any part of LIST is an array, foreach will get very confused if you add or remove elements within the loop body, for example with splice. So don't do that.

foreach probably won't do what you expect if VAR is a tied or other special variable. Don't do that either.[/code]
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP