数组到哈希 perl
这是同一个线程,但名称不同(Working with Spreadsheet::ParseExcel)。因为他们中的一些人提出了标题,而问题没有意义。抱歉没让事情变得容易。
我的问题是:像这样的数组
TY45745a A,B
TY45745a C,D
TY45745a E,F
TY5475a G,H
TY5475a I,J
TY5475a K,L
应该变成这样的散列。
TY45745a =>(A,B,C,D,E,F) TY5475a =>(G,H,I,J,K,L)
下一部分是重命名文件,如果文件名末尾有 [AE] 那么应该重命名至 TY45745a[1..6],并且如果有 [GL] TY5475a[1..6]。
%哈希=@array。
但这会导致
TY45745a => A,B
TY45745a => C,D
TY45745a => E,F
TY5475a => G,H
TY5475a => I,J
TY5475a => K,L
我应该如何对它们进行分组?感谢您的时间和建议
编辑:抱歉,这行不通,因为当通过 for 循环时,部分的输出将如下所示:
TY45745a
A,B
TY45745a
C,D
TY45745a
E,F
TY5475a
G,H
TY5475a
I,J
TY5475a
K,L
It's the same thread with a different name as this ( Working with Spreadsheet::ParseExcel ). Since some of them suggested the title and the question didn't make sense. Sorry for not making it easy.
my question is : an array like this
TY45745a A,B
TY45745a C,D
TY45745a E,F
TY5475a G,H
TY5475a I,J
TY5475a K,L
should be made to a hash like this .
TY45745a =>(A,B,C,D,E,F)
TY5475a =>(G,H,I,J,K,L)
And the next part of this would be to rename the file , And if the file names has [A-E] at the end of the file then it should be renamed to TY45745a[1..6], and if it has [G-L] TY5475a[1..6].
%hash = @array .
but that would result in
TY45745a => A,B
TY45745a => C,D
TY45745a => E,F
TY5475a => G,H
TY5475a => I,J
TY5475a => K,L
How should I group them ? Thanks for your time and suggestions
EDIT: Sorry, Bu that wouldn't work becos wen passed through the for loop the outpur of part would be like this:
TY45745a
A,B
TY45745a
C,D
TY45745a
E,F
TY5475a
G,H
TY5475a
I,J
TY5475a
K,L
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用问题中更新的数组,此方法有效:
我不确定您替换 [AF] 和 [GL] 的意思,因为这会产生您所描述的所需输出,而无需任何替换。
With the updated array in the question this works:
I'm not sure what you mean about replacing [A-F] and [G-L] though, since this produces what you've described as your desired output without any replacements.
给出:
gives: