in reply to Assign multiple items into an array containing the range operator from a file
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11137734 use warnings; my $inputfile = <<END; [0..1] [2..4] 9 [5..8] END open my $fh, '<', \$inputfile or die; # FIXME to your file local $/; my @sets = map { /\[(\d+)\.\.(\d+)\]/ ? $1 .. $2 : $_ } split ' ', <$f +h>; use Data::Dump 'dd'; dd \@sets;
Outputs:
[0 .. 4, 9, 5 .. 8]
|
|---|