You can't. You have no code. You have no data. You aren't using strictures and you aren't using an appropriate module from CPAN.
Update: OP has updated splitting results several times since the node was first posted.
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
| [reply] |
You are unlikely to get a non-disparaging response, because your question is meaningless.
It would be helpful to get what you want to transform, what you expect the result to be and what you have tried.
"Imaginary friends are a sign of a mental disorder if they cause distress, including antisocial behavior. Religion frequently meets that description"
| [reply] |
You didn't specify what the content was (it should be a table, right?) and how to get to the expected result from it.
So, I imagined it.
#!/usr/bin/perl
use strict;
use warnings;
use HTML::TableExtract;
my $html = "<table><tr><th>info\n<tr><td>john\n<tr><t"
. "d>100 - 2000\n<tr><td>kent</table>";
my $table = 'HTML::TableExtract'->new();
$table->parse($html);
print "Content-type: text/text\n\n";
my @rows = $table->rows;
chomp @$_ for @rows;
my $output = join ' ', 'data:' . $rows[0][0],
"$rows[1][0]:" . do { $rows[2][0] =~ /- (...)/;
+ $1 },
"$rows[3][0]:" . substr $rows[2][0], 6, 4;
print $output;
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [d/l] [select] |
Another guess, less elaborate than (but along similar lines as)
choroba's here:
Win8 Strawberry 5.8.9.5 (32) Wed 12/16/2020 18:30:38
C:\@Work\Perl\monks
>perl -Mstrict -Mwarnings
my $s = <<EOT;
info
john
100 - 2000
kent
EOT
my @field =
grep { not m{ \A - \z }xms }
$s =~ m{ \S+ }xmsg
;
$field[2] += 100;
my $t = "data:$field[0] $field[1]:$field[2] $field[4]:$field[3]";
die "bad response '$t'" unless $t eq 'data:info john:200 kent:2000';
print "'$t' response ok \n";
^Z
'data:info john:200 kent:2000' response ok
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] [select] |
The html you finally posted shows that you only have one row. It contains a lot of white space. You have parsed and dereferenced it correctly. All that is left is to clean up the white space and rearrange it.
use strict;
use warnings;
use Data::Dumper;
my $foo = 0;
my $row = [
'info',
'
john
',
'
100 - 200
',
'
kent
',
];
print Dumper($row);
foreach (@$row){
s/\A\s+//;
s/\s+\z//;
}
print Dumper($row);
my ($dat1, $dat2) = ${$row}[2] =~ m/(\d+)\D+(\d+)/;
print "data:$row->[0] $row->[1]:$dat1 $row->[3]:$dat2", "\n";
| [reply] [d/l] |
#!/usr/bin/env perl
use strict;
use warnings;
use Mojo::DOM;
use Mojo::Util qw(trim);
my $content = <<'HERE';
<td class="">info</td>
<td>
john
</td>
<td>
100 - 200
</td>
<td>
kent
</td>
HERE
my $dom = Mojo::DOM->new($content);
my ($data, $left_name, $range, $right_name) = map {trim($_->content)}
+@{$dom->find('td')};
my ($left_val, $right_val) = split /\s*-\s*/, $range;
print "data:$data $left_name:$left_val $right_name:$right_val\n";
That produces:
data:info john:100 kent:200
| [reply] [d/l] [select] |