Help for this page

Select Code to Download


  1. or download this
    # One-liners; different than the other Monks, but not better.
    my $pos = length( (split /\*/, $str)[0] );
    my $pos = ( $str =~ m{ \A ( [^*]+ ) }x ) ? length($1) : 0;
    
  2. or download this
    # Get all the positions
    my @positions;
    push @positions, pos($str)-1 while $str =~ m{\*}g;
    # Yields ( 4, 12 );
    
  3. or download this
    # Get all the asterisk-separated pieces
    my @pieces = split "\*", $str;
    my $pos = length $pieces[0];
    
  4. or download this
    # Just get the first piece
    my ( $first_piece ) = ( $str =~ m{ \A ( [^*]* ) }x );
    my $pos = length $first_piece;