Perlcc For Perl 5.12.3 For Mac

PrevNext

This is the first part of the Perl tutorial.

So given 5.12.4 had issues on Windows too and I had to go back down to 5.12.3, I went back down to 5.12.3 on Mac as well. The style/theme issue resolved but I still see this 2 tap behavior. What's up with 5.12.x?! I don't want to step too far back. The Perl developers have released Perl 5.12.3, the latest update to Perl 5. This latest version is the result of four months of work and '2,500 lines of changes'. In the 'perldelta' notes for the release, the developers note that the built-in functions keys,values and each now work on arrays rather than just hashes, but admit this was a change introduced in Perl 5.12.0 and not documented.

In this part you will learn how to install Perl on Microsoft Windows and how to startusing it on Windows, Linux or on a Mac.

For

You'll get directions to set up your development environment, or in less grandiose words:which editor or IDE to use for writing Perl?

We will also see the standard 'Hello World' example.

You can also watch the related video.

Windows

For Windows we are going to use Strawberry Perl.

In order to get started visit the website of Strawberry Perland follow the link to download it.

Go ahead, download the exe file and install it on your system. Before doing so,please make sure you don't have any other Perl installed.

They could work together but that would require some more explanations.For now let's have one single version of Perl installed on your system.

Linux

Most Linux modern Linux distributions come with a recent version of Perl.For now we are going to use that version of Perl. For editor,you can install Padre - most Linux distribution offer it from theirofficial package management system. Otherwise you can pick any regular text editor.If you are familiar with vim or Emacs, use the one you like. OtherwiseGedit might be a good simple editor.

Apple

I believe Macs also come with Perl or you can easily install it viathe standard installation tools.

Editor and IDE

Even though it is recommended, you don't have to use the Padre IDE to write Perl code.In the next part I'll list a couple of editors and IDEs youcan use for your Perl programming. Even if you select another editorI'd recommend - for the Windows users - to install the above mentioned DWIM Perl package.

It has lots of Perl extensions bundled so it will save you a lot of time down the road.

Video

If you prefer, you can also watch theHello world with Perlvideo I uploaded to YouTube.

In that case you might also want to checkout the Beginner Perl Maven video course.

First program

Your first program will look like this:

examples/hello_world.pl

Let me explain it step-by-step.

Hello world

Once you installed DWIM Perl you can click on'Start -> All programs -> DWIM Perl -> Padre' which will open the editorwith and empty file.

Type in

As you can see statements in perl end with a semi-colon ;.The n is the sign we used to denote a newline.Strings are enclosed in double-quotes '.The print function prints to the screen.When this is executed perl will print the text and at the end it will print a newline.

Save the file as hello.pl and then you can run the code by selecting 'Run -> Run Script'You will see a separate window showing up with the output.

That's it, you wrote your first perl script.

Let's enhance it a bit.

Perl on the command line for non-Padre users

If you are not using Padre or one of the other IDEsyou won't be able to run your script from the editor itself.At least not by default. You will need to open a shell(or cmd in Windows), change to the directory where you saved the hello.plfile and type in:

perl hello.pl

That's how you can run your script on the command line.

Perlcc

say() instead of print()

Let's improve our one-line Perl script a bit:

First of all let's state the minimum version of Perl we would like to use:

Once you typed this in, you can run the script again by selecting'Run -> Run Script' or by pressing F5.That will automatically save the file before running it.

It is generally a good practice to tell what is the minimum version of perl your code requires.

In this case it also adds a few new features to perl including the say keyword.say is like print but it is shorter and itautomatically adds a newline at the end.

You can change your code like this:

We replaced print by say and remove the n from the end of the string.

The current installation you are using is probably version 5.12.3 or 5.14.Most modern Linux distributions come with version 5.10 or newer.

Unfortunately there are still places using older versions of perl.Those won't be able to use the say() keyword and might need some adjustmentsto the examples later. I'll point out when I am actually using featuresthat require version 5.10.

Safety net

In addition in every script I'd strongly recommend to make some further modifications tothe behavior of Perl. For this we add 2, so called pragmatas, that are very similar to compiler flagsin other languages:

