1

I have a string that I need to split into three-character chunks. Googling found the following code, which works fine:

$input = "DEADBEEF";
@output = ();
my @output = ( $input =~ m/.{3}/g );
print $_."\n" foreach (@output);

I am a Perl beginner; can someone explain to me what the expression $input =~ m/.{3}/g does?

darch
  • 4,200
  • 1
  • 20
  • 23
I am
  • 1,057
  • 5
  • 14
  • 21

1 Answers1

6
$input - scalar variable
=~     - apply regular expression
m      - Match (in list context so return a list of matched substrings)
/      - start of expression
.      - any character
{3}    - 3 times
/      - end of expression
g      - globally
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335