Perl Tricks
Home
Learning
DBI Module
Learning
CGI Module
Building
WebApps
Learning
TK/GUI
Porting to
Windows
Creating Spreadsheets How To
Compile
Handy Regular
Expressions!
    Perl Tricks

This website is intended to be a collection of easy-to-find perl references for common implementations; such as: CGI, DBI, Web Apps, and so on. Expect these tutorials to be a basic reference for developing in these arenas, as everything can always be taken to the next level.

We're not out to do your home work, but perhaps assist you in understanding it. Email us at perl@perltricks.net.

Check out these PERL REFERENCES, if you're not sure where to start.


Random PERL One-Liner
perl -e 'for("073032076111118101032080069082076033"=~/\d{3}/g){print chr($_);}'
 
Everyday Perl 6
by Jonathan Scott Duff
 

Perl 6 will soon be here. How will programming in Perl 6 be different from programming in Perl 5 for your average Perl programmer? The answer is: very different yet very much the same. A Perl 6 program viewed at arm's length will look much like a Perl 5 program viewed at arm's length. Programming in Perl 6 will still feel like programming in Perl. What will change however, is that Perl 6 will enable programmers to be more expressive by giving them more tools to work with (making easy things easy) and allowing them to be more precise in their expressions.

While many of the changes in Perl 6 make it easier for people new to programming or coming from other programming languages to understand the language, none of the changes were made solely on those grounds. If your favorite part of Perl 5 syntax is that it uses an arrow for method dispatch on objects, don't be dismayed that Perl 6 uses a dot instead. The designers carefully considered each syntactic change to ensure that Perl 6 still has the Perlish nature and that the change was an overall improvement. Some Perl programmers delight in the syntactic differences of the language, but some of those differences aren't that important when compared to the big picture of Perl's culture (which includes the language, CPAN, and the community of programmers).

Sigil Invariance

One of the fundamental changes is that whenever you refer to individual elements of an aggregate (an array or hash), rather than changing the sigil to denote the type of thing you get back, the sigil remains the same.

For example, in both Perl 5 and Perl 6 you can create and initialize aggregates:

    my @array = (1,3,5,12,37,42);
    my %hash  = ( alpha => 4, beta => 6 );

How you access the individual elements of those aggregates looks just a little different:

    # Perl 6                            # Perl 5
    my $third = @array[2];              my $third = $array[2];
    my $beta  = %hash{'beta'};          my $beta = $hash{'beta'};

Long-time Perl 5 programmers might wonder how slices work in Perl 6. The answer is: the same way as in Perl 5.

    my @odds = @array[1,3,5];           # array slice
    my @bets = %hash{'alpha','beta'};   # hash slice

The only difference is that in Perl 5 the hash slice would have started with a @ sigil.

New Brackets

In these hash examples, it's awkward quoting the indexes into the hash. Perl 5 allows a syntactic shortcut where $hash{word} works as if you had written $hash{'word'}. A problem with that is that it can cause confusion when your word happens to be the name of a subroutine and you really want Perl to execute that subroutine.

In Perl 6, a syntactic shortcut for accessing hash elements takes advantage of a name change of the "quote word" operator:

    # Perl 6                        # Perl 5
    my @array = <foo bar baz>;      my @array = qw(foo bar baz);
    my %hash  = <a b c d e f g h>;  my %hash = qw(a b c d e f g h);
    my $queue = %hash<q>;           my $queue = $hash{'q'};
    my @vows  = %hash<c a g e>;     my @vows = @hash{qw(c a g e)};

Also, just as double-quoted strings interpolate while single-quoted strings do not, double-bracketed "quote word" constructs also interpolate:

    my $foo  = "This is";
    my $bar  = "the end";
    my @blah = << $foo $bar >>;     # ('This','is','the','end');

Note that the interpolation happens before the "quote word" aspect of this operator.

Speaking of interpolation, interpolating into double-quoted strings has changed slightly. Now to interpolate an array into a string, you must provide a set of empty brackets at the end of the array name. This has the side benefit of eliminating the ambiguity of whether you meant interpolation if you happen to include (for instance) an email address in your double-quoted string.

    my @items = <names addresses email>;
    say "Send @items[] to test@foo.com";
    # Send names addresses email to test@foo.com

You can also interpolate more things into your double-quoted strings:

    say "Send me $person.name()";         # results of a method call
    say "2 + 2 = { 2+2 }";                # any bit of perl code

That second one means that you'll have to be careful about inserting curly braces in your double-quoted strings, but that's a small price to pay for the ability to interpolate the results of arbitrary Perl code.

By the way, get used to the say subroutine. It's the same as print, but it appends a newline to the end. Quite useful, that.

