Post subject: Why UNIX and Linux suck
Joined: 5/3/2004
Posts: 1203
I'm getting my second degree on May 6th, and I've already finished all my finals. All I have to do is finish up the final project for a UNIX class I signed up for. (I'm not a CS major, I just decided to take a UNIX class for my personal edification, and I had the time.) Anyways, the final project is ridiculously simple, just making a webpage with CGI that will run on Solaris. I've made a lot of CGI using VBScript in the past, and I have to say the language is really nice. For example, to access POSTed form variables, you just do this:
Request.Form("variablename")
To get the exact same result in PERL, you need to do this:
read(STDIN, $my_input, $ENV{CONTENT_LENGTH});
@fv_pairs = split /\&/ , $my_input;

foreach $pair (@fv_pairs) {
   if($pair=~m/([^=]+)=(.*)/) {
      $field = $1;
      $value = $2;
      $value =~ s/\+/ /g;
      $value =~ s/%([\dA-Fa-f]{2})/pack("C", hex($1))/eg;
      $INPUT{$field}=$value;
   }
}

$INPUT{variablename};
And that is why UNIX and Linux suck. Long live Microsoft.
Former player
Joined: 3/30/2004
Posts: 1354
Location: Heather's imagination
UNIX and Linux suck because Perl sucks?
someone is out there who will like you. take off your mask so they can find you faster. I support the new Nekketsu Kouha Kunio-kun.
Player (206)
Joined: 5/29/2004
Posts: 5712
.............Apparently yes! Because Perl is all you can use on them, I suppose!
put yourself in my rocketpack if that poochie is one outrageous dude
Joined: 5/3/2004
Posts: 1203
Yup. PERL is the canonical UNIX/Linux scripting language (outside of pure shell scripting), and most UNIX textbooks have a chapter on it.
Player (81)
Joined: 3/11/2005
Posts: 352
Location: Oregon
I see your flame and raise you a reasonable reply. Your code is correct, but a better way is to use the CGI module.
use CGI;
my $q = new CGI;
my $x = $q->param('variableName');
Perl is a wonderful language if you let it do the work. Google around for tutorials and I think you'll be pleased at what you can get done with a few lines of code.
ideamagnate| .seen aqfaq <nothing happens> DK64_MASTER| .seen nesvideoagent * DK64_MASTER slaps forehead
Joined: 5/3/2004
Posts: 1203
I did google tutorials, in excess of 20. Most of them had solutions that were so obfuscated or explained so poorly that I couldn't even get them to work. The code in my first post was the best that I found. I suppose the real problem here is that the functionality isn't built into the language, and everyone has a different way of doing something that really should be automatic. To contrast that with my experiences using VBScript, I have programmed incredibly complex applications using nothing more than MSDN as a resource, but to figure out how to do something incredibly simple in PERL, I have to read pages and pages of tutorials only to discover a substandard solution.
Player (81)
Joined: 3/11/2005
Posts: 352
Location: Oregon
Technically it's not built into the language, but iirc the CGI module is included with the core distribution. Many common tasks have modules just waiting to be used. You can find the documentation for the CGI module online here, along with a nice module search page here. I hope you don't let an unpleasant first experience kill Perl for you.
ideamagnate| .seen aqfaq <nothing happens> DK64_MASTER| .seen nesvideoagent * DK64_MASTER slaps forehead
Player (36)
Joined: 9/11/2004
Posts: 2631
Wow, hating on Linux because Perl is line noise. You know, there's more resonable reasons to hate Linux. Especially, if you hate Linux because of something that really has nothing to do with Linux. I love Perl personally. Sure it's difficult to read, but it easy to program in (if you know the tricks, which apparently you don't). But not everybody does, and there are more accessable scripting languages that are prettier to read, like Python.
Build a man a fire, warm him for a day, Set a man on fire, warm him for the rest of his life.
Player (201)
Joined: 7/6/2004
Posts: 511
That's like saying Windows sucks because AOL deletes your email after a while even if you haven't read it yet.
g,o,p,i=1e4,a[10001];main(x){for(;p?g=g/x*p+a[p]*i+2*!o: 53^(printf("%.4d",o+g/i),p=i,o=g%i);a[p--]=g%x)x=p*2-1;}
Post subject: Re: Why UNIX and Linux suck
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
xebra wrote:
VBscript
Request.Form("variablename")
To do the same in PHP, you use this:
$_POST['variablename']
It's shorter, ergo it's better ;) You lose. Btw, your Perl example doesn't even work if the form sent using the multipart/form-data enctype.
Joined: 5/3/2004
Posts: 1203
Bisqwit: Don't forget PHP gets minus points for dollar signs, underscores, and semicolons ;) . And you kind of prove my point by mentioning there is a problem with the code I found. That was the clearest way to access form variables I found in any tutorial until IdeaMagnate set me straight, and here you are saying the code doesn't even work. There are not similar problems with ASP (or PHP) because there simply isn't a way to make that task obfuscated or complex in those languages. Flagitious: I know you're just trying to feed the flame, here, but it's not the same at all. As I said before, PERL is the canonical scripting language for UNIX. UNIX textbooks dedicate chapters to PERL. Windows textbooks do not dedicate chapters to AOL. Anyways, the point of the thread wasn't really to knock on UNIX and Linux. My main goal was to: one, get someone to tell me a better way, and two, express my dissatisfaction that in the guise of learning about UNIX I am being forced to learn a disagreable language when much simpler, more intuitive, and equally powerful languages exist.
Joined: 3/7/2006
Posts: 720
Location: UK
Huh, only because people don't use Python. More Python programmers! It's
import cgi
cgi.FieldStorage()['fieldname'].value
in Python, for your reference. FieldStorage() returns a dictionary-like object with which many values can be read at once.
Voted NO for NO reason
Player (201)
Joined: 7/6/2004
Posts: 511
Your point would be valid except for the following *PERL isn't the best UNIX choice for web scripting *PERL is not UNIX, PERL exists for Windows too *UNIX books do not devote any chapters to PERL This is based on the only Linux/Unix book I own: Linux in a Nutshell, 800 pages long and less than 1 page of it is about perl. I'm sure there are linux books out there which go into more detail about PERL, but there are also Windows books that go into more detail about AOL. I think you raise a good point that PERL is not a good choice for most web scripting applications, and I agree completely. But taking that farther to say linux is bad, is completely wrong. It is unfortunate that you are being forced to use the wrong language for the job, and for that I apologize.
g,o,p,i=1e4,a[10001];main(x){for(;p?g=g/x*p+a[p]*i+2*!o: 53^(printf("%.4d",o+g/i),p=i,o=g%i);a[p--]=g%x)x=p*2-1;}
Banned User
Joined: 3/10/2004
Posts: 7698
Location: Finland
Don't get trolled. This is a clear case of: http://www.bash.org/?152037
Editor, Active player (297)
Joined: 3/8/2004
Posts: 7469
Location: Arzareth
Warp wrote:
Don't get trolled. This is a clear case of: http://www.bash.org/?152037
It is still a noteworthy attempt, for showing code :)
Joined: 3/8/2004
Posts: 185
Location: Denmark
To do the above call in IRC, you'd just type in
say %variablename
Or, if you just need it internally
%variablename
Thus IRCscripts > PHP Did anyone say comparing apples to african elephants?
"We observe the behaviour of simple folk, and derive pleasure from their defects." -Aristotle - Book of Humour
Joined: 5/3/2004
Posts: 1203
Haha, Warp. Surely I'm not that clever. Ask anyone.