Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I have a program (see below) that parses 2 CSV files and outputs text files containing the relevant data. However, when I run my program, I get repeating 'Use of uninitialized value' errors for $listenerName, $port, $channel and $name. Please help me with this people I am going crazy trying to figure out what's wrong!
#!/usr/bin/perl use Class::CSV; use strict; use warnings; # Enable the above statement 'use warnings' to allow error checking. my @AllFiles; my @SplitLine; my %QMS; my $QMName; my $Line; my $buffer = ""; $AllFiles[0] = 'C:\Strawberry\perl_tests\SKYCHAINALL.csv'; $AllFiles[1] = 'C:\Strawberry\perl_tests\CRISALL.csv'; for (my $i=0; $i < @AllFiles; $i++) { open (my $fh, '<', @AllFiles[$i]); if (@AllFiles[$i] ne "\n") { print "\n" . "Filename = '" . @AllFiles[$i] . "'\n"; }; while(read($fh, $buffer, 100)) { @SplitLine = split(',', $buffer); #print $buffer . "\n"; $QMName = $SplitLine[5]; my $currentQM; if (length[$QMName] != 0) { if ($::QMS{"key"} .= $QMName) { $currentQM = $::QMS{"key"} .= $QMName; } else { $currentQM = New Class::QueueManager; $currentQM::Name = $QMName; $::QMS{"key"} .= $currentQM; }; }; &QueueManager::AddListenerName($SplitLine[7]); &QueueManager::AddPort($SplitLine[8]); &QueueManager::AddChannel($SplitLine[9]); &QueueManager::AddQueue($SplitLine[10], $SplitLine[11], $S +plitLine[12], $SplitLine[22]); }; close $fh; }; package Queue; our $Name; our $Depth; our $Persistence; our $Description; sub New { $Name = $_[0]; $Depth = $_[1]; $Persistence = $_[2]; $Description = $_[3]; } # overrides function sub ToString() { return $Name . " " . $Depth . " " . $Persistence . " " . $Desc +ription; }; sub getMQSCcommand { my $cmd; $cmd = "DEFINE QUEUE(" . $Name . ") "; if (length[$Depth] != 0) { $cmd = $cmd . "MAXDEPTH(" . $Depth . ") "; }; if (length[$Persistence] != 0) { $cmd = $cmd . "DEFPSIST(" . $Persistence . ") "; }; if (length[$Description] != 0) { $cmd = $cmd . "DESCRIPTION(" . $Description . ") "; }; $cmd = $cmd . " REPLACE"; return $cmd; }; package QueueManager; our $Name; our %ListenerNames; our %Ports; our %Channels; our %Queues; sub AddListenerName { my $listenerName = $_[0]; if (length($listenerName) == 0) { return ""; } if (exists($ListenerNames{$listenerName})) { $QueueManager::ListenerNames{"key"} .= $listenerName; }; }; sub AddPort { my $port = $_[0]; if (length($port) == 0) { return ""; } if (exists($Ports{$port})) { $QueueManager::Ports{"key"} .= $port; }; }; sub AddChannel { my $channel = $_[0]; if (length($channel) == 0) { return ""; } if (exists($Channels{$channel})) { $QueueManager::Channels{"key"} .= $channel; }; }; sub AddQueue { my $currentQ; my $name = $_[0]; my $depth = $_[1]; my $persistence = $_[2]; my $description = $_[3]; if (exists($Queues{$name})) { $currentQ = New Class::Queue; $QueueManager::Queues{"key"} .= $currentQ; }; }; # overrides function ToString sub ToString() { my $value; $value = $Name; foreach $::listenerName (@{%ListenerNames}) { $value = $value . " " . $::listenerName; }; foreach $::port (@{%Ports}) { $value = $value . " " . $::port; }; foreach $::channel (@{%Channels}) { $value = $value . " " . $::channel; }; foreach $::queue (@{%Queues}) { $value = $value . " " . $::queue; }; }; sub WriteQMFile { open(my $fh, '>', 'C:\Strawberry\perl_tests\'' . $::currentQM +. '.txt'); foreach $::listenerName (@{%ListenerNames->$::currentQM}) { print $fh 'DEFINE LISTENER(' . $::listenerName . ')' . "\n +"; }; foreach $::port (@{%Ports->$::currentQM}) { print $fh ' TRPTYPE(TCP) CONTROL(QMGR) PORT(' . $::port . +') REPLACE' . "\n"; }; foreach $::channel (@{%Channels->$::currentQM}) { print $fh 'DEFINE CHANNEL(' . $::channel . ') TRPTYPE(TCP) + CHLTYPE(SVRCONN) REPLACE' . "\n"; }; foreach $::queue (@{%Queues->$::currentQM}) { print $fh &getMQSCcommand; }; close $fh; print "Done\n"; };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: WHY DOESN'T THIS WORK
by choroba (Cardinal) on Mar 07, 2016 at 12:03 UTC | |
by Anonymous Monk on Mar 07, 2016 at 12:22 UTC | |
by poj (Abbot) on Mar 07, 2016 at 12:28 UTC | |
by Anonymous Monk on Mar 07, 2016 at 12:42 UTC | |
by Corion (Patriarch) on Mar 07, 2016 at 12:49 UTC | |
by AnomalousMonk (Archbishop) on Mar 07, 2016 at 15:48 UTC | |
by poj (Abbot) on Mar 08, 2016 at 07:49 UTC | |
|
Re: WHY DOESN'T THIS WORK
by GotToBTru (Prior) on Mar 07, 2016 at 12:57 UTC |