Fewer Parentheses

The usual places in Perl 5 that require parentheses no longer do in Perl 6:

    # Perl 6                        # Perl 5
        if $cond  { ... }                if ($cond)  { ... }
    unless $cond  { ... }            unless ($cond)  { ... }
     while $cond  { ... }             while ($cond)  { ... }
       for @array { ... }               for (@array) { ... }

In Perl 6, parentheses are now only necessary for grouping.

 

How to Use the Frame Blocking Facility (Anti-Clickjacking Defence) in Internet Explorer 8

Internet Explorer 8 gives webmasters a new way to protect their site from being placed in a frame, and thus, hopefully, prevent clickjacking from taking place. This article shows you how you can configure your website so that it takes advantage of IE 8's new feature.

How to Add Images to Your Website in Serif WebPlus X2

The second chapter of the Serif WebPlus X2 Tutorial is now online. This chapter deals with how you can add things like your website's logo, photos, product images, background images and so on to your web page. It also introduces the concept of a stacking order to the objects on your web page.

(For those who don't know, Serif WebPlus X2 is a point-and-click visual web editor that you can use to create a website.)

How to Add a CAPTCHA Test to Your Feedback Form Script: Reducing Spam in Your Contact Form

Is your mail box filled with spam sent by automated computer programs dumping junk into your feedback form? Are you tired of having to wade through tons of ridiculous body enhancement suggestions replete with grammatical errors before arriving at your real email? This article shows you how you can add a CAPTCHA facility to your feedback form in an easy-to-do way, to hopefully reduce the spam arriving through your contact form.

Note that this article is intended for the ordinary, non-technical webmaster, and can be implemented by anyone.

[Updated] Free Feedback Form Script Wizard: New Features Added

The Feedback Form Script Wizard has been updated to add the following features to the feedback form it creates:

  • The PHP feedback form script created by the wizard can now, at your option, check to make sure that the comments/message field is not empty before submitting its contents. (Note: this is not exactly a new feature since it was present in older versions of the script but was removed in recent versions. By popular request, the facility has now been restored to the script.)

  • You can now make the wizard use either XHTML or HTML for the form code. If you don't know what to use, just leave it at the default.

If you don't need the new features, you don't have to upgrade. As always, the script is free.

How to Point a Domain Name to Your Website (Or What to Do After Buying Your Domain Name)

So you've bought your own domain name. What do you do next? How do you point a domain name at your website or your web hosting account? This article answers that question.

What Does It Mean to Park a Domain Name? Domain Name Parking Explained.

In response to a query, this article explains what it means to park a domain name. It also covers situations where you may want to park a domain name, and discusses why you may not want use your domain name registrar's parking services.

Serif WebPlus X2 Tutorial: How to Design Your Website with Serif WebPlus X2

At the request of a number of visitors, I've now begun a new tutorial series. Serif WebPlus X2 is a site builder and WYSIWYG web editor that allows you to simply drag and drop elements onto a page to create a website. This tutorial will guide you through the steps of building a complete, fully-functional, multi-page website using the web editor.

Why Am I Still Seeing My Web Host's Default Page or a File Not Found Error Page After I've Published My Website?

This article attempts to address a problem where some webmasters publish their new websites using a web editor or an FTP program, only to find when they visit their website, that their web browsers still show them their web host's default web page or an error page. It provides a checklist of things to do in such a situation.

Is it Possible to Use Microsoft Word or Office to Create a Website? If So, How?

In response to a visitor's question on whether he can create a website using Microsoft Word, I have written a guide on how to create a website using MS Word/Office along with information about the problems you will face if you do so.

How to Move Your Website from GeoCities: Closure of GeoCities' Free Web Hosting

The venerable GeoCities, born in the early days of the Internet, is closing. If your website is currently hosted there, you should start moving it to another web host, free or otherwise. Since there are many things to attend to when moving a website, this tutorial gives you a step-by-step guide on how you can move the site from GeoCities so as to preserve (as much as possible) your search engine position as well as your visitors. Don't wait too long to get started. Some things, such as getting the search engines to recognize your new website, take a lot of time to resolve.

 
Omg! Positive tone boosts Yahoo celeb site to top (AP)
AP - Think of the most popular brands in celebrity news, and you'll probably come up with a small list that includes Entertainment Tonight, US Weekly and People.
BT offers staff time off in exchange for pay cut (AP)
AP - Telecoms company BT Group PLC is offering staff a year off work in return for a 75 percent cut in that year's pay.
US wants privacy in new cyber security system (AP)

US Homeland Security Secretary Janet Napolitano speaks to journalists after signing an agreement with the Portuguese government on the fight against crime and terrorism, Tuesday, June 30 2009, at the Necessidades Palace, the Portuguese foreign ministry, in Lisbon. (AP Photo/Armando Franca)AP - The Obama administration is moving cautiously on a new pilot program that would both detect and stop cyber attacks against government computers, while trying to ensure citizen privacy protections.


Web retailers, states tussle over tax rules (AP)
AP - In a big break for online shoppers, Web retailers generally don't have to charge sales taxes in states where they lack a store or some other physical presence.
Companies pledge more openness about Web tracking (AP)
AP - Companies that track consumer behavior online for advertising purposes are vowing to make their practices more transparent and to give people a way to decline being shadowed.
PC makers voluntarily supply Web filter in China (AP)

Children use computers in a library in Xiangfan in central China's Hubei province Wednesday July 1, 2009.  In a rare reversal, China's government gave in to domestic and international pressure and backed down from a rule that would have required personal computers sold in the country to have Internet-filtering software.  Just hours before the rule was to have taken effect Wednesday, the government said it would postpone the requirement for the 'Green Dam' software. (AP Photo)AP - Several PC makers were including controversial Internet-filtering software with computers shipped in China on Thursday despite a government decision to postpone its plan to make such a step mandatory.


Obama, McCain give dueling holiday addresses (AP)

President Barack Obama and first lady Michelle Obama, walk back to their limousine after greeting a crowd at Fort Lesley J. McNair, Saturday, July 4, 2009, in Washington.   (AP Photo/Manuel Balce Ceneta)AP - In dueling holiday addresses, President Barack Obama appealed for public support of his domestic programs and Sen. John McCain said Americans should side with Iranian election protesters.


Ericsson announces broadband contracts in China (AFP)

Swedish mobile phone network supplier Ericsson won contracts to supply broadband Internet to millions of users in China by a deal with three operators there.(Ericsson/File)AFP - Swedish mobile phone network supplier Ericsson won contracts to supply broadband Internet to millions of users in China by a deal with three operators there, it said Friday.


Bluetooth "Big Brother" tracks festival-goers (Reuters)
Reuters - Researchers are using Bluetooth technology to observe the meanderings of tens of thousands of festival-goers at a top European rock festival, hoping their findings will launch a new generation of tracking devices.
Michael Jackson sales surge expected to last months (Reuters)
Reuters - In the days following Michael Jackson's June 25 death, fans flocked to record stores and digital music outlets to purchase one last memory. And merchants say they expect the Jackson sales surge to last for weeks -- maybe even months.
"Asteroids" lands at Universal (Reuters)
Reuters - Universal Pictures has won a four-studio bidding war to pick up the film rights to the classic Atari video game "Asteroids."
IPhone 3GS Heats Up, DOJ Takes Aim at Google (PC World)
PC World - The iPhone scored quite a few headlines related to overheating problems with the 3GS this week. Depending on whom you believe, those issues are either real, exaggerated, the fault of users or some combination of the three. Otherwise, as warm weather takes hold above the equator and Bostonians contemplate whether it's time to brush up on our ark-building skills (rain, rain go away), we find this week's IT news offerings cover a broad range.
China Testing Mac Version of Green Dam Web Filter (NewsFactor)
NewsFactor - Despite the delay in China's requirement to install Green Dam Web-filtering software on all new PCs, the controversy is not dead. PC makers are including the software with new PCs even though the July 1 deadline has been postponed indefinitely.
SAP Benchmarking Program Begins Tracking First KPIs (PC World)
PC World - SAP users have begun measuring the performance of key aspects of their ERP (enterprise resource planning) systems as part of a benchmarking process agreed to with user groups. In April, SAP agreed to delay an increase in the cost of its Enterprise Support service, and to make future increases conditional on meeting certain targets for performance and customer satisfaction.
You don't know tech: The InfoWorld news quiz (InfoWorld)
InfoWorld - You win some; you lose some. This week China decided its Web censorship filtering software was not quite ready for prime time, while U.S. courts sentenced phone hackers and file swappers to some crime time.
'BugDay' Planned To Fix Bugs in New Firefox 3.5 (NewsFactor)
NewsFactor - Mozilla is scrambling to fix bugs in its just-released Firefox 3.5 browser. Users are posting complaints about problems across the Web.
Teen Releases First Jailbreak App for iPhone 3GS (NewsFactor)
NewsFactor - The first jailbreak application for Apple's new iPhone 3GS has been made available just two weeks after the iPhone debuted. George Hotz, a 19-year-old Google employee originally from New Jersey, created the application.
 
PERLTRICKS.NET © 2007
Privacy PolicyTerms Of UseAbout UsSite MapContact Us