in reply to Re^3: Creating a random generator
in thread Creating a random generator
May I ask why that site should be avoided? It is actually one of the cleaner sites out there. The sample code is at least legible without me having to <ctrl><mousewheel-up> to read it. It looks like it has a W3Schools feel to it.
Is it the fact that the tutorial is geared for web development? Web development and scripting go hand-in-hand. That is the reason I came here; I want to have a better and smaller web site through scripts. Javascript is too confusing, but Perl looks like it at least has some hard and fast rules to use it.
A select box, a hash of arrays, and a loop might save me the headache of maintaining 9 seperate web pages. (Though I am not sure about how Google will list it; will I get the listings for each option <hoping>, or just the one, or none because it would be a Perl script.)
Oh, and sorry for not linking it. I am still getting used to posting here. This forum is unlike the ones I am used to where I have to actually use html code to make by posts look good, though, I can handle it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Creating a random generator
by blazar (Canon) on Sep 28, 2007 at 14:48 UTC | |
May I ask why that site should be avoided? I will comment on some random excerpts from the site below. It is actually one of the cleaner sites out there. The sample code is at least legible without me having to <ctrl><mousewheel-up> to read it. It looks like it has a W3Schools feel to it. Should I create a deliberately full of bullshit clean site with a W3Schools feel, would you trust everything that's written into it, or consider it valuable? Is it the fact that the tutorial is geared for web development? Web development and scripting go hand-in-hand. That is the reason I came here; I want to have a better and smaller web site through scripts. Javascript is too confusing, but Perl looks like it at least has some hard and fast rules to use it. (Client-side) JavaScript and (server-side) Perl serve different purposes, although (Yes: I have issues with the tutorial being geared for web development, but that's an idiosyncrasy of mine so I'm not bringing it forth as a "rational" argument.) I'm not commenting on your will to make your site smaller and better by means of server side scripting and I wish nothing but the best for you in this respect. A select box, a hash of arrays, and a loop might save me the headache of maintaining 9 seperate web pages. (Though I am not sure about how Google will list it; will I get the listings for each option <hoping>, or just the one, or none because it would be a Perl script.) You surely have several options to have all of your pages indexed. Of course you can make your urls also look like they were those of a static page. Take for example the link above and consider the url http://en.wikipedia.org/wiki/AJAX: do you really think that there's a physical /path/to/wiki/AJAX on the machine running the server for that site? Oh, and sorry for not linking it. I am still getting used to posting here. This forum is unlike the ones I am used to where I have to actually use html code to make by posts look good, though, I can handle it. That's not a problem: you can learn as you go. You can use some restricted (which is very good, IMHO) HTML code in your posts. You also have shortcuts that make your life considerably easier. To me it's much more handy to write e.g. [wp://AJAX] than <a href="http://en.wikipedia.org/wiki/Special:Search?search=AJAX">AJAX</a>. Here are some comments to excerpts from the site: This tutorial will be covering the PERL syntax and should provide you with a very solid foundation of PERL for you to build upon. There's Perl and there's perl, but not such a thing as PERL. This is even the subject of a faq entry. Please notice that this may seem a very lightweight flaw to you but as you can read e.g. in PERL as shibboleth and the Perl community it is much used in Perl circles to tell who's in the know from who is not, and it's not a matter of elitist attitude, trust me: whoever wrote that doesn't know Perl but in possibly a very superficial manner and I wouldn't want read on the site, but let's go on... The language is very simplistic, offering optimum flexibility, perfect for short, straightforward scripting. I can't see how one could claim Perl to be simplistic: it is often alleged to be awkwardly complex instead... First things first, you must have PERL 5.005 installed on your web hosting machine. Version 5.005 is available for download via Perl.com, just follow the download links. It's dealing with 5.005 and while Perl is mostly backwards compatible, this detail clearly shows that the tutorial is at best seriously outdated. Regardless of the program you choose to use, a PERL file must be saved with a .pl (.PL) file extension in order to be recognized as a functioning PERL script. Where? Why? How so? Funnily enough the "tutorial" is strongly geared at *NIX audience, where the concept of "extension" is even non-existant. And as far as the web server is concerned, it's all up to its configuration, but that claim with "must" is plainly wrong and misleading. File names can contain numbers, symbols, and letters but must not contain a space. Use an underscore (_) in places of spaces. Where? Why? How so? While I don't particularly like spaces in filenames, especially in programs, most modern enough osen can happily deal with them, from *NIX where anything but "\0" and "/" can be used, to Win where they're actually abused. So what? helloperl.pl:: Personally, however web-oriented the tutorial may be, I would introduce
and -T early. Good programming practices are good programming practices everywhere, even more where security matters... Another great debugging technique is to isolate the code you are currently working on. To do this you can temporarily comment out lines of code to isolate only the section that is returning an error message. ... Comments are necessary for any script you wish to publish to others or make readily available. Not necessarily. Well crafted, self explaining code with proper POD documentation could happily have very few to no comments at all.
Whoa! What a nice practice to advertise... In PERL we use the backslash (\) character to escape any type of character that might interfere with our code. For example there may become a time when you would like to print a dollar sign rather than use one to define a variable. To do this you must "escape" the character using a backslash (\). Not in "PERL". In double quoted strings. Because he should say, first, that those strings interpolate variables. Outside of a string, the backslash befor a dollar sign has an entirely different meaning. The latter example using the my parameter is another means to define a variable that you might run across as you gain more experience. It is not necessary to use the my parameter. Variables can be defined either way. Funny: I had never heard anyone call my a "parameter"! Anyway, he who writes shows not to have understood what it is all about and if by any chance he/she did, then he's still giving that impression. Scalar variables are simple variables containing only one element--a string or a number. Strings may contain any symbol, letter, or number. No, they can contain much more. Notice that we used a period (.) between each of our variables. This is a special kind of operator that temporarily appends one string to another. "Temporarily"? Also, the IMHO bad example with print will get some people into the habit of always using the concatenation operator. Numbers are scalar data. They exist in PERL as real numbers, float, integers, exponents, octal, and hexidecimal numbers. Not exactly: some confusion between ways to specify numbers, and numbers. Logical operators state and/or relationships. Meaning, you can take two variables and test an either or conditional. Logical operators are used later on in conditionals and loops. For now, just be able to recognize them in the upcoming examples. Funnily enough, he mentions numeric and stringwise comparison operators at a time, in a table, without specifying in what they differ and thus giving the impression that e.g. > and ge are equivalent. To be sure, it claims that 7 ge 11 is a false value. But it is true!!!
There are two ways to set an array to scalar mode. We can use the scalar() function or we can redefine the array as a scalar variable. ... Ok, I grew tired and I'm stopping here, but I'm sure there are quite a lot of other "gems"... Update: at the request of the person I'm replying to, Lady_Aleena, I put the above in spoiler tags and duplicated it to a new meditation. | [reply] [d/l] [select] |
by Lady_Aleena (Priest) on Sep 29, 2007 at 07:13 UTC | |
Thank you for pointing out those problems with that tutorial to me. It had me hooked with the magic words of "web development" and by the way it looked. I didn't look at it as closely as you did. It is hard to find a Perl site that is geared specifically for web development. It is also hard to find a site about Perl that is written for the person who comes from markup or nothing at all. Perl Monks is a great resource, but it is kind of hard going through the tutorials here. That is why I keep having to ask questions. I hope one day to be able to start answering questions, but until then I hope the Monks will continue to put up with me until I can wrap my head around Perl. I read that article on AJAX, and I will probably not use it as I have no XML on my site. I will also only use javascripts written by others as the last time I tried writing one on my own, I blew it big time since javascript is so bloody difficult. Could you possibly point me to a page here or elsewhere that will show me the different ways a Perl script can be indexed? About some of the points you raised for the errors on that site. I wondered what Perl means. Win is short for Windows, is Perl short for something? You also made me look up the word shibboleth, good for you...I learned a new word. You are right about Perl being a pain in the rear to use at times, but it is much easier than javascript. File extensions requirements may be a relatively new to those reading that tutorial. With html, one could use .htm or .html, so a singular file extension requirement may trip up newcomers. The file names without spaces thing baffles me as much as it seems to be baffling you. As for the use statements at the beginning of Perl scripts. They are not required to make a script work as far as I can tell. The use of use strict is like choosing between using html or xhtml and between transitional *html and strict *html. If one doesn't want strict, one shouldn't have to put it in their script. Turning on warnings for web scripts is mostly a waste of space if the warning messages don't get through to the programmer. Some web servers wouldn't show the errors no matter what you added up in use. I am a victim of that. For me it is a fluke if I get a warning with the following in my code.
For simple scripts, scalars will (generally) hold only numbers or strings. So, for the simple programmer, that's all that (IMO) they need to know to start. Don't bog the newbie down with too much all at once. Newbies probably wouldn't know what interpolation or concatenation is. Even I have a hard time figuring those out. I have a small clue about what those words mean but still have to look them over and over again. | [reply] [d/l] [select] |
by blazar (Canon) on Sep 30, 2007 at 22:26 UTC | |
Thank you for pointing out those problems with that tutorial to me. It had me hooked with the magic words of "web development" and by the way it looked. Then don't be fooled by shiny little thingies. Be cautious. Of course it's fine to learn something bad to be corrected and turn it into the good version of it. But it's even better to learn it right from scratch. I didn't look at it as closely as you did. Chances are you wouldn't have known anyway, since you're admittedly a newbie. That's why I was warning you. It is hard to find a Perl site that is geared specifically for web development. It is very easy to find "Perl sites" that are geared specifically for web development. Far too easy. It is very hard to find good ones. I read that article on AJAX, and I will probably not use it as I have no XML on my site. I was not suggesting you to use AJAX. Nor is it the case that you have to "have XML on your site", there are quite a lot of JS libraries for this which will handle the "dirty" job under the curtain for you, and perl modules which provide "bindings" into those. I will also only use javascripts written by others as the last time I tried writing one on my own, I blew it big time since javascript is so bloody difficult. While I only touched upon JS and never wrapped my head around it, overall I would regard it as a much simpler programming language than Perl. (Of course it can be hard to know object hierarchies and such...) Could you possibly point me to a page here or elsewhere that will show me the different ways a Perl script can be indexed? Huh?!? Perl scripts are not indexed. Perhaps the pages they generate. I think you just want to learn about robots.txt and the robots meta-tag. Then, just ask Google. I wondered what Perl means. Win is short for Windows, is Perl short for something? The story is narrated elsewhere, but in some sense it is short for pearl. You are right about Perl being a pain in the rear to use at times, but it is much easier than javascript. I was not claiming nor implying that Perl is a PITA either at times or on a regular basis. Incidentally as I wrote before I consider it to be more complex than JS. But what's more important (in their typical usages - to which you're referring to now) is that they serve two different purposes, at two different ends of a medium. File extensions requirements may be a relatively new to those reading that tutorial. With html, one could use .htm or .html, so a singular file extension requirement may trip up newcomers. The file names without spaces thing baffles me as much as it seems to be baffling you. Huh?!? As for the use statements at the beginning of Perl scripts. They are not required to make a script work as far as I can tell. We recommend people to adopt those particular use statements in quite about any script beyond the level of a bare oneliner: CGI (and more generally, web-oriented) scripts do not make an exception. If you want to ask perl all the help it can give you not to make trivial errors then it will; if you don't... well you're on your own. The use of use strict is like choosing between using html or xhtml and between transitional *html and strict *html. If one doesn't want strict, one shouldn't have to put it in their script. Poor but somehow appropriate analogy. With the important difference that Perl's strictures reduce your freedom by enforcing good programming techniques that will likely prevent you from making typical programming errors: which is a great help to trade for those lost degrees of freedom. If one doesn't want strict, then she's on her own again. But she should also know that when posting code for help, people will point out that enabling strict and warnings would have allowed her to find the problem in the first place. Turning on warnings for web scripts is mostly a waste of space if the warning messages don't get through to the programmer. I'm quite confident that they're in the logs. But most importantly, one should first try the scripts on a shell, then upload them when reasonably sure that they're error and warnings free. (Of course in real world one can rarely be.)
That won't show warnings in your browser. Only fatal errors. Thus I presume that making all warnings fatal errors with:
would work. But even with this I stress that one should test the script on a shell first. And in any case use CGI::Carp qw(fatalsToBrowser); is nothing but a tool useful during development, but I'd rather take it out for "production". For simple scripts, scalars will (generally) hold only numbers or strings. So, for the simple programmer, that's all that (IMO) they need to know to start. Don't bog the newbie down with too much all at once. You wrote the magic world yourself: generally! it would have been enough if they also wrote it, perhaps in parens as you did: IMNSHO it wouldn't have been to "bog the newbie down with too much." Newbies probably wouldn't know what interpolation or concatenation is. Even I have a hard time figuring those out. I have a small clue about what those words mean but still have to look them over and over again. Huh?!? You must be joking? Whatever, my point is being exactly that just because newbies probably don't know what interpolation is, they should be told. The tutorial, instead, uses it without even explicitly explaining what it is! | [reply] [d/l] [select] |
by Lady_Aleena (Priest) on Oct 03, 2007 at 09:32 UTC | |
by blazar (Canon) on Oct 03, 2007 at 23:08 UTC | |