# Source: https://docs.datadoghq.com/security/code_security/static_analysis/static_analysis_rules/ruby-code-style/no-cryptic-perlisms.md

---
title: Avoid using Perl-style special variables
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Avoid using Perl-style special variables
---

# Avoid using Perl-style special variables

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site). ().
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `ruby-code-style/no-cryptic-perlisms`

**Language:** Ruby

**Severity:** Notice

**Category:** Code Style

## Description{% #description %}

The rule 'Avoid using Perl-style special variables' is important for improving the readability and maintainability of your code. Perl-style special variables, such as `$0`, `$1`, and `$_`, while powerful, can make your code less readable and harder to understand, especially for developers unfamiliar with Perl or its influence on Ruby. They can also introduce subtle bugs due to their global nature and the special behavior associated with them.

To avoid violating this rule, you can use the more descriptive aliases provided by the `English` library. This library, which is part of Ruby's standard library, provides human-readable names for Perl-style special variables. For example, instead of using `$&` to get the string matched by the last successful pattern match, you can use `$MATCH`.

Here's a compliant code example: Instead of `$_`, you can use `$LAST_READ_LINE`. Instead of `$!`, use `$ERROR_INFO`. This makes your code more self-explanatory and reduces the potential for confusion. Example:

```ruby
require 'English'
puts $LAST_READ_LINE
puts $ERROR_INFO
```

This practice significantly enhances the readability of your code and makes it more accessible to developers who are not familiar with Perl-style variables.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```ruby
$! = ' -- '
$@ = ' -- '
$; = ' -- '
$, = ' -- '
$/ = ' -- '
$\ = ' -- '
$. = ' -- '
$_ = ' -- '
$> = ' -- '
$< = ' -- '
$$ = ' -- '
$~ = ' -- '
$* = ' -- '
$& = ' -- '
```

## Compliant Code Examples{% #compliant-code-examples %}

```ruby
require "English"

$OUTPUT_FIELD_SEPARATOR = ' -- '
"Lorem ipsum dolor sit amet" =~ /dolor/
print $POSTMATCH, $PID, "\n"
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}