Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic

What's your favorite scripting language?
Perl  22%  [ 6 ]
PHP  44%  [ 12 ]
Python  15%  [ 4 ]
Ruby  15%  [ 4 ]
Bash  4%  [ 1 ]
Something else entirely.  0%  [ 0 ]
Total votes : 27
Author Message
PostPosted: Tue Apr 14, 2009 6:52 am 
Offline
Junior Member
User avatar

Joined: Thu Sep 11, 2008 6:46 pm
Posts: 36
Website: http://www.classhelper.org
Location: Atlanta, GA
Given the sheer number of useful Perl scripts available for Linux-based systems, knowing the basics of the language is a definite plus for anyone running their own server. I use Perl for tasks ranging from system scripting to web development and database stored procedures (MySQL and Postgresql are cool like that).

While it's not intended to serve as more than a true beginner's guide, some may find my tutorial useful: http://www.classhelper.org/articles/perl_tutorial/learn_perl_introduction.shtml

It assumes no prior knowledge of programming, and provides real-world(ish) examples for each chapter. Hope you find it useful :).

_________________
Educational resources for parents and teachers: http://www.ClassHelper.org


Top
   
 Post subject:
PostPosted: Tue Apr 14, 2009 8:43 am 
Offline
Senior Member

Joined: Mon Feb 28, 2005 7:21 pm
Posts: 76
I spent many years with Perl, but now PHP is my server-side language of choice. These days I think many folks would actually be learning JavaScript or another client-side language first! What I've always liked about PHP is its much easier syntax for complex data structures (and arrays in general). I don't have to keep referring to the Perl cookbook :)

I've also been writing quite a few bash scripts, mostly to provision and customize linodes. Most recently, as part of switching to Ubuntu from CentOS, I learned more about bashisms (because I had to write some init scripts, which are run with dash).

Looking very briefly at your tutorial, I noticed a few small things. Sorry my Perl is a bit rusty, though--

1. Love the -w and use strict!

2. You build an array with newlines appended to each part, which seemed a little odd.:
Code:
@grocery_list = ("apples\n", "oranges\n", "milk\n", "bread\n");
print @grocery_list;


If you omitted the newlines, you could do things like:
Code:
print "@grocery list";
print join("\n", @grocery_list) . "\n";

3. The first loop you show is with for, I think foreach is simpler for most applications (since this is a beginners guide). You could even refer back to your grocery list to show how you could introduce some formatting.

4. You simply must introduce sanitizing user input when you get into the "dynamic content" section (you do mention it briefly). For example, If you expect numbers for input, remove everything else. We don't need more CGIs with injection and cross-site scripting problems.

This is a good time to talk about -T (taint) to identify such unsafe inputs. I wouldn't write any Perl-based Web interface without it.

I would also link people to a page like http://www.owasp.org/index.php/Unvalidated_Input for details.


8)


Top
   
PostPosted: Tue Apr 14, 2009 9:03 am 
Offline
Junior Member
User avatar

Joined: Thu Sep 11, 2008 6:46 pm
Posts: 36
Website: http://www.classhelper.org
Location: Atlanta, GA
With respect to #2, I debated this for awhile. Wanting to keep the syntax as straightforward as possible for someone who's never seen code before, I opted out of "join" in that section. However, there's no reason I can't introduce it as an alternative.

I'll do the same with the "for" versus "foreach" loop structure, which is another good demonstration of the "more than one way to do it" philosophy. I started with "for" more out of deference to the first language I learned as a kid, which was C. The point about introducing some different formatting is a great one.

You're right that I should introduce taint mode and more rigorous input validation. While my aim is to make things as easy as possible for a raw beginner, there is definitely such a thing as knowing just enough to be dangerous. A couple of explanatory paragraphs with some practical demonstrations of these concepts might save someone from a nasty situation. While the security chapter does contain some links to pages that cover taint mode, I'll be adding your link to the list.

Thanks again for the great feedback :).

_________________
Educational resources for parents and teachers: http://www.ClassHelper.org


Top
   
 Post subject:
PostPosted: Tue Apr 14, 2009 11:26 am 
Offline
Senior Member
User avatar

Joined: Fri Jan 02, 2009 11:31 am
Posts: 141
Website: http://faroutscience.com
Location: Texas / Kansas
PHP is very nice but I'm starting to learn Ruby.

