sweepy838 has asked for the wisdom of the Perl Monks concerning the following question:

$input = "xxxx aaaa bbbbb"; ($txt) = $input =~ /\S{5}(.+)(?{length($input);})/; chomp; print $txt;
output should be "aaaa bbbbb" with no space at the beginning, but i get the space, and i know it has something to do with the \S that means any non-space character.. but it doesnt work without it either. help? thanks again, i am trying :p

Original content restored above by GrandFather

edit: jeez it's always after i post that i find the problem, replace the \S with a dot.. problem solved

Replies are listed 'Best First'.
Re: regex problem (again)
by JavaFan (Canon) on Apr 30, 2012 at 06:22 UTC
    Use /\S{4}\s(.+)/. I don't understand the (?{length($input);}) part -- it will always true unless $input is the empty string.

    BTW, the regexp as given did not match, so $txt did not start with a space.

      Hi sweepy, Just replace S (upper case) with s (lower case)
      $input = "xxxx aaaa bbbbb"; ($txt) = $input =~ /\s{5}(.+)(?{length($input);})/; chomp; print $txt;
      This is working!
        No, it's not:
        my $input = "xxxx aaaa bbbbb"; my ($txt) = $input =~ /\s{5}(.+)(?{length($input);})/; print $txt, "\n"; __END__ Use of uninitialized value $txt in print at ?? line ??.