You are certain to use $pos later in your code; *how* do you use it? Consider looking past the elegance of a single line, toward the elegant interplay within the *paragraph* of code. Your need for a separate $pos variable might even vanish, leaving a Zen-like elegance by its absence.
Some late-night thoughts:
# 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;
# Get all the positions my @positions; push @positions, pos($str)-1 while $str =~ m{\*}g; # Yields ( 4, 12 );
# Get all the asterisk-separated pieces my @pieces = split "\*", $str; my $pos = length $pieces[0];
# Just get the first piece my ( $first_piece ) = ( $str =~ m{ \A ( [^*]* ) }x ); my $pos = length $first_piece;
In reply to Re: Finding location
by Util
in thread Finding location
by uvnew
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |