I tried to adapt this code to obtain my desired output. I need help. My logic 
is 

While
if lines are not empty {do}
if lines are empty {do}

While
if lines are not empty {do}
else for empty lines{do}

I am new to programming. I have problem with logic and syntax. So please 
explain to me how I solve this problem.

Thanks



use strict; 
use warnings; 
my @ar = []; 
my $i = 0; 

while (<DATA>) { 
        chomp; next if !length(); 
        if (/^\s*&\s*$/) { 
                $i = 0; next; 
        } 
        push @{$ar[$i]}, @{$ar[$i++]} ? '&'.$_ : $_; 

} 

for my $ar (@ar) { 
        print @{$ar},"\n"; 


__DATA__name1
name2
name3
&
firstname1
firstname2
firstname3
&
adresse1
adresse2
adresse3

name4
name5
&
firstname4
firstname5
&
adresse4
adresse5

name6
name7
&
firstname6
firstname7
&
adresse6
adresse7


Desired output:
name1&firstname1&adresse1
name2&firstname2&adresse2 
name3&firstname3&adresse3

name4&firstname4&adresse4
name5&firstname5&adresse5

etc.



      __________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/

Reply via email to