Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Should work, except you're using 'i' switch which means ignore_case ie match ADM, adm, Adm etc.
If that doesn't fix it, please show code and or describe in more detail.
Have you checked carefully that there's no hidden chars at the start of the field eg <space> etc.
Basically I am looking for how to search the string for "adm-" the above does not seem to do it. Here is the sequence: When it runs, it never gets written to STAFF it goes to BAD. Some reason the "=~ /adm-/" seems as if it never runs. How do I get it to search the string for that!!
Well, in your code, there are only three ways for $sane to be set to 1: if $a[9] is too small, if $a[10] is [b]too large, or if $a[9]/$a[10] is a "bad ratio".
These appear to be "error cases", in that you want it to return false when these things happen. However, when they happen, you are setting $sane = 1. Should you not be setting $sane to 0? (a 0 is false, and a 1 is true). Otherwise, you are setting $sane = 1 (true) when there is an error occuring.
If this is the case, then you are going to also want to change your default value for $sane to a 1 as well.
I have some debugging but why is that messing up if I did originally set sane to 0? And if it does help, I am actually modifying the person I took over for code.
Well 0 is a false. Therefore it will always return false, except when you are setting $sane to 1 (true), which you only do in those three if conditions. It seems to me that you would want this reversed. Right now, you've got it set up to return FALSE as long as there is NOT an error. If there IS an error, it returns TRUE. Shouldn't that be reversed? (right now script returns true on sane data, false if there was a problem). This is what I mean:
Code:
#!/usr/bin/perl
sub chkchrg {
local(@u) = @_;
# The default value is 1 (true), as in the data is SANE
local($sane) = 1;
%ratio = ("CL", 1000, "BW", 1000, "DJ", 1000);
%size = ("CL", 1024, "BW", 1024, "DJ", 1024, "PL", 1024);
%pgcount = ("CL", 1000, "BW", 1000, "DJ", 1000);
# if ( ($u[2] =~ /dj/) && ($u[11] < 1) ) {
# $sane = 1;
# }
($p) = (split(/-/, $a[2]))[2];
#print "\n$p\n";
#print "\n$a[9]\n";
#print "\n$a[10]\n";
chop($p);
# print "\n$p\n";
# when the script actually enters one of these if statements,
# then I assume that means an error has occured/data is not sane.
# (otherwise you wouldn't be printing error messages)
if ( $a[9] < $size{$p}) {
# therefore, set sane to 0 (false)
$sane = 0;
$reason = " ********Size is too small - Size is $a[9] ********";
}
elsif ( $a[10] > $pgcount{$p}) {
$sane = 0;
$reason = " ********Page count is to large - Page count is $a[10] ********";
}
elsif ($a[10]) {
if ( ($a[9] / $a[10]) < $ratio{$p}) {
$sane = 0;
$reason = " ********Bad Ratio********";
}
}
$sane;
}
1;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.