Hello,

I am new to perl, and am using perl on windows 98, i have tried writting a program, but the problem i experiencing is how to run the program.

1 i am using active perl 5 which came with an installer
2.i use note pad for the program and saved with the extension .pl

What do i do to run this program. Please help.


001

You could post the code, if it's a program with the code. One thing that I like to do is use a dos prompt and try to run the file.... you MIGHT have to load the perl Executable and pass the file as a parameter, something like:

c:\perl\bin\perl.exe myfile.pl

I have it running on my XP box, and I can just double click it, or type the name of the .pl file, as if it were an exe, com or bat. However, the first line of the perl file should be the path to your perl.exe... so:

#!c:\perl\bin\perl.exe

It might be different on your system, I'm not sure, but if none of those solutions work, post your code, and we'll check it out.

c:\perl\bin\perl.exe myfile.pl

where do i write that, on the run command of windows or the ppm of perl. On the ppm command, it does not recognize it while it says "file not found on the run command of windows".

c:\perl\bin\perl.exe is where mine is.

Actually, when i wrote the program in notepad, i save it on my desktop. It has the perl icon, but the problem is, when i double-click the icon for the program, the perl DOS screen pops-up with the output and disappears within a second such that you cannot see the output.
Any suggestions please.

001 :confused:

Well, You could click on start, go to run, type in cmd, and then use the dos interface to run the perl program. You put the #!c:\perl\bin\perl.exe as the very first line in your perl file. I might be confused, but it sounds like you are writing a perl module, and not an actual perl script, because most perl modules end in .pm, or I'm guessing too .ppm. However, if you run the script from the command line, you will see any output that it spits out at you.

you will see any output that it spits out at you.


I was just wondering if it is not possible to make the output remain on the screen instead of it just spitting it out, making it difficult to see the output.

001

This Introductions section is for members to introduce themselves, not for technical questions to be asked and answered. As we have a forum section specifically for Perl I'll move the topic to it.

Thanx Catweazle, I completely missed that one! :-|

001:

By using the dos prompt, the information that gets display stays on the screen. That's the whole point behind using the dos prompt. The information displayed will stay on the screen. In windows, as soon as you run your perl file, and it finishes, it closes the spawned dos-window that runs the perl file. If you are not very proficient at using DOS, another solution that can be used for testing purposes only is to add a:

$tmpvar = <STDIN>;

Before the program terminates. However, this requires you to hit enter, before the program will quit (if you put it before an exit or die), but it's easy to forget about it being in there... and it isn't really a good method of debugging. The best solution, is to run perl from the command line, passing your program as the parameter.

Thanks Comatose,

It worked , but I still experience problems with the output when there are errors in the program. It justs spits out the output and its difficult to read. What do i do.

001

Well, An Alternative Method is to use a filename for all your output, so, for example, in one program that I made, I needed all the Error Messages To Go To A Log File, So I stuck This at the top of my program:

open(STDERR, ">>log");

Then any error message that I needed to read, would be in the same folder as my script, in a file called "log". I think you can do the same for STDOUT, and have all output belonging to the screen redirected to a file also. Let me know how it turns out.

i tried it, but there was no error message written in the file.

Thanks Comatose,

It worked , but I still experience problems with the output when there are errors in the program. It justs spits out the output and its difficult to read. What do i do.

001

You could show us what you mean by pasting the difficult to read output between CODE tags here.

You can try this bit of code to get the output and errors into a scrollable Tk::Text window:

#!d:\perl\bin\perl.exe -w

use strict;
use Tk;
use IPC::Open3;

my $filename="perl myfile.pl";  # change me for a different file
my $mw=Tk::MainWindow->new();  # makes a new Tk window

my $button=$mw->Button(-text => "Run $filename",
	-command => \&runme )->pack();   # this is the run button
my $text=$mw->Scrolled(qw/Text -height 20 -scrollbars e/)->pack();  # stdout goes into this window
my $texterr=$mw->Scrolled(qw/Text -height 10 -scrollbars e/)->pack();  # stderr goes into this one

MainLoop;  
# Tk's mainloop, all event processing takes place here
# if we don't reach MainLoop then the entire Tk window will be
# unresponsive.

