I'm kinda new to programming and Perl... I would say I could do that in C like language, but I've got no idea how to do that in Perl.
To simplify things...
my $sql = [
{ ID => 1 },
{ ID => 2 },
{ ID => 2 },
{ ID => 2 },
{ ID => 3 }
];
my $number = 0;
foreach( @{ $sql } ) {
my @array = ();
if ( $number != $_->{ ID } ) {
push @array, $number;
if( $number ) {
push @array, '(' . $_->{ ID } . ')'; #how should I cycle that ?
}
}
$number = $_->{ ID };
print("@array");
}
I somehow need to get an output like this 1(2)(2)(2)3. I don't want to work with real code here, so I made a simple example how I use it now. I would be really grateful for help.
This code gives me 01 (2)2 (3) which is wrong. I've been thinking about it about for multiple hours so my results are getting worse and worse because I'm stuck and looping through the same mistakes.