in reply to converting generation format to parent child format (recursive)
I see no permutation or recursion in your example; In what way would this code be insufficient? :
Output:#!/usr/bin/perl use strict; use warnings; while (<DATA>) { chomp; my @fields = split /\s+/; # Change to /\t/ for production? # You can walk the array like this: print "\t$fields[0]\n"; for my $i ( 1 .. $#fields ) { print "$fields[$i-1]\t$fields[$i]\n"; } # Or like this: # my $last_field = ''; # for my $field (@fields) { # print "$last_field\t$field\n"; # $last_field = $field; # } print "\n"; } __DATA__ A B C D E Foo Bar Baz Senior Junior TheThird
A A B B C C D D E Foo Foo Bar Bar Baz Senior Senior Junior Junior TheThird
|
|---|