Generating # of letters and making them "_"

Posted on 2007-10-01
Last Modified: 2011-09-20
I am trying to create a hangman program. So far I am trying to generate the number of underscores per word.



_ _ _

We have a variable that stores the number of letters in the word and I am trying to generate X amount of _ for each letter in the word.

What would I go about doing that with?

I tried a for loop but that wasn't what I wanted

I have

$lettercount which equals to the number of letters in a word (int)

Just stuck on how I am to make that number of letters in to _

Any suggestions?


    LVL 84

    Accepted Solution

    $_ = "Cat";
    s/./_ /g;
    LVL 84

    Expert Comment

    print "_ " x $lettercount;
    LVL 1

    Author Comment

    Thank you very much! That worked great. I was lost on how to do that.


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now