in reply to Print max count of repeated consecutive numbers in an array
At the request of LanX
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11137256 use warnings; my @a = ( 2,2,2,3,3,4,4 ); my @best; $best[split] = (split)[0] for "@a" =~ /\b((\d+)(?: \2\b)*)/g; print "highest count is $#best for the number $best[-1]\n";
Outputs:
highest count is 3 for the number 2
|
|---|