hello, Im new to PERL and I'm writing some code to compare two files lines:

file 1 gets random password from a server
file 2 is a test case to check that I'm getting the password with the required characteristics ( length, alnum or num)

the problem that I have is in the case that the password generated by the server supouse to be numeric
and the password in my test case have a char but, it doesnt throw the error message.

anyways here is some code: for that specific section

elsif (($tact_line =~ m/[0-9]^\w/)&($texp_line =~ m/\w/)){
            print "\nnumeric password can't have alpha characters\n";
            print "$ARGV[0] $tact_line  |   $ARGV[1] $texp_line\n";
            exit 1;
        }

Hi,
It will be better if you can share more codes here, so that we can see what you are really comparing.
However, there are several things wrong with the code you have shown so far.
Do you intend to use && as against & and || as against |. What then is the purpose of exit 1.
The in your match string in perl REs, ^ out the [] represents the beginning of a string, but inside means exception, so what do you mean by ~ m/[0-9]^\w/.
Sometimes you might what to place at the beginning of your script

use warnings;
use strict;
use diagnostics; ## only use when you want verbose explanations of error

Hope this helps.

The following may not exactly correspond to what you mean by 'numeric' but it will serve as an example of what the Scalar::Util module can do.

#!/usr/bin/perl
use warnings;
use strict;

use Scalar::Util qw(looks_like_number);
while (my $teststring = <DATA>){
    chomp $teststring;#Remove newline character from end of string
    if (looks_like_number($teststring)){
        print $teststring, ' looks like a number to me', "\n";
    }
    else{
        print $teststring, ' does NOT look like a number to me', "\n";
    }
}

__DATA__
hello
5
2.3
-2.3
7t7
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.