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

please help anyone.... check out this code; from the command line, if i put GU1 it accept but if i try to put GU 1(with space between), then it doesn't accept it, what can i do? i want the program to ignore the spaces sample code:

$msg =~ s/\"/'/igx; if (($msg =~ /gu1/i) && ($msg !~ /gu1[0123456789]+/i)) { $vote = 'gu1'; $found = 1; }

please anyone help me

Edit: g0n - fixed formatting and inserted codetags

Replies are listed 'Best First'.
Re: print out
by philcrow (Priest) on Oct 13, 2005 at 14:10 UTC
    When you enter parameters at the command line, the shell interprets space (or multiple spaces) as an argument separator. To see this, carefully print @ARGV:
    #!/usr/bin/perl { $" = "\n"; print "@ARGV\n"; }
    This will print each argument on a separate line. Then you will see that it isn't your script that is mishandling the args. To put them back together, you could do something like:
    my $args = join '', @ARGV;
    Then you can ask the original question about spaces in the regexes. You could use /gu\s*1/ in the first instance. That will match gu followed by optional space followed by 1.

    Phil

Re: print out
by Roy Johnson (Monsignor) on Oct 13, 2005 at 14:08 UTC
    Before you test it, remove the spaces:
    $msg =~ tr/ //d;

    Caution: Contents may have been coded under pressure.
Re: print out
by Perl Mouse (Chaplain) on Oct 13, 2005 at 14:24 UTC
    if ($msg =~ /gu\s*1(?!\d)/i) { $vote = 'gu1'; $found = 1; }
    Perl --((8:>*