I use Perl 5 every single day. I have no interest in what they did to it in Perl 6. I guess I should look at 7, but I don't have high hopes.
Here's something I was just running a few minutes before I found this post:
Mac-mini:~ bruce$ curl http://hoult.org/bruce.ip 2>/dev/null | grep '\.' | perl -ne 'sub p {print "$s $n\n" if $n!=0} chomp; if($_ eq $s){++$n}else{p;$s=$_;$n=1}; END {p}'
103.152.127.142 125
103.152.127.143 480
103.152.127.142 283
103.152.127.143 3
103.152.127.142 1
103.152.127.143 37
103.152.126.179 537
103.152.126.178 16
103.152.127.164 600
103.152.126.144 62
103.152.126.145 180
103.152.126.144 262
103.152.127.166 247
103.152.126.147 11
103.152.127.163 441
103.152.127.162 74
103.152.127.163 64
206.83.116.202 1282
It goes on a bit longer than that. List of how in how many consecutive 15 minute periods I had the same IP number on Starlink, starting at the beginning of February.
If I want something perl'ish but with more conventional data structures and functions and so forth then I use Ruby.
I use Perl 5 every single day. I have no interest in what they did to it in Perl 6. I guess I should look at 7, but I don't have high hopes.
Here's something I was just running a few minutes before I found this post:
Mac-mini:~ bruce$ curl http://hoult.org/bruce.ip 2>/dev/null | grep '\.' | perl -ne 'sub p {print "$s $n\n" if $n!=0} chomp; if($_ eq $s){++$n}else{p;$s=$_;$n=1}; END {p}'
103.152.127.142 125
103.152.127.143 480
103.152.127.142 283
103.152.127.143 3
103.152.127.142 1
103.152.127.143 37
103.152.126.179 537
103.152.126.178 16
103.152.127.164 600
103.152.126.144 62
103.152.126.145 180
103.152.126.144 262
103.152.127.166 247
103.152.126.147 11
103.152.127.163 441
103.152.127.162 74
103.152.127.163 64
206.83.116.202 1282
It goes on a bit longer than that. List of how in how many consecutive 15 minute periods I had the same IP number on Starlink, starting at the beginning of February.
If I want something perl'ish but with more conventional data structures and functions and so forth then I use Ruby.
Interesting... ... never occurred to me using curl that way
.. with custom argument and custom sorting
put desired URL as argument
$s;$n=0; $\="\n"; sub p{ $fhs{$s}=$n if $n; $s=$_;$n=1;}
open PIPE, 'curl '.shift.'|' or die('PIPE Failed');
while(<PIPE>){ chomp; next unless m/\d+\.\d+\.\d+\.\d+/; ($_ eq $s) ? $n++:p;} p;
close PIPE; foreach (sort {$b cmp $a} keys %fhs) { push(@fhs,$fhs{$_}."\t".$_); }
foreach (sort {$a <=> $b} @fhs) { print; }
1 206.83.116.210
1 206.83.116.151
1 103.152.127.142
2 206.83.116.61
3 206.83.116.253
11 103.152.126.147
16 103.152.126.178
36 206.83.116.218
37 103.152.127.143
64 103.152.127.163
74 103.152.127.162
91 206.83.116.6
97 206.83.116.232
180 103.152.126.145
187 206.83.116.142
191 206.83.116.132
193 206.83.116.228
247 103.152.127.166
262 103.152.126.144
372 206.83.116.192
537 103.152.126.179
559 206.83.116.201
580 206.83.116.166
600 103.152.127.164
660 206.83.116.240
1784 206.83.116.202
PERL made me rethink the way I think..
btw: this wrap is still a plain oneliner
Paul
It's of course nice that you can do it all inside perl using a pipe and hash or array but keeping much of it in bash works well for me.
I can get effectively the same output as yours by just appending | sort -nk2 to my bash line. Or get actually the same as yours by changing the print in the perl and using | sort -nk1. Or | awk '{print $2"\t"$1}' | sort -nk1 (or perl instead of awk)
PERL just gives a banana for that kind of concern...
Both uses on a same oneliner can be piped or called either way..
This time with IPV4SORT custom sorting
$\="\n"; $s='';$n=0; sub p { $fhs{$s} = $n if $n; $s = $_; $n = 1; }
if ( scalar @ARGV ) { open PIPE, 'curl '.shift.'|' or die('PIPE Failed');
while(<PIPE>) { chomp; next unless m/\d+\.\d+\.\d+\.\d+/; ($_ eq $s)?$n++:p; } p; close PIPE;
} else {
while(<>) { chomp; next unless m/\d+\.\d+\.\d+\.\d+/; ($_ eq $s)?$n++:p; } p;
} foreach( map{ $fhs{$_}."\t".$_ } ipv4sort keys %fhs) { print; }
262 103.152.126.144
180 103.152.126.145
11 103.152.126.147
16 103.152.126.178
537 103.152.126.179
1 103.152.127.142
37 103.152.127.143
74 103.152.127.162
64 103.152.127.163
600 103.152.127.164
247 103.152.127.166
91 206.83.116.6
2 206.83.116.61
191 206.83.116.132
187 206.83.116.142
1 206.83.116.151
580 206.83.116.166
456 206.83.116.192
559 206.83.116.201
1784 206.83.116.202
1 206.83.116.210
36 206.83.116.218
193 206.83.116.228
97 206.83.116.232
660 206.83.116.240
3 206.83.116.253
PERL is AWK on heavy steroids..
and a very clever logic spectrum
you can even do ipv6 sorting instead by direct translation
Paul