Information Technology Grimoire

Version .0.0.1

IT Notes from various projects because I forget, and hopefully they help you too.

shorthand if

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 emp