1. Computing
Send to a Friend via Email

New to Perl?

If you're new to Perl or programming in general, we've got a nice, easy introduction for you. We'll get your environment set up, talk you through your first Perl script and start looking at some basic Perl functionality.

Follow along
Perl Spotlight10

Calculate Perl String Length

Tuesday January 3, 2012

Perl 6 Camelia logo

One of the most common things you might want to do is calculate Perl string length. For instance, you might ask the user to enter some text and want to make sure that they haven't entered too much or too little. Piece of cake. Just use Perl's length() function.

But that's just scratching the surface of what Perl can do with strings. Being designed from the ground up as a text manipulation language, Perl has a lot of string functions. Try some of these out in our quick and easy guide.

Photo Bagwold | Dreamstime.com. Used with permission.

Comparing two values in Perl

Friday December 30, 2011

Unless you know in advance exactly what values your Perl programs are going to deal with, then at some point you're going to need to test one value against another. For instance, you might want to display a simple "Continue? (Y/N)" message to your user. If they enter 'Y' you will perform some processing. If they enter 'N' your program should exit.

Perl uses comparison operators to achieve this. In this simple beginner tutorial Comparing Values in Perl we look at how you compare two values and direct program flow accordingly.

Perl 6 Coding Contest

Friday December 30, 2011

Perl 6 Camelia logo

What's that you say? Perl 6 hasn't been released yet?

Well, of course, you're right. Perl creator Larry Wall has been telling people at just about every Perl conference over the last couple of years that Perl 6 will be out "by Christmas". Of course, he never told us which Christmas!

However, some folks just aren't prepared to wait for an official release and want to start playing with Perl 6 straight away. If you're among them, you can access a preview release of Perl 6 called Rakudo Star.

And if you're cutting edge enough to playing with Perl 6 already, why not enter the Perl 6 Coding Contest? There are five tasks to complete:

  • Find a way to express an integer as an expression containing four 9s
  • List numbers which are sums of cubes in more ways than one
  • Calculate addition chains
  • Slide a hex-shaped piece across a board
  • List all possible trees of a certain type

You'll be judged on the clarity, consistency, brevity and efficiency of your code. If you fancy your chances, find out more at the Strangely Consistent Perl 6 blog.

Image Larry Wall - used with permission

Other things you can do with Perl strings!

Friday December 30, 2011

Perl String Manipulation

Ok, so we're focusing on regular expressions over the next couple of weeks. But let's not forget all the other things you can do with Perl strings.

Perl is famous for its ability to parse text. In fact it was designed initially as a text manipulation language. Creator Larry Wall's main objective in creating Perl was to make it simpler for programmers to extract and format text by combining all the things he liked about sed, awk and C. Hence the name: PERL (Practical Extraction and Reporting Language).

Although it wasn't long before developers (particularly web developers and system administrators) harnessed the power and flexibility of Perl for other applications, it remains to this day one of the best languages out there for slicing and dicing text. It handles strings faster and more efficiently than many other languages and has a whole range of functions for comparing, sorting, extracting and manipulating strings. Learning how to work with strings is fundamental to understanding Perl. Check out our basic string manipulation tutorial.

Image Wong Chee Yen | Dreamstime.com

©2014 About.com. All rights reserved.