Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

While my esteemed predecessors have done a good job of answering your direct questions, perhaps I can shed some light on a few stylistic questions you didn't ask, but may still find informative.

The line:

     open FILELIST, ">$filelist";

is problematic for a couple of reasons:

  • The open might fail (for example, if the file does not exist), so you need to check the return.
  • The two-argument open (with the append (>) symbol in the same string as the filename) is a potential security risk; see the old Two-arg open() considered dangerous discussion for more info.
  • The filehandle, FILELIST, is in the global symbol table. It's better form to create a lexical variable instead with my.

So, instead, I would write:

(UPDATED thanks to AnomylousMonk's good catch of a very carelessly chosen variable name)

open my $fh, '>', $filelist or die "Can't open $filelist: $!";

If it fails, the program will exit with an informative error code. You could instead wrap the open call in an if statement if you want to do something else.

Purely personal preference on this next one, but your entire foreach { ... } loop could be more concisely written:

    print $fh $_ for @files;

In reply to Re: syntax questions by rjt
in thread syntax questions by manishrathi

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
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (8)
    As of 2017-12-15 17:20 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (439 votes). Check out past polls.