Perl file test operators (reference)

This document provides a list of the most commonly-used Perl file test operators.

Operators to determine whether a file or directory exists

Here are the most common Perl file test operators that can be used to determine whether a file or directory exists:

-e  File or directory name exists
-z  File exists and has zero size
-s  File or directory exists and has non-zero size

All of those tests can be executed as shown in the following source code example:

How to exclude certain elements in an array with pattern matching

Problem: You have an array of elements, and you need to process every element in the array, except the elements that match a given regular expression (pattern).

Solution: You can solve this problem using a combination of the Perl regular expression pattern matching, along with the next operator.

Ruby “execute shell command” examples

Ruby exec FAQ: How do I execute a shell command from a Ruby script?

It's very easy to execute an external shell command from a Ruby script. Off the top of my head there are at least two ways to do this. First, you can use the traditional backtick operators. Second, you can use the %x syntax. I'll demonstrate both examples here.

Use the backtick operator

First, I'll use the backtick operator to execute a shell command. Here's how you can run a simple command, like the ls command, using Ruby and the backtick operator:

How to get help on Windows/DOS commands

Okay, this is one small step for me, and not really any steps for mankind ... I never know how to get help on Windows/DOS commands. I try command line options/switches like -h, -help, --help, /help, and \help, and of course none of them works.

Then somehow today I learned that the magic incantation, er, command line option, is /?, like this:

taskkill /?



Perl ‘equals’ FAQ: What is true and false in Perl?

Perl true/false FAQ: What is true in Perl? What is false in Perl?

The Perl programming language is a little unusual in not having true and false boolean operators. Because of this, I can never seem to remember what equates to true and false in Perl, so I decided to create this page.

What is true/false in Perl

In short, the following elements evalue to false in Perl:

The Java ternary operator examples

Summary: This tutorial shares examples of the Java ternary operator syntax.

Interested in saying a lot while writing a little? In a single line of code, the Java ternary operator let's you assign a value to a variable based on a boolean expression (either a boolean field, or a statement that evaluates to a boolean result).

At its most basic, the ternary operator (also known as the conditional operator) can be used as an alternative to the Java if/then/else syntax, but it goes beyond that, and can even be used on the right hand side of Java statements.

Perl “exec”: How to execute system commands

Summary: Using the Perl backtick operator to execute system comands

One of the real strengths of the Perl programming language is the ease in which you can access (execute) the commands of the underlying operating system. As other programming languages point out, this can be considered a weakness, because it also makes your programs system-dependent, but in reality I've found this to be a problem only five or 10 percent of the time.