You can achieve it by using the following code.For your requirement,I have stored the column names into array in hard coded manner.If you want to be dynamic, then you can store the column headings into hash.At the time, you can't expect the hash keys to be in order.First, you check this.If you face any problem, I will explain you with storing and retrieving the details from hash.

use strict; use warnings; my %hash; #declaring hash for storing the data open FH, "<input.txt" or die "can't open file:$!"; #opening the file i +n read mode my $i=0; #declaring iterator for storing different records in a file my @arr; #temporary array to store splitted details while(<FH>) { #reading data from file if(/^Artist:\s*(.*)$/) { #checking whether its first artist detail +s $i++; #incrementing the iterator for storing the details push @{$hash{$i}}, $1; #pushing the artist name to array while(<FH>) { #continue reading the file to get artist det +ails if(/^Artist:\s*(.*)$/) { #checking whether particular +artist details completed $i++; #incrementing the iterator for storing the d +etails push @{$hash{$i}}, $1; #pushing the artist nam +e to array last; #break the loop } else { @arr=split(':'); #splitting the field name and val +ue $arr[1]=~s/\s//g; #removing the unwanted space +s in file push @{$hash{$i}}, $arr[1]; #storing the furth +er informations into array } } } else { @arr=split(':'); #splitting the field name and value $arr[1]=~s/\s//g; #removing the unwanted spaces in file push @{$hash{$i}}, $arr[1]; #storing the further informati +ons into array } } my @fields=('Artist','Title','Album','Year','Genre'); #storing the fie +ld names in the file in order print "$_\t" for @fields; #printing the column headings print "\n-------\t-----\t------\t----\t-----\n"; #printing the ----- a +fter each column for my $key (sort keys%hash) { #getting the records in order from hash my $j=0; print $hash{$key}->[$j++]." " while($j<5); #getting all data of arti +st from hash and printing it print "\n"; #printing newline for differentiating the records }

In reply to Re: converting rows into column by nvivek
in thread converting rows into column by changma_ha

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.