YouEnjoyMyself
IS-IT--Management
A couple of days ago I asked for some help on a scripting. I have now tried modifying that same script to work on another project I am doing, but I keep getting unintialized value error. I believe I have all the values defined. Could someone please explain to me as to why I would get this error. I have posted the script and DATA below. I have tried figuring this out for myself, but I am horrible at scripting. If any one could recomend a good book on scripting that would be helpful too.
#!perl
use strict;
use warnings;
#keywords to look for
my @keywds = ('Client',
);
#construct header from keywds
my $header = join('Client','Backup Time',' Media Date',
map {
(my $x = $_) =~ s/\b([a-z])/\U$1/g; #uc first char of words
$x =~ /^Created|Assigned/? 'Date ' . $x: $x;
} @keywds
);
#make hash with keywds as keys for quick lookup
my %kw;
@kw{@keywds} = ();
my %temp;
my @data;
while (<DATA>) {
chomp;
s/\s+$//;
s{s*\d+:\d+:\d+\s*}{}x; #Takes C time off (see Note)
my ($key, $value) = split (/\:/);
if (exists($kw{$key})) {
$temp{$key} = $value;
if ($key eq $keywds[0]) {
push(@data, { %temp });
%temp = ();
}
}
}
#write the file
my $outfile = "c:\\outfile.csv";
open(CSVFILE, ">$outfile") || die qq(Can't open "$outfile" for output.\n);
print CSVFILE "$header\n";
for my $row (@data) {
for (my $i=0; $i<@keywds; $i++) {
print CSVFILE $row->{$keywds[$i]}, $i<@keywds - 1? ",": "\n";
}
}
close(CSVFILE) || die qq(Can't close output file "$outfile".\n);
__DATA__
Client: albany8-mail2
Backup ID: albany8-mail2_1103590863
Policy: Mail_FileSystem_Albany
Policy Type: MS-Windows-NT (13)
Proxy Client: (none specified)
Creator: root
Name1: (none specified)
Sched Label: Incr
Schedule Type: INCR (1)
Retention Level: 2 weeks (1)
Backup Time: Mon Dec 20 2004 20:01:03 (1103590863)
Elapsed Time: 245 second(s)
Expiration Time: Mon Jan 03 2005 20:01:03 (1104800463)
Compressed: no
Encrypted: no
Kilobytes: 636117
Number of Files: 3650
Number of Copies: 1
Number of Fragments: 1
Histogram: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
DB Compressed: no
Files File Name: Mail_FileSystem_Albany_1103590863_INCR.f
Previous Backup Files File Name: (none specified)
SW Version: (none specified)
Options: 0x0
MPX: 0
TIR Info: 0
TIR Expiration: Wed Dec 31 1969 19:00:00 (0)
Keyword: (none specified)
Ext Security Info: no
File Restore Raw: no
Image Dump Level: 0
File System Only: no
Object Descriptor: (none specified)
Previous BI Time: Wed Dec 31 1969 19:00:00 (0)
BI Full Time: Wed Dec 31 1969 19:00:00 (0)
Request Pid: 0
Backup Status: 0
Stream Number: 0
Backup Copy: Standard (0)
Files File size: 376031
PFI type: 0
IMAGE_ATTRIBUTE: 0
Primary Copy: 1
Image Type: 0 (Regular)
Job ID: 166680
Num Resumes: 0
Resume Expiration: Wed Dec 31 1969 19:00:00 (0)
Copy number: 1
Fragment: 1
Kilobytes: 636117
Remainder: 0
Media Type: Media Manager (2)
Density: hcart (6)
File Num: 1
ID: 002285
Host: verbackup
Block Size: 65536
Offset: 2
Media Date: Mon Dec 20 2004 20:01:03 (1103590863)
Dev Written On: 2
Flags: 0x0
Media Descriptor: ?
Expiration Time: Mon Jan 03 2005 20:01:03 (1104800463)
MPX: 0
retention_lvl: 2 weeks (1)
checkpoint: 0
resume num: 0
#!perl
use strict;
use warnings;
#keywords to look for
my @keywds = ('Client',
);
#construct header from keywds
my $header = join('Client','Backup Time',' Media Date',
map {
(my $x = $_) =~ s/\b([a-z])/\U$1/g; #uc first char of words
$x =~ /^Created|Assigned/? 'Date ' . $x: $x;
} @keywds
);
#make hash with keywds as keys for quick lookup
my %kw;
@kw{@keywds} = ();
my %temp;
my @data;
while (<DATA>) {
chomp;
s/\s+$//;
s{s*\d+:\d+:\d+\s*}{}x; #Takes C time off (see Note)
my ($key, $value) = split (/\:/);
if (exists($kw{$key})) {
$temp{$key} = $value;
if ($key eq $keywds[0]) {
push(@data, { %temp });
%temp = ();
}
}
}
#write the file
my $outfile = "c:\\outfile.csv";
open(CSVFILE, ">$outfile") || die qq(Can't open "$outfile" for output.\n);
print CSVFILE "$header\n";
for my $row (@data) {
for (my $i=0; $i<@keywds; $i++) {
print CSVFILE $row->{$keywds[$i]}, $i<@keywds - 1? ",": "\n";
}
}
close(CSVFILE) || die qq(Can't close output file "$outfile".\n);
__DATA__
Client: albany8-mail2
Backup ID: albany8-mail2_1103590863
Policy: Mail_FileSystem_Albany
Policy Type: MS-Windows-NT (13)
Proxy Client: (none specified)
Creator: root
Name1: (none specified)
Sched Label: Incr
Schedule Type: INCR (1)
Retention Level: 2 weeks (1)
Backup Time: Mon Dec 20 2004 20:01:03 (1103590863)
Elapsed Time: 245 second(s)
Expiration Time: Mon Jan 03 2005 20:01:03 (1104800463)
Compressed: no
Encrypted: no
Kilobytes: 636117
Number of Files: 3650
Number of Copies: 1
Number of Fragments: 1
Histogram: -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
DB Compressed: no
Files File Name: Mail_FileSystem_Albany_1103590863_INCR.f
Previous Backup Files File Name: (none specified)
SW Version: (none specified)
Options: 0x0
MPX: 0
TIR Info: 0
TIR Expiration: Wed Dec 31 1969 19:00:00 (0)
Keyword: (none specified)
Ext Security Info: no
File Restore Raw: no
Image Dump Level: 0
File System Only: no
Object Descriptor: (none specified)
Previous BI Time: Wed Dec 31 1969 19:00:00 (0)
BI Full Time: Wed Dec 31 1969 19:00:00 (0)
Request Pid: 0
Backup Status: 0
Stream Number: 0
Backup Copy: Standard (0)
Files File size: 376031
PFI type: 0
IMAGE_ATTRIBUTE: 0
Primary Copy: 1
Image Type: 0 (Regular)
Job ID: 166680
Num Resumes: 0
Resume Expiration: Wed Dec 31 1969 19:00:00 (0)
Copy number: 1
Fragment: 1
Kilobytes: 636117
Remainder: 0
Media Type: Media Manager (2)
Density: hcart (6)
File Num: 1
ID: 002285
Host: verbackup
Block Size: 65536
Offset: 2
Media Date: Mon Dec 20 2004 20:01:03 (1103590863)
Dev Written On: 2
Flags: 0x0
Media Descriptor: ?
Expiration Time: Mon Jan 03 2005 20:01:03 (1104800463)
MPX: 0
retention_lvl: 2 weeks (1)
checkpoint: 0
resume num: 0