Jeff


Top
   
 Post subject:
PostPosted: Tue Apr 14, 2009 4:14 pm 
Offline
Junior Member
User avatar

Joined: Mon Apr 13, 2009 12:59 pm
Posts: 27
Website: http://ultramookie.com
Location: interwebs
I love PHP and Perl both. I think they have their own strengths and weaknesses. I use a lot of Perl at work to do stuff (along with Bash) since I do a lot of SA type work. But, for fun, I like to write PHP code (http://github.com/ultramookie).

I have a Ruby book and need to start reading up on Ruby. I hear it is quite nice.

_________________
http://ultramookie.com/


Top
   
 Post subject: Same here.
PostPosted: Tue Apr 14, 2009 8:30 pm 
Offline
Junior Member
User avatar

Joined: Thu Sep 11, 2008 6:46 pm
Posts: 36
Website: http://www.classhelper.org
Location: Atlanta, GA
ultramookie wrote:
I love PHP and Perl both. I think they have their own strengths and weaknesses. I use a lot of Perl at work to do stuff (along with Bash) since I do a lot of SA type work. But, for fun, I like to write PHP code (http://github.com/ultramookie).

I have a Ruby book and need to start reading up on Ruby. I hear it is quite nice.


I haven't done anything with Ruby, and I really ought to. I've heard it supports Lisp-y language features, which brought back memories on a friend's dad explaining SmallTalk programming to be as a kid.

_________________
Educational resources for parents and teachers: http://www.ClassHelper.org


Top
   
PostPosted: Tue Apr 14, 2009 9:21 pm 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
ClassHelper wrote:
With respect to #2, I debated this for awhile. Wanting to keep the syntax as straightforward as possible for someone who's never seen code before, I opted out of "join" in that section. However, there's no reason I can't introduce it as an alternative.


I think you should hold off on arrays at that point. You've introduced a scalar, so now you could introduce the use of scalars in a foreach loop, such as
Code:
my $loopvar;
foreach $loopvar (1..10)
{
  print "We are $loopvar times around the loop\n";
}


THEN you can introduce arrays, and show the printout as "foreach $loopvar (@array)". This maintains consistency with the \n in each print statement. And then you can show the join() syntax as a shortcut.

Your "print @array" is actually quite a powerful feature (shows implicit type conversion) and not something to introduce as a throw-away.

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
 Post subject: Another good suggestion.
PostPosted: Tue Apr 14, 2009 9:54 pm 
Offline
Junior Member
User avatar

Joined: Thu Sep 11, 2008 6:46 pm
Posts: 36
Website: http://www.classhelper.org
Location: Atlanta, GA
Yet another item on my list of stuff to add to the tutorial :). God, I'm gonna wind up with something that looks like an O'Reilly book within a matter of months :).

_________________
Educational resources for parents and teachers: http://www.ClassHelper.org


Top
   
 Post subject:
PostPosted: Tue Apr 14, 2009 10:16 pm 
Offline
Senior Member

Joined: Mon Feb 28, 2005 7:21 pm
Posts: 76
All these Perl flashbacks! 8)

I see 1..10 (as a beginner) and wonder, what is that?

I think someone is more likely to want to iterate over an array since that seems logical, or print the value of $i++ in any loop, than to use sweh's foreach/range example.

What do you think the first built-in function is that someone would use? chomp? chop? split? join?

Perhaps I missed it, but CPAN could deserve a mention in the resources section.


Top
   
 Post subject:
PostPosted: Sat Apr 18, 2009 6:06 am 
Offline
Senior Member

Joined: Fri Feb 17, 2006 9:47 pm
Posts: 91
Ruby is where it's at, it banishes those awful memories of writing PHP, yuck.


Top
   
 Post subject:
PostPosted: Tue Apr 21, 2009 2:55 pm 
Offline
Junior Member

Joined: Tue Apr 27, 2004 11:46 pm
Posts: 30
What kind of scripting are we talking about here?

Web site scripting? or system administration tasks? or...?

Perl, PHP, Python, Ruby, etc, all have varying purposes.

Perl is what I mostly use for quick sys admin type tasks.
PHP is what I use when I need a quick web script to run something.
My larger websites are built using Python and Django.

Bash is shell scripting... very useful for certain tasks.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group