BudiBadu Logo
Samplebadu
Perl

Learn Perl by Examples

Perl 5

Perl is a highly capable, feature-rich programming language with over 30 years of development. It is especially strong in text processing and system administration tasks.

These examples cover the core concepts of Perl, from its unique variable types (scalars, arrays, hashes) to its powerful regular expressions and module system.

Scalars

Working with single values through this sample code demonstrating scalar variable declaration with dollar sign sigil, automatic type conversion between strings and numbers, string interpolation in double quotes, and undefined value handling.

Arrays

Managing ordered lists of scalars with this code example showing array declaration with @ sigil, element access using $ sigil for single values, stack and queue operations with push/pop/shift/unshift, and array slicing with range operator.

Hashes

Storing key-value pairs with this sample code demonstrating hash declaration with % sigil, fat comma operator for initialization, element access with curly braces, hash iteration using each function, and keys/values extraction.

Regular Expressions

Pattern matching and text manipulation with this code example demonstrating binding operator for regex application, match operator with modifiers, substitution operator for replacement, capture groups with automatic variables, and metacharacter usage.

Subroutines

Creating reusable code blocks with this sample code demonstrating subroutine definition with sub keyword, argument access via @_ array, parameter unpacking with my, return value behavior, and variable argument handling.

References

Building complex data structures with this code example demonstrating reference creation using backslash operator, anonymous array and hash references with brackets and braces, arrow operator for dereferencing, and nested structure navigation.

Modules

Organizing and reusing code with this sample code demonstrating module loading with use statement, core module functionality, CPAN ecosystem access, namespace management with packages, and Data::Dumper for structure visualization.

File I/O

Reading and writing files with this code example demonstrating file handle creation with open function, mode specification for read/write/append, diamond operator for line reading, chomp for newline removal, and error handling with die.