Help for this page

Select Code to Download


  1. or download this
    my $string = "1234567890abcdefghijABCDEFGHIJK";
    my $chars;
    my $n = 2;
    
  2. or download this
    $chars = substr( $string, 0, $n );
    substr( $string, 0, $n ) = "";
    
  3. or download this
    ( $chars, $string ) = ( substr($string,0,$n), substr($string,$n) );
    
  4. or download this
    $chars = substr ($string, 0, $n, "");
    
  5. or download this
    $string = s/^(.{$n})(.*)$/$2/s;
    $chars = $1;
    
  6. or download this
    ($chars, $string) = split /^(.{$n})/, $string, 1;
    
  7. or download this
    ($chars, $string) = $string =~ /^(.{$n})(.*)$/s;
    
  8. or download this
    ( $chars, $string ) = unpack "a$n a@{[length($string)-$n]}", $string;