in reply to Newbie cmd prompt problem

G'day nquiton,

Welcome to the monastery.

The answer to that will depend on how you're actually running your program. Possibilities include:

> perl prog_name > prog_name > perl -e "... perl code ..."

Also, does: (a) a new window appear, display some program output (possibly too quickly to read), then disappear; or (b) the window containing the initial command prompt disappear as soon as the program finishes?

A possible workaround would be to add this line to your code after processing is completed but before the program exits:

print "Hit enter when done: "; <>;

I don't have an MSWin machine to demonstrate that on, but it should look something like this:

$ perl -Mstrict -Mwarnings -E ' say "Your program runs and displays output here ..."; print "Hit enter when done: "; <>; ' Your program runs and displays output here ... Hit enter when done:

When I hit Enter, it returns to the command prompt; in your case, I presume the window would now disappear. The point is, it gives you a chance to actually read the output (or, indeed, do whatever you want with it: paste into a text file, take a screenshot, etc.).

There may be configuration options to alter the behaviour you're seeing: unfortunately, I can't help with that, but maybe another monk can.

-- Ken

Replies are listed 'Best First'.
Re^2: Newbie cmd prompt problem
by nquiton (Novice) on Sep 12, 2013 at 00:06 UTC
    Thanks for trying to help. I really appreciate it! re:(a) a new window appear, display some program output (possibly too quickly to read), then disappear; or (b) the window containing the initial command prompt disappear as soon as the program finishes? Both a and b. That is what is so frustrating. Well, that and my brain doesn't think in code. Yes, sometimes it disappears as soon as the program finishes and sometimes nothing happens when I hit enter, no error, it just has the path that I typed. Other times it runs and tells me what lines have errors. Re: your suggestion. I'm only 2 days into this class so I'm not sure what you mean. Here is my code and yes I know there are errors but won't be able to find them until I can run it. Can you add what you were telling me to do so I can try it? #Noel use strict; my $numone; my $numtwo; print "Please enter first number "; $numone=<STDIN>; print "Please enter second number "; $numtwo=<STDIN>; if ($numone < $numtwo); { print $numone; print $numtwo; } elsif { print $numtwo; print $numone; }
      "Thanks for trying to help. I really appreciate it! ..."

      While I'm happy to help, you need to help us as well. Posting all your text and code in a single block without any markup makes it very difficult to read. Put your text into paragraphs within <p>...</p> tags and your code within <code>...</code> tags. Details can be found in (or linked from) "Writeup Formatting Tips"; and "How do I change/delete my post?" explains how to fix what you've already done.

      After putting your code into some sort of readable layout, it would appear that what I'm talking about is pretty much the same thing that you're learning about:

      $ perl -Mstrict -Mwarnings -E ' my $numone; my $numtwo; print "Please enter first number "; $numone = <STDIN>; print "Please enter second number "; $numtwo = <STDIN>; #if ($numone < $numtwo); { <--- WRONG: no semicolon here if ($numone < $numtwo) { print $numone; print $numtwo; } # elsif { <--- WRONG: should be else else { print $numtwo; print $numone; } print "Hit enter when done: "; <>; ' Please enter first number 456 Please enter second number 123 123 456 Hit enter when done:

      So, in this context, "<>" is just a short-hand form of "<STDIN>": see "perlop: I/O Operators" for the full story. Also, I don't assign the user input to a variable because I don't want it and, in fact, don't really care what the user enters. This works the same:

      $ perl -Mstrict -Mwarnings -E ' ... previous code unchanged ... print "Hit enter when done: "; <STDIN>; ' Please enter first number 456 Please enter second number 123 123 456 Hit enter when done: I'm all done with this!

      -- Ken

      clearly I don't know how to insert my code. Yicks.
Re^2: Newbie cmd prompt problem
by nquiton (Novice) on Sep 12, 2013 at 00:29 UTC
    I think I know what the problem is. Apparently when naming your files you should not use spaces. When I changed the file name and removed my spaces it ran. Now I know for sure I'll never be a programmer because I have LOTS of errors:-)
      "I think I know what the problem is. Apparently when naming your files you should not use spaces. When I changed the file name and removed my spaces it ran."

      I generally refrain from using spaces in filenames because spaces are already used to separate the program name from switches, input files, and so on: basically it's a real nuisance that's easily avoided. However, it's not actually illegal and you will encounter third-party filenames that do include spaces: when you do, just quote them (i.e. "some filename with spaces"). I'd tend to write that filename as some_filename_without_spaces, which is just as easy to read but has none of the associated problems.

      "Now I know for sure I'll never be a programmer because I have LOTS of errors:-)"

      You'll learn a lot more from making mistakes and fixing them, than if you wrote all your code perfectly. What's more, sorry to be the one to tell you this but, don't worry at all about mistakes after only 2 days of coding: you'll still be making mistakes with 20 years experience under your belt.

      Also, don't worry too much about the number of errors: a simple mistake like a missing semicolon at the end of a statement, or using the wrong quote to terminate a string, can result in dozens of errors. When I frst ran the code you posted, I got:

      syntax error at -e line 9, near ");" Unmatched right curly bracket at -e line 12, at end of line syntax error at -e line 12, near "}" syntax error at -e line 16, near "}" Execution of -e aborted due to compilation errors.

      But, as you can see from my previous post, there were only two small errors that were easily fixed.

      -- Ken