Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Here is your program wrapped in code tags, and formatted so it's a little easier to read. I've made comments explaining what's going wrong/on within the code.

print "What is your name?\n"; $input=<STDIN>; $name=inputcutter($input); # Be careful with that slash. You just escaped your # double-quote. print "What is your age?n\"; $input=<STDIN>; $age=inputcutter($input); # You don't have an array called @age in your code. # Try $age instead. print "Your are $name and your age is @age years old.\n"; sub inputcutter { # Here, you're neglecting to fetch the data you just # passed to here (in @_, FYI). If you do # $input = shift;, you'll grab the first element of # @_, which is what you need. # On this line, $s holds whether or not the chomp was # successful, not the chomped version of $input. You # can just chomp $input; and forget about $s. $s=chomp $input; return ($s); }

It is highly recommended you use strict; and run with Warnings and Taint. I'm not going to rehash the reasons why, when there is already a node on PM such as Use strict warnings and diagnostics or die just waiting to be read.

Also, remember to include your shebang line at the top of your program (usually #!perl or #!/usr/bin/perl), or else your program won't run. And if you're on a Windows box, you have to execute the program like this: perl programname.pl or  perl -T programname.pl

If the program is still giving you problems, please reply back to this thread for additional help. But I implore you to be more descriptive of the problem as it will increase the chances of us being able to help you out.

Update: As blakem points out, Anonymous Monk probably did have the <STDIN> after all. Node edited to reflect changes.


Sarah
If Bill Gates can name a company after his "bedroom" problems, I can have a stupid sig that points it out.

In reply to Re: My program it doesn't work could you tell me my mistakes? by monkeygirl
in thread My program it doesn't work could you tell me my mistakes? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found