Teen Programmers Unite  
 

 

Return to forum top

easy perl/emacs question

Posted by LKStruck [send private reply] at March 10, 2003, 08:22:23 PM

I just started learning perl using emacs on linux 8.0
I thought everything was going great...Then I tried to create a basic program for user input. The line that I tried was;
$input=<STDIN>
print "you entered" $input;
What I get is;
you entered
Why doesn't emacs recognize <STDIN>
I've tried different combos and for some reason it just won't prompt me for input. Whats the deal?

Posted by gian [send private reply] at March 10, 2003, 09:17:12 PM

"linux 8.0"

There is no such thing. I presume you are referring to the Distribution which you are using, presumably Redhat 8.

Emacs is a text editor, and AFAIK does not have a perl interpreter in it (although it seems to have everything else, so I could be wrong). What you need to do is either: a) Save it as a .pl file and run "perl thefile.pl" or b) At the beginning of the file put "#!/usr/bin/perl" (I think that's where it lives), and then set it to executable using the command "chmod +x thefile.pl".

Posted by LKStruck [send private reply] at March 10, 2003, 09:59:32 PM

Yes... Sorry about the redhat thing
Here's my code;
>#!/usr/bin/perl
>print "Enter the Data: ";
>$data = <STDIN>
>print "You entered $data !!";
I made the file executable by entering;
>chmod +x data.pl
at the shell prompt, and then executed by entering
>./data.pl
and
>perl data.pl
The response is;
<Enter the Data: You entered !!
It doesn't prompt me for input.
Do I need to include some kind of library or initiate a mode or (i hope) is it just syntax?

Posted by vexoid [send private reply] at March 10, 2003, 10:13:05 PM

Try a semicolon after <STDIN>... and you should chomp($data) to get rid of the line feed.

Posted by LKStruck [send private reply] at March 10, 2003, 10:35:27 PM

I made the changes and there is no difference.
I also changed the mode from <Fundamental> to <Perl>
I also added -w to the end of #!/usr/bin/perl
I get the warning
"use of uninitialized value"
I just can't get it to prompt me for input

Posted by taubz [send private reply] at March 10, 2003, 11:30:39 PM

It works for me. There's no reason why it shouldn't work. What's this "mode" you're referring to?

Posted by LKStruck [send private reply] at March 11, 2003, 12:00:44 AM

I think I may just have a crappy version of emacs.I'm using emacs on REDHAT linux 8.0 and right above the minibuffer is a line with a bunch of info like what line you're on and so on. One of these peices of information is what mode it's operating in. When I start the program it seems to use as a default <Fundamental> you can change this (as I have done with no positive outcome concerning my problem) to a bunch of different things. Apparently there are two perl modes. I changed it by entering| M-x perl-mode |but you could enter cperl-mode. I've entered every program in the book I bought (learnin perl oreilly) that contains <STDIN> and none of them work. Maybe I just need a fresh version of emacs

Posted by stilldo [send private reply] at March 11, 2003, 12:02:33 AM

sorry... here i am, the ignorant n00b, but what the hell are you referring to with "emacs"? being a mac-user, im inclined to think its the newer version of the iMac, but there you go.

li'l help?

Posted by LKStruck [send private reply] at March 11, 2003, 12:13:47 AM

It's a text editor. I'm fairly certain it was created for use with unix/linux systems but I think you can get it on windows now too. It would be sweet if you could use emacs on iMacs just because of the confusion factor!

Posted by unknown_lamer [send private reply] at March 11, 2003, 02:50:56 PM

Emacs predates UNIX...(TECO...)

Anyway, don't run your perl programs in emacs. Just open a shell and run them from there.

Posted by stilldo [send private reply] at March 11, 2003, 03:37:33 PM

oh.. kool, thanks :)

Posted by gian [send private reply] at March 11, 2003, 09:45:22 PM

"Emacs predates UNIX..."

Emacs was written on a commercial UNIX platform (System V?).

Posted by unknown_lamer [send private reply] at March 12, 2003, 09:54:37 AM

No, Emacs was written as a set of macros for TECO on some old timesharing system originally. Eventually it was ported to POSIX systems when RMS started GNU.

Posted by split [send private reply] at March 17, 2003, 12:59:18 AM

Emacs is the devil.

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.