sub runme {  
  # this subroutine is called when the button is pressed 
  my $pid = open3 (*PROG_IN, *PROG_OUT, *PROG_ERR, $filename) or die "Boom: $!\n";   # ok Boom is not best error msg. 
  close (PROG_IN);  
  # PROG_IN is for writing to programs that require input
  # see Ch16 for info on blocking and deadlock...
  foreach (<PROG_OUT>)
    { $text->insert('end',$_); $mw->update;}
   # each line is inserted into the widget, and update is called to 
   # refresh it - i was having probs not seeing anything in text
   # windows.
  foreach (<PROG_ERR>)
    { $texterr->insert('end',$_); $mw->update;}  
  }

Both Tk and IPC modules come with Activestate's perl install. The runme subroutine is mostly straight out of the Perl Cookbook Ch16. It reads the STDOUT and STDERR of the program and inserts each line into the appropriate Tk::Text window.

*.ppm's are packages to be used with Activestate's ppm utility (Programmers Package Manager) This is how modules are installed under windows. Strikes me as very similar to a Debian binary dpkg. =)

Kordaff

then that means that there are no errors being output (which is a good thing). If you can actually paste the output here, it would help a lot.

Well if you really want to make the output stay on the screen. why not try using \r instead of \n.
On Tk, you can also use that open(STDERR,">>logfile");
and also use this line when executing your script.

c:\>perl -W myscript.pl>>logfile2.log

Well , hope that works :)

Hello,

I am new to perl, and am using perl on windows 98, i have tried writting a program, but the problem i experiencing is how to run the program.

1 i am using active perl 5 which came with an installer
2.i use note pad for the program and saved with the extension .pl

What do i do to run this program. Please help.

Hi,
please save your program in notepad with extension .pl, But
where have you saved your perl package? say suppose in c dive
In the pgm written in notepad the first line should be as follows:
c:\>perl
Now save the pgm with .pl extension, go to command prompt type
perl filename.pl
this will surely work if any doubts mail me up re_raju@yahoo.co.in:confused:

with windows 98, open a DOS window (MS-DOS prompt) and cd\ if necessary to get out of the windows directory.

Then type in:

c:\perl\bin\perl.exe name_of_script.pl

or if perl is in the command path:

perl name_of_script.pl

and press the enter key. The script will run and the output will remain on the screen. If it goes beyond one page of output you might be better writing the output to a file.

make sure you have an open command prompt window rather than typing the command into the Start > Run box. to open a command prompt window that wont disapear on completion, type cmd in the Start > Run box.

if you want to use the syntax c:\myperlscripts\perl myscript.pl, rather than c:\ActivePerl\bin\perl c:\myperlscripts\myscript.pl you need to add the path to the perl interprettor to the PATH environment variable. You can do this from the command prompt, but whatever you do, don't try it, it'll more than likely overwrite PATH with just the path to perl, and PATH generally contains alot of important paths. In XP, you can set environment variables from the My Computer > Properties popup dialog... I don't know if that's the case in Win98... Try My Computer (desktop) Right click > properties > advanced tab > environment variables button. Look for a system variable called PATH (case is irrelevant) and append the path to the perl interprettor to that list (semicolon delimited). My Perl path is C:\ActivePerl\bin.. and my whole PATH string looks like this:

c:\PHP\;c:\ActivePerl\bin;C:\Program Files\ActiveState Komodo 3.5\;C:\Program Files\Borland\Delphi7\Bin;C:\Program Files\Borland\Delphi7\Projects\Bpl\;c:\JavaProfiler\lib;C:\WinAVR\bin;C:\WinAVR\utils\bin;C:\Program Files\Alias\Maya7.0\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Intel\Wireless\Bin\;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;

Hey, I have two PATH strings, one for system and one for Matt... These paths screw up sometimes (they did more on my other PC)... But in general they should be concatenated when a program requests a named variable... So it doesn't matter if it's a user var or a system var.

c:\JavaProfiler\lib;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;

Now you all know what I've got on my PC :P

EDIT: Infact, if you installed ActivePerl properly, it should have appended itself to path automatically.

EDIT: Infact, if you installed ActivePerl properly, it should have appended itself to path automatically.

:)

ah... i had to type it all out before i remembered that... -_-

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.