thecryoflove has asked for the wisdom of the Perl Monks concerning the following question:

UPDATE!!!

I have posted it in my scratchpad if anybody wants to give me some hints and help. Haven't looked at your comments bv but will do and thanks for the input! Also... so everything is working the way I want it as far as output is concerned except for the .xspf that the program generates in the top directory is named "..xspf". If you want to look at my SP and help it will be under the sub Wanted. Thanks for the support monks!

Hello monks. This is my first time posting here... have used the site for knowledge extensively the last couple of days while attempting to write my first non-HelloWorld perl program; program that goes through my music directory and creates a XSPF playlist for every album and artist (I'm OCD when it comes to my music folder's organization).

I've got it 99.9% done and was curious if it would go against conduct if I posted my code (the final curly bracket sits exactly on line 150) and got feedback as to how to simplify things, as I know there are probably functions/shortcuts/special vars that could turn a couple of my blocks of code into a couple lines.

If this would be considered a sin I will not post it... however, if you guys wouldn't mind showing me some pointers I would love to put it up here and be told how to code correctly. It's commented on the non-self explanatory parts.

What do you think?

Replies are listed 'Best First'.
Re: Should I ask this question?
by ww (Archbishop) on Sep 30, 2009 at 22:27 UTC

    The convention here is to use the CB to ask questions such as the one you've just posted (ie, don't use a SOPW to ask whether to post)
    OR
    just post a SOPW, with the code (inside code tags) and narrative notes (in para tags) asking about specific areas that make you wonder if the code is well written. If there are no snippets/segments/constructs about which you have doubts, a generic "How can I improve this?" can do little worse than fail to draw comments (unless it's so badly written that you draw downvotes for your exposition/formatting).

Re: Should I ask this question?
by kennethk (Abbot) on Sep 30, 2009 at 22:27 UTC
    Assuming you don't mind leaving your code up for the world to see, please do post it in the public forum. This site is about helping people learn and appreciate what Perl (note the capitalization on the language, perl is the program) can do for them. Sometimes it seems like most traffic on SoPW is "Why won't my code work?" and the OPs just want quick, one-off solutions or free code-writing. If you demonstrate a desire to understand Perl and show effort (and having written your script already shows effort), I think every person on this site will happily help you improve your methods and style.

    As a side note, if your code is 150 lines, please wrap your code in <readmore> tags to avoid overwhelming the SoPW page.

Re: Should I ask this question?
by Marshall (Canon) on Oct 01, 2009 at 00:52 UTC
    The key thing that I've seen in the last year (I'm relatively new) is: whether or not you are working? Folks who are working and can present questions based upon the code that they have written so far get a LOT more help than those who aren't working.

    I was working on an LWP program a couple days ago and got stuck. I posted the code that I had so far on my scratchpad (after some hours of work) and asked for help in the Chatterbox. I got enough help to "unstick my brain" and was able to complete the project. I had posted code on my sctachpad before to help others, but that was the first time I asked others to help me. And it worked!

    james2vegas helped me out and provided very key info regarding a POST query question. I worked over the next 5 hours to finish the code. The whole project was more complex than my question, but the answer to my question allowed me to move forward and get the job done. PerlMonks is a good way to learn about new approaches and ideas that you need to spend more time thinking about.

    In general, the more clear your question, the better the quality of the response will be.

Re: Should I ask this question?
by bv (Friar) on Oct 01, 2009 at 14:55 UTC

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

    I hope that helped, and good luck!

    print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))
      Thanks for the input bv. Just the type of stuff I was looking for!
Re: Should I ask this question?
by bv (Friar) on Sep 30, 2009 at 22:06 UTC

    I haven't been here long enough to know if that would be frowned on, other than the fact that any honest attempt to learn will not be turned away. Why don't you post it on your scratchpad and those that wish can comment in this thread. If someone else says go for it, then post here as well.

    print pack("A25",pack("V*",map{1919242272+$_}(34481450,-49737472,6228,0,-285028276,6979,-1380265972)))
Re: Should I ask this question?
by dsheroh (Monsignor) on Oct 01, 2009 at 07:50 UTC
    You don't need to ask to ask. Just ask.
      Are you sure? :D
Re: Should I ask this question?
by Bloodnok (Vicar) on Oct 01, 2009 at 09:26 UTC
    Welcome, come inside ...

    If you don't ask, you'll never know if you should have asked :-D

    As others have suggested, don't be afraid to ask since the monks are only too glad to help if they can, even more so in the case of noobs and questioners that have obviously taken the time & trouble to attempt to solve the problem for themselves .

    They [the monks] only tend to take exception when they feel that the questioner is taking the mickey &/or being award winningly stupid/obtuse.

    A user level that continues to overstate my experience :-))
Re: Should I ask this question?
by ELISHEVA (Prior) on Oct 01, 2009 at 19:40 UTC

    Welcome to PerlMonks!

    Your indenting is a bit funky. I think you might find it easier to read if you used a more conventional style. There are two basic styles: cuddled and uncuddled, but both indent the code within the braces. This makes it easier to see which flow-of-control statements control which lines.

    Here is an example using cuddled curly braces:

    sub Wanted { my $orig_dir = cwd; if (-d $_) { chdir $_; # more code ... foreach my $file (@music_files) { chdir $_; $file =~ s/ /%20/g; #more code here } } }

    And here is the uncuddled version

    sub Wanted { my $orig_dir = cwd; if (-d $_) { chdir $_; # more code ... foreach my $file (@music_files) { chdir $_; $file =~ s/ /%20/g; #more code here } } }

    Your code sample actually uses a mix of both the cuddled and uncuddled style. It is generally a good idea to be consistant and follow one style or another. That way your readers don't have to do mental flip-flops while reading the code. They can also focus on your code rather than trying to remember that you prefer cuddled for foreach but uncuddled for if...else or vice versa.

    Best, beth