bodacydo
bodacydo

Reputation: 79309

What is "Modern Perl"?

I have been hearing a lot about this "Modern Perl." What is it?

One of the things I heard was the new open syntax:

open my $FH, '<', $filename

and not

open FH, "<$filename";

What else is in Modern Perl?

Upvotes: 13

Views: 3933

Answers (4)

Josh Kelley
Josh Kelley

Reputation: 58352

To add some specifics to deinst's overview, Modern Perl:

  • uses Perl 5.10's new features, like switch statements (given / when) and say
  • follows good Perl programming practices, like use strict and use warnings
  • may use the Modern::Perl CPAN module to streamline all of this
  • uses Moose for writing high-level OO code

Upvotes: 12

jjpcondor
jjpcondor

Reputation: 1416

In order to be specific to your question related to opening a file handle in modern Perl: You should use the three-argument form, instead two-argument form!

Use the three-argument form of open to specify I/O layers (also called "disciplines") to apply to the handle. It affects how read-write is processed (see http://perldoc.perl.org/functions/open.html for more details). For example:

open(my $fh, "<:encoding(UTF-8)", "filename")
|| die "can't open UTF-8 encoded filename: $!";

Upvotes: 1

ysth
ysth

Reputation: 98388

Modern Perl isn't a proper noun; it's just something people might say to refer to Perl code that uses features only available in the last X years, where X will vary from person to person.

For information about various changes to Perl, see the perldelta files, for instance at http://perldoc.perl.org/index-history.html.

Upvotes: 2

deinst
deinst

Reputation: 18782

To quote the source

Modern Perl programming, circa 2010, relies on the collected wisdom of the entire Perl ecosystem. It's time to write elegant, reliable, maintainable, well-tested, and predictable code.

See also, the book. And this quote from the book

Modern Perl is a loose description of how experienced and effective Perl 5 programers work. They use language idioms. They take advantage of the CPAN. They're recognizably Perlish, and they show good taste and craftsmanship and a full understanding of Perl.

Upvotes: 13

Related Questions