If I understand correctly, when I assign values to an array
of strings with < ... >
, I should escape special symbols with \
:
> my @array = < \\ a b>
[\ a b]
> my @array = < \< a b>
[< a b]
> my @array = < \<de\< a b>
[<de< a b]
Using backslashes is not always convenient, sometimes the code may become obscure.
Is there a better way to pass a list of strings containing special characters to an array?
Elements can either be a number, string, or any type of scalar data including another variable. Array Creation: In Perl programming every array variable is declared using “@” sign before the variable’s name. A single array can also store elements of multiple datatypes.
Perl - Arrays. An array is a variable that stores an ordered list of scalar values. Array variables are preceded by an "at" (@) sign. To refer to a single element of an array, you will use the dollar sign ($) with the variable name followed by the index of the element in square brackets. Here is a simple example of using the array variables −.
Introduction to Perl strings. In Perl, a string is a sequence of characters surrounded by some kinds of quotation marks. A string can contain ASCII, UNICODE and escape sequences characters such as \n.. A Perl string has the length that depends on the amount of memory in your system, which is theoretically unlimited.
Perl provides numerous special variables, which have their predefined meaning. We have a special variable, which is written as $ [. This special variable is a scalar containing the first index of all arrays. Because Perl arrays have zero-based indexing, $ [ will almost always be 0.
Use <<
>>
instead of <
>
, and use single quotes inside:
> my @array = << '<de<' a b>>
[<de< a b]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With