Call: (480) 382-8464

Perl Shorthand If Clause

Perl has a ton of short hand features. One that a lot of non-beginners use, and that I forget frequently, is the perl short hand if clause. This tutorial will show you how to use the shorthand if clause in perl:

Perl “IF” Clause, Normally…

Typically if you want to do an if statement in perl, you would do something like this:


my $data;

if($form->{somefield}){
  $data = $form->{somefield};
}else{
  $data = 1;
}

print $data;

Perl Shorthand “IF” Clause

But, if you wanted to do the shorthand version of the if statement, here is how you would code it:


my $data = $form->{somefield} ? $form->{somefield} : 1;
print $data;

Another Example of Using the Shorthand Perl IF Clause:


print $form->{somefield} ? $form->{somefield} : 1;

Both examples will either use the data that is in the $hash{value} container, or it will use the number 1 if the hash{value} is empty.

Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Main Offers/Services

Hosting and website related services offered by Digital Crunch:



Managed VPS Hosting

Server Updates, Module/Software Installs, Firewall, Security, Hosting Management, Wordpress - let us manage it for you

Hosted Email

Setup and Maintain Business Class, Secure Email Hosting including spam protection and 25GB of storage space

Linux Consulting

Server Updates, Module/Software Installs, Firewall, Security, Hosting, Wordpress and Apps, anything related to Linux

Managed Newsletters

We broadcast your content to your list, capture leads for you, follow up on schedules, make more sales for you

Website Maintenance

Content updates, menu changes, graphics changes, adding content, getting links, building traffic, building sales funnels

Hosting Tutorials

Tutorials we've written for other customers that like to get their hands dirty and learn about hosting