[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

Generating # of letters and making them "_"

I am trying to create a hangman program. So far I am trying to generate the number of underscores per word.

EX:

Cat

_ _ _

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?

Thanks,

Ryan
0
catonthecouchproductions
Asked:
catonthecouchproductions
  • 2
1 Solution
 
ozoCommented:
$_ = "Cat";
s/./_ /g;
print;
0
 
ozoCommented:
print "_ " x $lettercount;
0
 
catonthecouchproductionsAuthor Commented:
Thank you very much! That worked great. I was lost on how to do that.

Ryan
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now