in reply to MultiLine Tables into Variables
And output is:#!/usr/bin/perl use warnings; use strict; package main; my $node_name = ""; my $host_name = ""; my $path_name = ""; my $backup_date = ""; while(<DATA>) { my ($node, $host, $path, $backup) = unpack('A9A10A10A10',$_); if ( $node =~ /^\w+/ ) { if ( $host_name =~ /\w+/ ) { printf "%-9s %-25s %-28s %-17s\n", $node_name, $host_name, $path_name, $backup_date; $node_name = ""; $host_name = ""; $path_name = ""; $backup_date = ""; } $node_name = $node; $host_name = $host; $path_name = $path; $backup_date = $backup; $backup_date =~ s/^\s+//; } else { $host_name .= $host; $path_name .= $path; $backup_date .= $backup; } } printf "%-9s %-25s %-28s %-17s\n", $node_name, $host_name, $path_name, $backup_date; __DATA__ BD3101 bananaswi \breakfa 2007-03-06 ithapple st\fruit 14:02:31.000000 s.gif s\tree\ TP4223 chocolate \sweet\d 2006-02-28 caramelfu esserts\ 21:16:41.000000 dge.gif hersheys\ EO2123 tofuwith \organic\ 2007-07-16 peas.gif vegetable 13:55:06.000000 s\legumes\
C:\Code>perl unpack.pl BD3101 bananaswiithapples.gif \breakfast\fruits\tree\ 2007- +14:02:31.0 TP4223 chocolatecaramelfudge.gif \sweet\desserts\hersheys\ 2006- +21:16:41.0 EO2123 tofuwithpeas.gif \organic\vegetables\legumes\ 2007- +13:55:06.0
|
|---|