| punter | Nice perl problem: How (in 1 line) would you remove every second element from an array? hm? |
| kestas | if I have some text, say 'ABC ABC DEF' , is it possible to build a regex that will take only the last ABC DEF. Like /ABC.*?DEF/ but going from the right instead of the left ? |
| punter | kestas: yes kestas: i think, do sthng like this: |
| f00li5h | eval: @foo = 1..10; [ map { $i ++ % 2 } @foo ] |
| buubot | f00li5h: [0,1,0,1,0,1,0,1,0,1] |
| f00li5h | eval: @foo = 1..10; [ grep { $i ++ % 2 } @foo ] |
| buubot | f00li5h: [2,4,6,8,10] |
| punter | kestas: if you add ".*" at the beginning of your regexp... kestas: so /.*ABC.*?DEF/ ... wouldn't that do it? (just a thought) |
| kestas | punter: ah but the pattern could be like ABC ABC DEF ABC ABC DEF |
| f00li5h | kestas: what do you actually want? |
| punter | kestas: see my answer kestas: i think it's correct |
| kestas | punter: it's also across multiple lines hmm |
| unop | eval: $_="ABC ABC DEF ABC ABC DEF"; [/.*(ABC DEF)$/] |
| buubot | unop: ['ABC DEF'] |
| punter | kestas: then add the 's' modifier at the end kestas: /.*blabla/s |
| kestas | hmm interesting, thanks |
| punter | Any takers for my interesting problem? How would you (in one line) take only the odd elements (or the even elements) from an array |
| f00li5h | punter: did that already @foo = 1..10; [ grep { $i ++ % 2 } @foo ] |
| punter | f00li5h: a... i'm sorry, i'll check |
| unop | eval: [grep $_%2, 0..10] |
| buubot | unop: [1,3,5,7,9] |
| punter | very nice, thanks |
| f00li5h | unop: every second element, not every even element |
| punter | but you would need to write "my $i" on a separate line to conform with strict, right? that's okay |
| f00li5h | no heck no |
| unop | f00li5h, errm, i was reading his last question -- take odd elements from an array |
| punter | no? |
| pasteling | "zen" at 155.47.156.126 pasted "Not reading in files well." (39 lines, 936B) at http://sial.org/pbot/23164 |
| f00li5h | punter: if you my $i, it will not be global, and so it will fail punter: (unless you do it outside the grep) |