Perl
cotrTypesString
Perl String Type
# Perl uses scalars for strings.
cotrInterpolate
Perl Interpolate String
"Your string here $${1:variable}"
cotrPrintMulti
Perl Print Multi
print <<'END_STRING';${1:Line 1}${2:Line 2}${3:Line 3}END_STRING
cotrTryCatch
Perl Try Catch
eval { # Your code here};if ($@) { # Your code here}
cotrClass
Perl Class
package ${1:MyClass};
# Your code here
cotrComment
Perl Comment
# ${1:Your comment here}
cotrOperatorsBool
Perl Boolean Operators
# Perl Boolean Operators# Logical AND: && or and# Logical OR: || or or# Logical NOT: ! or not# Equality: ==# Inequality: !=# Greater than: ># Less than: <# Greater than or equal to: >=# Less than or equal to: <=
cotrTypeCheck
Perl Type Check
ref ${1:variable}
cotrTypesDynamic
Perl Dynamic Type
# Perl is a dynamically typed language.
cotrFuncArrow
Perl Arrow Function
${2:my_function} = ->(${3:parameters}) { ${4:# Your code here}}
cotrTypesMap
Perl Map Type
%hash
cotrPrint
Perl Print
print '${1:Your message here}\n';
cotrEnum
Perl Enum
# Perl does not have a built-in enum type. Use a list or hash instead.
cotrGenList
Perl Generate List
my @${1:listName} = (${2:initialValue}) x ${3:length};
cotrFuncAnon
Perl Anonymous Function
lambda { |${1:parameters}| # Your code here}
cotrNotEqual
Perl Not Equal To
!=
cotrTypesDate
Perl Date Type
use DateTime
cotrVar
Perl Create Variable
my $${1:myVar} = $2;
cotrWhileLoop
Perl While Loop
while (${1:condition}) { # Your code here}
cotrFunc
Perl Function
sub ${2:myFunction} { my (${3:parameters}) = @_;
${4:# Your code here}}
cotrInfo
Perl Info
# Typing: Dynamically typed# Paradigm: Multi-paradigm: procedural, object-oriented, scripting# Compilation: Interpreted# Concurrency: Supports multi-threading with the threads module
cotrTypeCompare
Perl Type Comparison
# Check if two variables have the same type:if (ref ${1:variable1} eq ref ${2:variable2}) { # Your code here}
cotrVarNullable
Perl Create Nullable Variable
my $${1:myVar}; # Variable can be undefined (undef).
cotrVarStatic
Perl Static Variable
our $${1:myStaticVar} = ${2:value};
# Perl does not have static variables in the traditional sense.# Access the package variable# $${1:myStaticVar}
cotrCommentMulti
Perl Multi-Line Comment
=begin${1:Your comment here}=end
cotrOperators
Perl Mathematical Operators
# Perl Mathematical Operators# Addition: +# Subtraction: -# Multiplication: *# Division: /# Modulus (Remainder): %# Exponentiation: **# Increment: Use += 1# Decrement: Use -= 1# Assignment: =# Addition assignment: +=# Subtraction assignment: -=# Multiplication assignment: *=# Division assignment: /=# Modulus assignment: %=# Exponentiation assignment: **=
cotrVarInt
Perl Create Integer Variable
my $${1:myInt} = ${2:0};
cotrSwitch
Perl Case Statement
case ${1:variable} {when ${2:value1} # Your code herewhen ${4:value2} # Your code hereelse # Your code here}
cotrFuncArgsNamed
Perl Named Arguments (Alternative)
# Perl does not have named arguments in the traditional sense.# You can use record syntax or higher-order functions to achieve similar functionality.
cotrEntry
Perl Entry Point
# Perl Entry Point# To run this program, use: `perl filename.pl`
use strict;use warnings;
print "Hello, World!\n";
cotrTypesList
Perl List Type
@array
cotrForLoop
Perl For Loop
for (my $${1:i} = 0; $1 < ${2:10}; $1++) { # Your code here}
cotrVarSyntax
Perl Variable Declaration Syntax
# Perl Variable Declaration Syntax:
# - my: (Scope: Block)# - Declares a lexically scoped variable.# - Preferred for most variable declarations.
# - our: (Scope: Package)# - Declares a package-scoped variable.# - Use for variables that need to be shared across the package.
# - local: (Scope: Block)# - Declares a dynamically scoped variable.# - Use with caution due to potential scoping issues.
# Note:# - Use 'my' for most variable declarations.# - Use 'our' for package-level variables.# - Avoid using 'local' unless you have a specific reason.
cotrVarString
Perl Create String Variable
my $${1:myString} = "${2:Your string here}";
cotrVarStringMulti
Perl Create Multi-Line String Variable
my $${1:myString} = <<'END_STRING';${2:Line 1}${3:Line 2}${4:Line 3}END_STRING
cotrVarDate
Perl Create Date Variable
my $${1:myDate} = DateTime->new( year => ${2:year}, month => ${3:month}, day => ${4:day} );
cotrIf
Perl If Statement
if (${1:condition}) { # Your code here}
cotrEqual
Perl Equal To
==
cotrTypesNum
Perl Double Type
# Perl uses scalars for floating-point numbers.
cotrTypesNull
Perl Null Type
undef
cotrVarTyped
Perl Create Typed Variable
# Note: Perl is dynamically typed; explicit type annotations are not used.my $${1:myVar} = $2;
cotrVarMap
Perl Create Hash Variable
my %${1:myHash} = (${2:key} => ${3:value});
cotrIfElse
Perl If Else Statement
if (${1:condition}) { # Your code here} else { # Your code here}
cotrStructure
Perl Project Structure (High-Level)
# Recommended High-Level Perl Project Structure:
# - lib/# - Contains Perl module files (`.pm`).# - Organize modules into directories, mirroring the module's namespace.
# - bin/# - Contains executable Perl scripts.
# - t/# - Contains test scripts written using Perl's testing frameworks (like Test::More).
# - docs/# - Documentation for the project.
# - scripts/# - Contains utility scripts that are not part of the main application logic.
# - data/# - Contains data files used by the application.
# Note:# - This structure is flexible and can be adjusted based on the project's requirements.# - Ensure that the `lib` directory is included in the `@INC` array or use the `use lib`# directive in scripts to include the library path.
cotrTypes
Perl Types
$BLOCK_COMMENT_STARTPerl is a dynamically typed language.
Some common types in Perl include:- Scalar: Single value (numbers, strings, references)- Array: Ordered list of scalars- Hash: Unordered collection of key-value pairs- Code: Subroutine reference- Filehandle: File handle- Regexp: Regular expression- undef: Represents an undefined value$BLOCK_COMMENT_END
cotrTypesBoolTrue
Perl Boolean True
1
cotrVarBool
Perl Create Boolean Variable
my $${1:myBool} = ${2:1};
cotrConst
Perl Create Constant
use constant ${1:MY_CONST} => $2;
cotrTypesInt
Perl Integer Type
# Perl uses scalars for integers.
cotrTypesBool
Perl Boolean Type
# Perl uses 1 and 0 for boolean values.
cotrTypesBoolFalse
Perl Boolean False
0
cotrFuncSyntax
Perl Function Syntax
# Perl Function Syntax# Basic function:# sub functionName {# my ($parameters) = @_;# # Your code here# }
# Function with arguments:# sub functionName {# my ($arg1, $arg2, ...) = @_;# # Your code here# }
cotrFuncArgs
Perl Function Args
# In Perl, you can use default arguments in function definitions.sub ${2:myFunction} { my (${3:$arg1}, ${4:$arg2} = ${5:'defaultVal'}) = @_;
${6:# Your code here}}
cotrGenMap
Perl Generate Map
# Perl does not have a built-in way to generate a map (hash) with a specific number of key-value pairs.# You can use a loop or a custom function to achieve this.
cotrTernary
Perl Ternary Operator
${1:condition} ? ${2:trueValue} : ${3:falseValue}
cotrThrow
Perl Throw Exception
die '${1:Your message here}';
cotrNow
Perl Date Now
use DateTime
DateTime->now
cotrConcat
Perl Concatenate Strings
"${1:string1}" . "${2:string2}"
cotrVarNum
Perl Create Float Variable
my $${1:myFloat} = ${2:0.0};
cotrVarList
Perl Create Array Variable
my @${1:myArray} = (${2:items});
cotrForEach
Perl For Each Loop
foreach my $${1:item} (@${2:iterable}) { # Your code here}
cotrTypeConvert
Perl Type Conversion
# Perl Type Conversion:
# Implicit conversions (Perl performs automatically):# - Can be unpredictable, especially with loose equality (==).
# Explicit conversions:# - int(variable) // Converts to integer# - 0 + variable // Converts to number# - "" . variable // Converts to string
# Note:# - Be aware of implicit conversions and use explicit conversions when necessary for clarity and control.