2 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
use strict;
use warnings 'all';
use Data::Dumper;
# get ids
my $text =
'1 << 3'."\n".
'5 << 2'."\n".
'3 << 2'."\n".
'9 << 5'."\n".
'8 << 2'."\n".
'7 << 5'."\n".
'2 << 5'."\n".
'4 << 4';
# sort the ids
my @sorted = sort { $a->[1] <=> $b->[1] }
map { [split(/\s*<<\s*/, $_)] }
split("\n", $text);
# initialize the data hash, the hash for array checking
# and our actual position
my($hash, $last) = ({}, {});
my $actpos = 0;
# iterate through the sorted ids
foreach (@sorted)
{
# get cid and sharednetworkid
my($cid, $snid) = (@{$_});
# set start and content
my($start, $content, $end) = ($actpos, 'x'x($actpos+$cid));
# check whether we have an array
if (defined($last->{$snid}))
{ $start = $hash->{$last->{$snid}}->{END} }
# set end
$end = length($content) + $start;
# increment actual position
$actpos = $end + 1;
# create hash items
$hash->{$cid} = {START => $start,
CONTENT => $content,
END => $end};
# set last sharednetworkid
$last->{$snid} = $cid;
}
# output
$Data::Dumper::Sortkeys = 1;
print Dumper($hash);
2 Einträge, 1 Seite |