| Server IP : 85.214.239.14 / Your IP : 216.73.216.27 Web Server : Apache/2.4.65 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Mon Sep 30 15:36:27 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/root/usr/share/doc/libparse-recdescent-perl/examples/ |
Upload File : |
#!/usr/bin/perl -ws
use Parse::RecDescent;
undef $::RD_WARN;
my $parse = Parse::RecDescent->new(<<'EOGRAMMAR');
{use Tie::Hash; }
line: <rulevar: local %max; tie %max, Tie::StdHash'; %max = (count=>0) >
line: seplist[sep=>',']
| seplist[sep=>':']
| seplist[sep=>" "]
| { $max{item} }
seplist: <skip:"">
<leftop: /[^$arg{sep}]*/ "$arg{sep}" /[^$arg{sep}]*/>
{ $max{count} = @{$max{item} = $item[2]}
if @{$item[2]} > $max{count};
}
<reject>
EOGRAMMAR
while (<DATA>)
{
chomp;
my $res = $parse->line($_);
print '[', join('][', @$res), "]\n";
}
__DATA__
c,o,m,m,a,s,e,p,a,r,a,t,e,d
c:o:l:o:n:s:e:p:a:r:a:t:e:d
s p a c e s e p a r a t e d
m u:l t i,s:ep ar:a,ted
m u:l,t i,s:ep ar:a,ted
m:u:l,t i,s:ep ar:a,ted