Repeatedly match perl expression for specific / multiple times?

For this example line: <a><b><c><d><e><f><g> I would like to write an expression that will repeat the first 5 tags <(?)> And put them in $ 1, $ 2 , $ 3, $ 4 and $ 5.

A naive implementation would, of course, be: /<(?)><(?)><(?)><(?)><(?)>/
But that day I remember doing something like /(<(?)>:5)/ .

I find it hard to find this syntax.
Can anyone help?

Thanks.

+4
source share
1 answer
 perl -wE '$_="<a><b><c><d><e><f><g>"; say /<(.)>/g;' 

Will give all the matches. This is just a matter of getting the snippet:

 my @tokens = (/<(.)>/g)[0 .. 4]; 
+13
source

All Articles