Help for this page

Select Code to Download


  1. or download this
    $d1 = substr($field, 0, 2);    # 2 bytes
    $d2 = substr($field, 2, 2+2);  # 4 bytes
    $d3 = substr($field, 4, 4+6);  # 6 bytes etc.
    
  2. or download this
    my @d;
    for my $i (0 .. $length-$n) {
        $d[$i] = substr($field, $i*$n, $n)
    }
    
  3. or download this
    my @d = map{ substr $field, $_*n, $n } 0 .. ($length)/$n;
    
  4. or download this
    my @d = unpack("A$n " x $length/$n, $field);
    
  5. or download this
    my @d = $field =~ m[.{1,$n}]g;