September 2017
Beginner
402 pages
9h 52m
English
\t and \T match with tab characters and non-tab characters, respectively. Imagine that you have a line of tab-separated data and you want to put it into an array. The following code will do it for you:
my $data = "John\tSmith\t1970";my @data = $data.split(/\t/);print qq:to/OUT/Name = @data[0]Last name = @data[1]Year of birth = @data[2]OUT
Here, we call the split method on the $data string and pass it a regex containing a single \t character class, which should match with a tab character. Thus, it will split the source line into three parts and put them into the @data array.
The qq:to/OUT/ construction is the start of the heredoc, which ends at the second occurrence of the label OUT. A double qq requires variable interpolation ...
Read now
Unlock full access