Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Special symbols as elements of strings array in Perl 6

Tags:

raku

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?

like image 370
Eugene Barsky Avatar asked Oct 29 '17 12:10

Eugene Barsky


People also ask

What is an array element in Perl?

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.

How to use array variables in Perl?

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 −.

What is a string in Perl?

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.

What is a special variable in Perl?

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.


1 Answers

Use << >> instead of < >, and use single quotes inside:

> my @array = << '<de<' a b>>
[<de< a b]
like image 70
Elizabeth Mattijsen Avatar answered Sep 18 '22 13:09

Elizabeth Mattijsen