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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: [perlre] grouping parenthesis capture whole string instead of proper subset... why?
by lestrrat (Deacon) on Oct 25, 2002 at 21:28 UTC
    if($setstr =~ /(.*)\|\|$/) { ... }

    works for me ;)

Re: [perlre] grouping parenthesis capture whole string instead of proper subset... why?
by Tanalis (Curate) on Oct 25, 2002 at 21:29 UTC
    | is used by Perl to mean OR - you probably need to escape it, like this:

    $setstr =~ /(.*)\|\|$/

    If you always want to remove two pipes from the end of a line, you could also use the substitute function:

    $setstr =~ s/\|\|$//;

    Hope this helps
    --Foxcub

Re: [perlre] grouping parenthesis capture whole string instead of proper subset... why?
by VSarkiss (Monsignor) on Oct 25, 2002 at 21:32 UTC

    lestrat's answer is correct, but you can also do: $setstr =~ s/\|\|$//;if your sole intent is to remove two vertical bar characters at the end.

Re: [perlre] grouping parenthesis capture whole string instead of proper subset... why?
by robartes (Priest) on Oct 25, 2002 at 21:31 UTC
    Pipes are special in regexpen, therefore you need to escape them, for example using the \Q trick:
    use strict; my $string="altcategory=||"; $string =~ /(.*)\Q||\E$/; print $1;
    or by introducing leaning toothpick (or cross-eyed plumbing in the case of pipes) syndrome:
    $string=~/(.*)\|\|$/;

    CU
    Robartes-

Re: [perlre] grouping parenthesis capture whole string instead of proper subset... why?
by DaveH (Monk) on Oct 27, 2002 at 18:39 UTC

    You could make use of chomp and Perl's "Input Record Separator":

    my $setstr = 'altcategory=||'; warn $setstr; { $/='||'; chomp $setstr } warn $setstr;

    Cheers,

    -- Dave :-)