Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
my $input_file = undef;
my @files = undef;

These are examples of types of statements that I see in several places in your code and that I consider programming tics that should be addressed with psychotherapy or powerful behavior modifying drugs.

The first,
    my $input_file = undef;
defines a lexical scalar variable that is default-initialized to undef — and then explicitly initializes the variable to undef. I see no point to the explicit initialization, but it can do no harm.

The second type of statement,
    my @files = undef;
can potentially do some damage because it doesn't do what I think you think it does. A lexical array is defined in an empty state by default, but this statement explicitly initializes the array with a single undef element.

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @files = undef; ;; dd \@files; ;; print 'number of elements in array: ', scalar(@files); " [undef] number of elements in array: 1
Is this what you expect and want? I thought not. In the example code you posted, this semantic error, by good fortune, does no harm (that I can see), but it is the kind of error that can bite you in the ass at any time given the opportunity.

Update: If you want to go the explicit useless initialization route for list-type variables, the correct syntax is
    my @array = ();
    my %hash  = ();
but again, these statements | initializations would IMHO just be more evidence of a need for medical intervention. The only circumstance I can see in which such statements | initializations can barely be justified is when an initial empty state is vital to the correct operation of a succeeding algorithm and you don't want to bother emphasizing this fact by going to all the trouble of typing a comment.

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

In reply to Re: What can I do to improve my code - I'm a beginner by AnomalousMonk
in thread What can I do to improve my code - I'm a beginner by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    [marto]: this cpan day there should be a call to remove old crud :P
    [marto]: as well as encourage active development

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (6)
    As of 2018-07-17 08:25 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (359 votes). Check out past polls.