Page 1 of 2
So I'm starting to learn Perl..
Posted: 2004-07-07 01:04am
by haas mark
And I feel more comfortable with a UNIX environment than I do with DOS. Where might I be able to find something to download so that I can use UNIX on my Win machine?
Also, because I don't know how, how does one change shells (it seems bash and Korn shells are preferred, and for the small time I was in a Java class, I preferred bash shell)?
Posted: 2004-07-07 01:23am
by Pu-239
http://www.cygwin.com/ for emulation of a Unix/Linux environment.
Even better, get Linux and dual boot
. Unfortunately, IE6 does not run well under Wine (last time I tried), so it's preferable to get a second computer and LAN, which I assume you do not have. Anyway, you can run Apache from Cygwin. Then again, old computers and NICs are cheap.
Bash is the default shell for Linux and Cygwin. I use zsh though (more features, completion is slower though). Change shells with chsh.
Posted: 2004-07-07 01:36am
by haas mark
Thanks! Now I can get started learning this stuff.. hopefully nowhere near as difficult as Java, though...
Posted: 2004-07-07 01:49am
by Pu-239
By the way, I hate perl (though when I redo my robotics website, I'm going to scrap PHP and use perl+xslt). Use PHP or server-side java for larger sites. Perl's syntax is ugly as hell. Hell, I almost prefer straight C over perl (need to learn more C++ - hate C++ because of too much specialized syntax- I like C better, but it doesn't have classes and references, plus malloc debugging is annoying).
You might want to figure out how to use Apache too, since uploading scripts to a server and testing can be quite annoying, and I doubt they have "easy" text editors on the server (though I do like using Vim, I don't know more than two other people who do (Wong and somebody who mentors for my robotics team, and only because of RSI after using emacs too much).
Posted: 2004-07-07 02:06am
by haas mark
Uh, ok. But I don't know PHP either, and I'm going to need to learn some form of Perl to work with CGI anyhow.
As for Apache... my last venture into that didn't go too well.
Right now I'm trying to figure out how to install ActivePerl..
Posted: 2004-07-07 03:34am
by Pu-239
verilon wrote:Uh, ok. But I don't know PHP either, and I'm going to need to learn some form of Perl to work with CGI anyhow.
As for Apache... my last venture into that didn't go too well.
Right now I'm trying to figure out how to install ActivePerl..
Then don't use CGI. PHP does what CGI can do.
And don't bother with activeperl... use Cygwin and it's included perl, since it's environment will be more similar with what you see on a UNIX server.
Anyway, does cygwin include Apache2 (I don't have the patience to download Apache 1.3 over dialup)? If so I can help you with apache config. If not, there are others here who can help you.
There's also server-side java, though I've never tried it, and it's overkill.
Posted: 2004-07-07 03:43am
by haas mark
Pu-239 wrote:verilon wrote:Uh, ok. But I don't know PHP either, and I'm going to need to learn some form of Perl to work with CGI anyhow.
As for Apache... my last venture into that didn't go too well.
Right now I'm trying to figure out how to install ActivePerl..
Then don't use CGI. PHP does what CGI can do.
I'll end up getting that eventually.
And don't bother with activeperl... use Cygwin and it's included perl, since it's environment will be more similar with what you see on a UNIX server.
Ok, but I downloaded and installed Cygwin and I tried
and it said "perl command not found" or something like that.
Anyway, does cygwin include Apache2 (I don't have the patience to download Apache 1.3 over dialup)? If so I can help you with apache config. If not, there are others here who can help you.
Not so far as I know.
There's also server-side java, though I've never tried it, and it's overkill.
-hisses at Java- That shit is evil.
Posted: 2004-07-07 03:45am
by Pu-239
When you run the cygwin installer there should be a list of things you can install, and you have to select perl, and you probably want to select apache2 or apache too.
If you have broadband, install everything, it's easier. 600 megs though, but I'm sure broadband can handle it.
Unlike dialup.
Posted: 2004-07-07 04:33am
by haas mark
Pu-239 wrote:When you run the cygwin installer there should be a list of things you can install, and you have to select perl, and you probably want to select apache2 or apache too.
If you have broadband, install everything, it's easier. 600 megs though, but I'm sure broadband can handle it.
Unlike dialup.
Okay, now I'm installing everything. So how do I get it to open up with the shbang at the beginning? (
#!/usr/bin/perl)?
Posted: 2004-07-07 04:37am
by Pu-239
I'm not sure on cygwin but try chmod +x, then ./[script], and if that doesn't work, just do perl [script] - omit brackets.
For CGI, you don't run them this way, hence the need to install apache. Still need chmod +x on a real UNIX server though, and probably cygwin if it supports permissions.
Other locations for perl are /bin/perl or /usr/local/bin/perl - should be unlikely to encounter these.
Posted: 2004-07-07 04:41am
by Comosicus
I also find PHP much easyer than Perl. And except some complex things (like a CGI proxy), PHP can handle almost everything Perl does.
That server-side Java is called Java Server Pages (JSP). I had some collegues using that and it lookd pretty nasty to me.
In my opinion PHP + good coded JavaScript can handle anything you like for a web site.
Posted: 2004-07-07 04:41am
by haas mark
Ok, and how do I create a script? Still pretty new to this stuff, and the books I've found so far already assume you know just that much about command line. Which I don't.
Posted: 2004-07-07 04:47am
by Comosicus
First script in Perl or PHP?
Posted: 2004-07-07 04:49am
by Pu-239
Also, when programming CGI, you should enable -T -w (enables tainting and stricter warnings). Also use strict. So, at the beginning of the script, do
#! /usr/bin/perl -w -T
use strict;
[stuff]
Perl CGI scripts can be easily exploited when written improperly, so any extra checking helps.
Anyway, I think Java is easy. If you think it's hard, you might have problems with perl, since I don't like perl.
Sample perl script:
Code: Select all
#!/usr/bin/perl
use strict;
my $directory = "./gallery/";
my $webdir = "./images/gallery/";
opendir(DIR , "$directory");
my @pictures = readdir(DIR);
closedir(DIR);
my $gallerynum = 0;
my $buffer;
my $j = 0;
my $piccounter =0;
@pictures = grep(/(.*)icon\.jpg/, @pictures);
for(my $i = 1; $j <= @pictures; $i++) {
open(FILE,">", "../pages/imagegallery$i.inc");
$buffer =
"<div class=\"cntntheader\">Image Gallery</div>\n" .
"<div class=\"content\"\n>" .
"<div class=\"gallerybox\"\n>";
$piccounter +=20;
print("Printed Header\n");
for($j; $j < $piccounter; $j++){
my $picbase = $pictures[$j];
$picbase =~ s#icon\.jpg##g;
$buffer = $buffer .
"<a href = \"./picture.php?image=$webdir$picbase" . "small.jpg\">\n" .
"<img src=\"$webdir$pictures[$j]\" alt=\"$pictures[$j]\" />\n" .
"</a>\n";
print("Printed Content\n");
}
$buffer = $buffer . "\t</div>\n</div>";
print("Printed Footer\n");
print FILE $buffer;
close(FILE);
}
This generates a gallery for generating HTML for stitching with PHP for image thumbnails and links. The result is
http://www.broken-llama.com/robotics/pa ... gegallery1.
Could have been made neater with tables, but I decided to not use tables for consistency (used pure CSS layout). Heck of a lot easier then writing all of them by hand though. It's not optimized at all though, but it's not a CGI script and is run only when images are added.
That's only like my 5th script ever though.
Posted: 2004-07-07 04:53am
by haas mark
Comosicus - Perl.
Pu-239 wrote:Also, when programming CGI, you should enable -T -w (enables tainting and stricter warnings). Also use strict. So, at the beginning of the script, do
#! /usr/bin/perl -w -T
use strict;
[stuff]
Okay, now to figure out how to get to the beginning of the script..
Perl CGI scripts can be easily exploited when written improperly, so any extra checking helps.
Anyway, I think Java is easy. If you think it's hard, you might have problems with perl, since I don't like perl.
Well, the hard stuff I had with Java was (a) it was the guinea pig class, (b) class moved too fast, (c) we did exercises with stuff not covered in the text, and barely in lecture, (d) most of the class failed the first test, and (e) arrays.
Allrighty.
Posted: 2004-07-07 05:06am
by Pu-239
To create a script under cygwin, try nano [scriptname], then add the stuff at the top and write the contents. You could try notepad/textpad/blah too, but I don't know where you installed cygwin. Emacs is a lot better, but harder to use. The best is obviously vim, however according to some, it turns you crazy (into a Unix nerd who hunts G&C into the middle of the night looking for threads pertaining to *NIX and then replying in a matter of minutes).
Posted: 2004-07-07 05:12am
by haas mark
Pu-239 wrote:To create a script under cygwin, try nano [scriptname], then add the stuff at the top and write the contents. You could try notepad/textpad/blah too, but I don't know where you installed cygwin. Emacs is a lot better, but harder to use. The best is obviously vim, however according to some, it turns you crazy (into a Unix nerd who hunts G&C into the middle of the night looking for threads pertaining to *NIX and then replying in a matter of minutes).
Like you? ;P
Well, I'll try that when I have some time tomorrow, but right now it's time for bed. Need to be able to try to get to sleep before sunup so I can be up *before* too late this afternoon...
Posted: 2004-07-07 05:24am
by Pu-239
verilon wrote:Pu-239 wrote:To create a script under cygwin, try nano [scriptname], then add the stuff at the top and write the contents. You could try notepad/textpad/blah too, but I don't know where you installed cygwin. Emacs is a lot better, but harder to use. The best is obviously vim, however according to some, it turns you crazy (into a Unix nerd who hunts G&C into the middle of the night looking for threads pertaining to *NIX and then replying in a matter of minutes).
Like you? ;P
Well, I'll try that when I have some time tomorrow, but right now it's time for bed. Need to be able to try to get to sleep before sunup so I can be up *before* too late this afternoon...
Sky is already starting to lighten up in this timezone (Eastern).
Posted: 2004-07-08 03:06am
by haas mark
Pu.. can you tell me which options I *need* to be able to program in Perl with this Cygwin thing? It seems to take *forever* to install this stuff...
Posted: 2004-07-08 03:22am
by Pu-239
perl*, bash*, apache (there's no apache2, so that might make it more difficult for me to help, but most other people use regular apache anyway), nano (maybe Emacs, or you can use a normal Windows text editor), perl_manpages, maybe pinfo, pdksh if you want ksh. You should keep whatever is in the default install too.
RXVT is recommended if you don't want to be constrained to a small CMD window. Easiest way to start RXVT is to open up bash, type "rxvt -bg black -fg gray -e bash", and work from that. I'm not sure about the options for rxvt though, since I don't have it installed. Cygwin should automatically install everything else needed.
I can also set up a limited shell account on my server for your use but that may take awhile for me to secure from local exploits, and I'm running out of space, not to mention it's a PII-233 with limited resources. I also have to ask permission, since the machine is hosted inside my friend's internal network, with lots of insecured machines (Mine is pretty secured from remote attacks, though need to upgrade kernel, which is hazardous remotely).
Posted: 2004-07-08 03:24am
by haas mark
Err.. Ok. I'll try to figure that all out. Thing is, I tried installing it before, and it decided that the chsh command didn't exist.
Posted: 2004-07-08 03:34am
by Pu-239
verilon wrote:Err.. Ok. I'll try to figure that all out. Thing is, I tried installing it before, and it decided that the chsh command didn't exist.
You probably have to install that too (don't know what package that is in). There's always manual editing of /etc/passwd. Fileutils, textutils, findutils, and cygutils should also be installed if they aren't.
EDIT: chsh should be in the passwd package.
If cygwin doesn't work, try
Microsoft SFU. I don't know anything about this product though.
Posted: 2004-07-09 03:05am
by haas mark
Ok so now how do I run the damn thing?
Posted: 2004-07-09 03:27am
by Crayz9000
verilon wrote:Pu-239 wrote:To create a script under cygwin, try nano [scriptname], then add the stuff at the top and write the contents. You could try notepad/textpad/blah too, but I don't know where you installed cygwin. Emacs is a lot better, but harder to use. The best is obviously vim, however according to some, it turns you crazy (into a Unix nerd who hunts G&C into the middle of the night looking for threads pertaining to *NIX and then replying in a matter of minutes).
Like you?
Like me
Posted: 2004-07-09 03:37am
by Pu-239
verilon wrote:Ok so now how do I run the damn thing?
Clicking the cygwin icon should give you a bash shell. Type "rxvt -fg gray -bg white" should give you another shell. If it's not bash, or does not behave like bash, hit enter. Typing info bash is suggested, though not required. Type "nano programname" and type in
Code: Select all
#! /bin/perl -w -T
use strict;
[your stuff here]
Keyboard commands for nano are listed at the bottom- ^ means control.
To run, chmod +x programname, then run with ./run . Most of this stuff should be covered in your perl book.