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

Heres my source:
#!/usr/bin/perl # The distance formula!!! print "What is the first point? ("; chomp ($x1 = <STDIN>); print ","; chomp ($y1 = <STDIN>); print ")\n"; print "What is the second point? ("; chomp ($x2 = <STDIN>); print "$x2, "; chomp ($y2 = <STDIN>); print "$y2)";
when i do it it prints "What is the first point? ("
i enter my x-cordinate so it looks like:
"What is the first point? (5
,"
what is making this new line? i want it to go like this


"What is the first point? ("
"What is the first point? (5," I typed 5 then enter
"What is the first point? (5,9)" I typed 9 then enter

how do i do it?

im guessing the <STDIN> is making the newline, or print, or im just new to Perl

thanks for your help!

Edit: formatting and deleted dup stuff - dvergin 2002-04-10

Replies are listed 'Best First'.
Re: Formating in print
by japh (Friar) on Apr 11, 2002 at 00:47 UTC
      OK i see! thanks

      i thought the chomp deleted the \n BEFORE it could make a newline

      i guess i was wrong!

      im also making another program that will use the cd-tray to lock a door with a password (dont ask... another of my whacko ideas! the cd-tray will move a lever etc.)

      i will use the system command "eject" to open and close the tray. what i need is a way to find the status of the tray. is it open? is it closed? im looking into the Audio::CD module to see if the "stat" command will work

      any ideas on this insane project?

Re: Formating in print
by emilford (Friar) on Apr 11, 2002 at 00:54 UTC
    I know that perl has a module called Term::Readkey that you could probably take advantage of to do whatever it is you're trying to do. I've never really used it before though, so one of the other monks will probably need to expand...or you could try looking it up on CPAN.
    For example:
    use Term::ReadKey; ReadMode 'cbreak'; # makes each char available as it is typed $key = ReadKey(0); # get the single char # I guess here is where you'd want to print the comma # ReadMode 'normal'; # return mode back to normal

    If you want to get the individual coordinates, why not just have the user enter the two values seperated by a comma and then use the split function to get the values into an array. Just a thought.

    But anyway, give the Term::ReadKey a look and see if that'll help you out at all. -Eric
      hmm... it doesnt print...

      when i used <STDIN> it would show what i was typing. Now it shows nothing even when i print

      heres my new code:

      #!/usr/bin/perl # The distance formula!!! use Term::ReadKey; print "What is the first point? ("; ReadMode 'cbreak'; $x1 = ReadKey (0); print "$x1,"; ReadMode 'cbreak'; $y1 = ReadKey (0); print "$y1)\n"; print "What is the second point? ("; ReadMode 'cbreak'; $x2 = ReadKey (0); print "$x2,"; ReadMode 'cbreak'; $y2 = ReadKey (0); print "$y2)\n";

      im confused with this Term::ReadKey

      STDIN seems much more friendly :P

        I don't really know what to tell you. Like I said, I've never actually had a use for Term::ReadKey, so I've never written any code using it. I just remember reading about and thought it might help. Perhaps one of the other monks can give you some insight. Good luck.