examples/hello_world.pl

In this case the use keyword tells perl to load and enable each pragma.

strict and warnings will help you catch some common bugsin your code or sometimes even prevent you from making them in the first place.They are very handy.

User Input

Now let's improve our example by asking the user her name and includingit in the response.

examples/hello_name.pl

$name is called a scalar variable.

Variables are declared using the my keyword.(actually that's one of the requirements strict adds.)

Scalar variables always start with a $ sign.The <STDIN> is the tool to read a line from the keyboard.

Type in the above and run it by pressing F5.

It will ask for your name. Type in your name and press ENTER to let perl knowyou have finished typing in your name.

You will notice that the output is a bit broken: The comma afterthe name appears on a newline. That's because the ENTER you pressed, when typing in your name,got into the $name variable.

Getting rid of newlines

examples/hello_name_chomp.pl

It is such a common task in Perl, that there is a special function called chompto remove the trailing newlines from strings.

Conclusion

In every script you write you should always add use strict; and use warnings;as the first two statements. It is also very recommended to add use 5.010;.

Exercises

I promised exercises.

Try the following script:

examples/hello_and_world.pl

It did not show on one line. Why? How to fix it?

Exercise 2

Write a script that asks the user for two numbers, one after the other.Then prints out the sum of the two numbers.

What's next?

The next part of the tutorial is abouteditors, IDEs and development environment for Perl.

Published on 2012-08-08

If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
perl5125delta - what is new for perl v5.12.5
    • the Encode manpage has been upgraded from version 2.39 to version 2.39_01.
    • the File::Glob manpage has been upgraded from version 1.07 to version 1.07_01.
    • split() and @_

perl5125delta - what is new for perl v5.12.5

This document describes differences between the 5.12.4 release and the 5.12.5 release.

If you are upgrading from an earlier release such as 5.12.3, first read the perl5124delta manpage, which describes differences between 5.12.3 and 5.12.4.

Encode decode_xs n-byte heap-overflow (CVE-2011-2939)

A bug in Encode could, on certain inputs, cause the heap to overflow. This problem has been corrected. Bug reported by Robert Zacek.

File::Glob::bsd_glob() memory error with GLOB_ALTDIRFUNC (CVE-2011-2728).

Calling File::Glob::bsd_glob with the unsupported flag GLOB_ALTDIRFUNC would cause an access violation / segfault. A Perl program that accepts a flags value from an external source could expose itself to denial of service or arbitrary code execution attacks. There are no known exploits in the wild. The problem has been corrected by explicitly disabling all unsupported flags and setting unused function pointers to null. Bug reported by Clément Lecigne.

Mac

Heap buffer overrun in 'x' string repeat operator (CVE-2012-5195)

Poorly written perl code that allows an attacker to specify the count to perl's 'x' string repeat operator can already cause a memory exhaustion denial-of-service attack. A flaw in versions of perl before 5.15.5 can escalate that into a heap buffer overrun; coupled with versions of glibc before 2.16, it possibly allows the execution of arbitrary code.

This problem has been fixed.

There are no changes intentionally incompatible with 5.12.4. If any exist, they are bugs and reports are welcome.

Updated Modules

the B::Concise manpage no longer produces mangled output with the -tree option [perl #80632].

A regression introduced in Perl 5.8.8 has been fixed, that caused charnames::viacode(0) to return undef instead of the string ``NULL' [perl #72624].

the Encode manpage has been upgraded from version 2.39 to version 2.39_01.

See Security.

the File::Glob manpage has been upgraded from version 1.07 to version 1.07_01.

5.32.0 Documentation - Perl Language

See Security.

5.12.3

The documentation for the upper function now actually says ``upper', not ``lower'.

the Module::CoreList manpage has been updated to version 2.50_02 to add data for this release.

Perlcc - Generate Executables From Perl Programs - Metacpan.org

The the perlebcdic manpage document contains a helpful table to use in tr/// to convert between EBCDIC and Latin1/ASCII. Unfortunately, the table was the inverse of the one it describes. This has been corrected.

The section on User-Defined Case Mappings had some bad markup and unclear sentences, making parts of it unreadable. This has been rectified.

This document has been corrected to take non-ASCII platforms into account.

Platform Specific Changes

Mac OS X
There have been configuration and test fixes to make Perl build cleanly on Lion and Mountain Lion.
NetBSD
The NetBSD hints file was corrected to be compatible with NetBSD 6.*
    chop now correctly handles characters above ``x{7fffffff}' [perl #73246]. ($<,$>) = (...) stopped working properly in 5.12.0. It is supposed to make a single setreuid() call, rather than calling setruid() and seteuid() separately. Consequently it did not work properly. This has been fixed [perl #75212]. Fixed a regression of kill() when a match variable is used for the process ID to kill [perl #75812]. UNIVERSAL::VERSION no longer leaks memory. It started leaking in Perl 5.10.0. The C-level my_strftime functions no longer leaks memory. This fixes a memory leak in POSIX::strftime [perl #73520]. caller no longer leaks memory when called from the DB package if @DB::args was assigned to after the first call to caller. the Carp manpage was triggering this bug [perl #97010]. Passing to index an offset beyond the end of the string when the string is encoded internally in UTF8 no longer causes panics [perl #75898]. Syntax errors in (?{...}) blocks in regular expressions no longer cause panic messages [perl #2353]. Perl 5.10.0 introduced some faulty logic that made ``U*' in the middle of a pack template equivalent to ``U0' if the input string was empty. This has been fixed [perl #90160].

split() and @_

split() no longer modifies @_ when called in scalar or void context. In void context it now produces a ``Useless use of split' warning. This is actually a change introduced in perl 5.12.0, but it was missed from that release's the perl5120delta manpage.

Perl 5.12.5 represents approximately 17 months of development since Perl 5.12.4 and contains approximately 1,900 lines of changes across 64 files from 18 authors.

Perl continues to flourish into its third decade thanks to a vibrant community of users and developers. The following people are known to have contributed the improvements that became Perl 5.12.5:

Andy Dougherty, Chris 'BinGOs' Williams, Craig A. Berry, David Mitchell, Dominic Hargreaves, Father Chrysostomos, Florian Ragwitz, George Greer, Goro Fuji, Jesse Vincent, Karl Williamson, Leon Brocard, Nicholas Clark, Rafael Garcia-Suarez, Reini Urban, Ricardo Signes, Steve Hay, Tony Cook.

The list above is almost certainly incomplete as it is automatically generated from version control history. In particular, it does not include the names of the (very much appreciated) contributors who reported issues to the Perl bug tracker.

Many of the changes included in this version originated in the CPAN modules included in Perl's core. We're grateful to the entire CPAN community for helping Perl to flourish.

For a more complete list of all of Perl's historical contributors, please see the AUTHORS file in the Perl source distribution.

If you find what you think is a bug, you might check the articles recently posted to the comp.lang.perl.misc newsgroup and the perl bug database at http://rt.perl.org/perlbug/ . There may also be information at http://www.perl.org/ , the Perl Home Page.

If you believe you have an unreported bug, please run the perlbug program included with your release. Be sure to trim your bug down to a tiny but sufficient test case. Your bug report, along with the output of perl -V, will be sent off to perlbug@perl.org to be analysed by the Perl porting team.

If the bug you are reporting has security implications, which make it inappropriate to send to a publicly archived mailing list, then please send it to perl5-security-report@perl.org. This points to a closed subscription unarchived mailing list, which includes all the core committers, who be able to help assess the impact of issues, figure out a resolution, and help co-ordinate the release of patches to mitigate or fix the problem across all platforms on which Perl is supported. Please only use this address for security issues in the Perl core, not for modules independently distributed on CPAN.

The Changes file for an explanation of how to view exhaustive details on what changed.

The INSTALL file for how to build Perl.

The README file for general stuff.

The Artistic and Copying files for copyright information.

perl5125delta - what is new for perl v5.12.5
Perlcc For Perl 5.12.3 For Mac

Perl5100delta - What Is New For Perl 5.10.0 - Metacpan.org