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"; };

In reply to WHY DOESN'T THIS WORK by Anonymous Monk

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.