We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,231 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

PERL custom diff

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;
        }
3
Contributors
2
Replies
11 Hours
Discussion Span
6 Months Ago
Last Updated
3
Views
iacosar
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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.

2teez
Junior Poster
162 posts since Apr 2012
Reputation Points: 40
Solved Threads: 32
Skill Endorsements: 0

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
d5e5
Practically a Posting Shark
831 posts since Sep 2009
Reputation Points: 162
Solved Threads: 163
Skill Endorsements: 1

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.6186 seconds using 2.66MB