Other monks have posted solutions based on Text::CSV to which I think you should pay close attention. This post is not about the OPed code per se, but about a general approach to debugging code.

Are you using warnings and strict with your code? I suspect not. If not, do so (see example code below), then fix the problems these thinking-aids reveal. These modules are useful for all Perl programmers, but especially for novice Perlers.

After being sure warnings and strict are enabled, the next thing to do is to be sure you are getting the data you think you're getting.

The statement
    ($samaccountnameAD,$givennameAD,...,$managerAD)=split(/,$/);
splits a string on a comma that is at the end of the string. The  $ in the  /,$/ regex is an end-of-string anchor; see perlre, perlretut, and perlrequick. You cannot get more than two fields from this split, but you're trying to get quite a few fields.

c:\@Work\Perl\monks>perl -wMstrict -le "use warnings; use strict; ;; use Data::Dumper; ;; $_ = 'vv,WWWW,xxx,YY,zzzz,'; ;; my ($v, $w, $x, $y, $z) = split(/,$/); print Dumper($v, $w, $x, $y, $z); ;; print qq{'$v' '$w' '$x' '$y' '$z'}; " $VAR1 = 'vv,WWWW,xxx,YY,zzzz'; $VAR2 = ''; $VAR3 = undef; $VAR4 = undef; $VAR5 = undef; Use of uninitialized value in concatenation (.) or string at -e line 1 +. Use of uninitialized value in concatenation (.) or string at -e line 1 +. Use of uninitialized value in concatenation (.) or string at -e line 1 +. 'vv,WWWW,xxx,YY,zzzz' '' '' '' ''
You see in this example the exact output of the split operation; probably not what you wanted and expected. Try this example again with a string that does not end in a comma character; there is a tiny but significant difference. Try it with an empty string as input.

The example above uses Data::Dumper. This utility for visualizing data can be a sanity-saver. It is a core module (i.e., has been made a part of the standard Perl distribution; see corelist for getting info on core modules). I prefer Data::Dump, but it is not core.

This post addresses just one, small aspect of debugging; there are many more. Good luck.


Give a man a fish:  <%-{-{-{-<


In reply to Re: Comparing two files line by line and exporting the differences from the first file by AnomalousMonk
in thread Comparing two files line by line and exporting the differences from the first file by jzelkowsz

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.