Yet another solution (boy, you've got to be quick around here :)) #!/usr/bin/perl -w use strict; my $input ='junk_input.txt'; #returns filename from command line my $nodename; my $filename; my $pathname; my $backupdate; my $textline; my $nochar =""; my $charposition; my $nextrecord; chomp $input; #strip the carriage return my %len = ('NODE',0,'FILE',0,'PATH',0,'DATE',0); my @textline = (); open (DATAFILE, "$input")|| die ("Can not open $input:!\n"); # access + the file while (my $textline=<DATAFILE>) { chomp $textline; ################################ # If continuation of last line ################################ if (substr($textline,0,8) =~ /^\s/) { # Append contents to previous values $nodename .= substr($textline,0,8); $filename .= substr($textline,9,9) if (length($textline +) >= 10); $pathname .= substr($textline,19,10) if (length($textline +) >= 20); $backupdate .= ' ' . substr($textline,29) if (length($textline +) >= 30); } else { ################################ # If new line ################################ push @textline, "$nodename|$filename|$pathname|$backupdate"; + # Save previous line # Save new values $nodename = substr($textline,0,8); $filename = substr($textline,9,9) if (length($textline +) >= 10); $pathname = substr($textline,19,10) if (length($textline +) >= 20); $backupdate = substr($textline,29) if (length($textline +) >= 30); } # Remove unwanted spaces at beginning or end, depending on column $nodename =~ s/\s{1,}$//g; $filename =~ s/\s{1,}$//g; $pathname =~ s/\s{1,}$//g; $backupdate =~ s/^\s{1,}//g; # Save longest column length (used later for formatting output) $len{NODE} = length($nodename) if (length($nodename) > $len{ +NODE}); $len{FILE} = length($filename) if (length($filename) > $len{ +FILE}); $len{PATH} = length($pathname) if (length($pathname) > $len{ +PATH}); $len{DATE} = length($backupdate) if (length($backupdate) > $len{ +DATE}); } push @textline, "$nodename|$filename|$pathname|$backupdate"; + # Save last line of input file close (DATAFILE); for my $textline (@textline) { ($nodename,$filename,$pathname,$backupdate) = split(/\|/,$textline) +; # Separate columns # Format column widths $nodename .= ' ' x ($len{NODE} - length($nodename)); $filename .= ' ' x ($len{FILE} - length($filename)); $pathname .= ' ' x ($len{PATH} - length($pathname)); $backupdate .= ' ' x ($len{DATE} - length($backupdate)); print "$nodename $filename $pathname $backupdate\n"; }

In reply to Re: MultiLine Tables into Variables by perlofwisdom
in thread MultiLine Tables into Variables by Knoperl

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.