Ok, let's see. Kudos for using strict and warnings!

# Your code: print "\nWorking on ".$dir."\n\n";

When printing, concatenating strings with . is probably not what you want. It's more expensive than simply printing a list or interpolating values into a string. The following two statements are equivalent, but better:

# print a list print "\nWorking on ", $dir, "\n\n"; # Interpolate print "\nWorking on $dir\n\n";

When you are printing blocks of text with lots of newlines, use the q and qq operators, so that this:

print "Select an option: \n\n 1\) Create new XSPFs\n2\) Delete all XSPFs in dir and create new ones\n";

becomes this (notice that parentheses do not need to be escaped in strings):

print q{Select an option: 1) Create new XSPFs 2) Delete all XSPFs in dir and create new ones };

Here's somewhere you can really improve your code:

open(XSPF, ">$playlist");

There are a few things you should know about using open. First, whenever possible, use the 3-argument version. This protects you against subtle security bugs if your code ever gets used suid, and probably some other bugs. Second, filehandles are variables, too! You should use my to make them lexical. Last, and to some people most importantly, you should always check the success of system calls like open. This is the "or die" part of "use strict and warnings or die." Put it all together with the $! variable to tel you why you failed and you get something like this:

open my $XSPF, '>', $playlist or die "Can't open $playlist: $!";

Along with the q and qq operators, you should understand the difference between single and double quotes and how to use them. This line:

print XSPF "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

could be written with single quotes as such:

print XSPF '<?xml version="1.0" encoding="UTF-8"?>',"\n";

but you could really just use the q operator for that and the next 2 lines put together.

Finally, a few nitpicky things that aren't so important. I prefer to use parentheses only when necessary, or when it's not clear what arguments go with what functions. So I never use parens with close, rarely with open, and also rarely with compound conditionals. I also prefer to use and, or and not to &&, ||, and !, but there are differences in precedence, so be careful. Lastly, I prefer to call subroutines with func() rather than &func, unless I specifically need to pass the current @_ to the sub. See perlsub for more on that.

I hope that helped, and good luck!

print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))

In reply to Re: Should I ask this question? by bv
in thread Should I ask this question? by thecryoflove

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.