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

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: difference between "*." and "." operators
by svenXY (Deacon) on Oct 11, 2007 at 10:23 UTC
    Hi,
    not sure I understand what you want...
    This is how I interpret your code (pls. use code tags by the way):
    #!/usr/bin/perl use strict; use warnings; my $string = "abcABC123ABCabc"; # the following is using shell commands # to do something perl can do much better... echo `expr match "$string" 'abc[A-Z]*.2'` ; echo `expr match "$string" 'abc[A-Z]*2'` ;
    As said - not sure what your intention is.

    To test a regex, you'd use something like:
    #!/usr/bin/perl use strict; use warnings; my $string = "abcABC123ABCabc"; print "Regex1: ", $string =~ /abc[A-Z]*.2/, "\n" ; print "Regex2: ", $string =~ /abc[A-Z]*2/, "\n";
    Result:
    Regex1: 1 Regex2:
    Reason: The first matches any number of uppercase characters, followed by 1 character then followed by a 2 (this regex matched once in the string, therefore 1). The second matches any number of A-Z followed by a 2 - as there is a 1 inbetween, it doesn't match.
    Maybe you look after .* which will match any number of any character???
    Regards,
    svenXY
Re: difference between "*." and "." operators
by jhourcle (Prior) on Oct 11, 2007 at 10:57 UTC
     echo `expr match "$string" 'abcA-Z*.2'`

    You're using backticks, which is causing perl to call a shell. expr is a shell function, not a perl function. You'll want to run 'man expr' on your system to get the documentation for that command.

    update:For some reason my brain wasn't working this morning -- you're calling echo, which isn't a perl command, either. I have a feeling that your whole thing is shell, not Perl.

      ++jhourcle - I believe you are right - that was no Perl at all in the OP.
      At least we explained the Perl-way of doing this now ;-)
      Regards,
      svenXY
Re: difference between "*." and "." operators
by johngg (Canon) on Oct 11, 2007 at 10:33 UTC
    It may help you to study the tutorial and there is also the documentation available for deeper explanations.

    Cheers,

    JohnGG

Re: difference between "*." and "." operators
by shmem (Chancellor) on Oct 11, 2007 at 14:39 UTC
    how *. and * operators work
    None of them is an operator. Both are metacharacters.

    One is a quantifier - * - match zero ore more times the preceeding character.
    The other is an alias - . - match any character.

    Read perlre where these are covered. Speaking of the meaning of *. is like speaking of the meaning of "od mo" in the expression "Good morning".

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}