On 12/20/07, banker123 <[EMAIL PROTECTED]> wrote:
>
> I have a text file with a ragged hierarchy as shown below, I would
> like to structure the data in a different format (also shown below)
> please help. Also the data below is just an example the actual data
> file is much larger and the hierarchy has 10 levels the lowest level
> "Employee" could be stored anywhere wtihin the 10 levels depeding
> upon
> the business units structure. I have not used Perl in about 6 months
> but
> if memory serves me correctly Perl is the perfect tool for the job.
>
> Original
> Company Business Unit1 Employee1
> Company Business Unit1 Business Unit2 Employee2
>
>
> New
> Employee1 Company Business Unit1
> Employee2 Company Business Unit1 Business Unit2
>
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
if you only need re-organize company and employee
use strict;
use warnings;
while(<DATA>){
chomp;
my @line = split/\s{5}/;
print join (" ", @line[-1, 0, 1.. $#line -1]), "\n";
}
__DATA__
Company Business Unit1 Employee1
Company Business Unit1 Business Unit2 Employee2
Company Business Unit1 Business Unit2 Business
Unit3 Employee3