Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

strange simple error

Posted on 2013-12-21
6
Medium Priority
?
298 Views
Last Modified: 2013-12-22
there are 3 part of errors that we get

1. the beginning errors
2. in the code you should see if ($reason eq "mbps" ) {
but it still applie else part of if

3. why do we get numeric  error :S

[root@sflow islemler]# perl deneme.pl
Unquoted string "paketlimiti" may clash with future reserved word at deneme.pl line 19.
Unquoted string "trafiklimiti" may clash with future reserved word at deneme.pl line 23.
Name "main::paketlimiti" used only once: possible typo at deneme.pl line 4.
Name "main::trafiklimiti" used only once: possible typo at deneme.pl line 5.
Argument "trafiklimiti" isn't numeric in numeric gt (>) at deneme.pl line 23, <$fh> line 1.
paket limiti asildi
mbps

178.20.230.51 35mbps
1387666838 178.20.230.51 35 mbps
paket limiti asildi
pps

178.20.230.51 3072pps
1387666838 178.20.230.51 3072 pps
paket limiti asildi
mbps

178.20.227.86 11mbps
1387666838 178.20.227.86 11 mbps
paket limiti asildi
pps

79.110.81.134 1536pps
1387666838 79.110.81.134 1536 pps
paket limiti asildi
mbps

178.20.230.51 32mbps
1387666839 178.20.230.51 32 mbps
paket limiti asildi
pps

178.20.230.51 3328pps
1387666839 178.20.230.51 3328 pps

Open in new window










use warnings;

 $paketlimiti = 2500;
 $trafiklimiti = 10;

open(my $fh, '-|', 'sflowtool -4 -p 3601  | /scripts/DoSTargets') or die $!;
while (my $line = <$fh>) {

#print ((split(/ /, $line))[1],"\n");


my $ip  = (split(/ /, $line))[1];
my $size = (split(/ /, $line))[2];
my $reason = (split(/ /, $line))[3];


if ($reason eq "mbps" ) {
        if ($size >  paketlimiti) {
                print "trafik limiti asildi \n";
        }
}else{
        if ($size >  trafiklimiti) {
                print "paket limiti asildi \n";
        }
}

print $reason . "\n";
print $ip." ".$size.$reason;
print $line;
}

close $fh;

Open in new window

0
Comment
Question by:3XLcom
  • 3
  • 2
6 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 39734075
splain
/opt/local/bin/splain: Reading from STDIN
Unquoted string "paketlimiti" may clash with future reserved word at deneme.pl line 19.
Unquoted string "paketlimiti" may clash with future reserved word at deneme.pl
      line 19 (#1)
    (W reserved) You used a bareword that might someday be claimed as a
    reserved word.  It's best to put such a word in quotes, or capitalize it
    somehow, or insert an underbar into it.  You might also declare it as a
    subroutine.

Name "main::paketlimiti" used only once: possible typo at deneme.pl line 4.
Name "main::paketlimiti" used only once: possible typo at deneme.pl line 4 (#2)
    (W once) Typographical errors often show up as unique variable names.
    If you had a good reason for having a unique name, then just mention it
    again somehow to suppress the message.  The our declaration is
    provided for this purpose.
   
    NOTE: This warning detects symbols that have been used only once so $c, @c,
    %c, *c, &c, sub c{}, c(), and c (the filehandle or format) are considered
    the same; if a program uses $c only once but also uses any of the others it
    will not trigger this warning.

Argument "trafiklimiti" isn't numeric in numeric gt (>) at deneme.pl line 23, <$fh> line 1.
Argument "trafiklimiti" isn't numeric in numeric gt (>) at deneme.pl line 23,
      <$fh> line 1 (#3)
    (W numeric) The indicated string was fed as an argument to an operator
    that expected a numeric value instead.  If you're fortunate the message
    will identify which operator was so unfortunate.



Did you mean to say
     if ($size >  $paketlimiti) {
0
 

Author Comment

by:3XLcom
ID: 39734080
yes    if ($size >  $paketlimiti) { this part is not wroking correctly check the output

trafik limiti asildi  8>10
178.20.228.75 8mbps
1387668213 178.20.228.75 8 mbps
trafik limiti asildi  8>10
95.7.67.146 8mbps
1387668214 95.7.67.146 8 mbps
trafik limiti asildi  41>10
185.9.156.83 41mbps





#use strict;
use warnings;

my $paketlimiti = 2500;
my $trafiklimiti = 10;

open(my $fh, '-|', 'sflowtool -4 -p 3601  | /scripts/DoSTargets') or die $!;
while (my $line = <$fh>) {

#print ((split(/ /, $line))[1],"\n");


my $ip  = (split(/ /, $line))[1];
my $size = (split(/ /, $line))[2] + 0;
my $reason = substr((split(/ /, $line))[3],0,-1);


if ($reason eq 'mbps' ) {
        if ($size >  paketlimiti){
                print "trafik limiti asildi  " .$size.">".$trafiklimiti."  \n";
        }else{
                print "trafik limiti asildi  " .$size."<".$trafiklimiti."  \n";
        }
}else{
        if ($size >  trafiklimiti) {
                print "paket limiti asildi \n";
        }
}

print $ip." ".$size.$reason."\n";
print $line;
}

close $fh;

Open in new window

0
 

Author Comment

by:3XLcom
ID: 39734085
that worked but why my variable not acting like a numeric value ;

  
 if ($size >  10){
                print  $size2." trafik limiti asildi  " .$size.">".$trafiklimiti."  \n";
        }else{
                print $size2." trafik limiti asildi  " .$size."<".$trafiklimiti."  \n";
        }

Open in new window

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 85

Expert Comment

by:ozo
ID: 39734697
If you mean $size, what was its value?
0
 
LVL 28

Accepted Solution

by:
FishMonger earned 2000 total points
ID: 39734860
Why did you comment out the use strict; statement?

Ignoring the problems strict points out is never a good practice.

Are you receiving the warning for every line or just some of the lines?

In either case, it would appear that the line is not formatted as you expect.  You should use the Data::Dumper or Data::Dump module to dump out the full line as well as the vars after the splitting the line.

Why are you using 3 separate split statements?  You should assign all 3 of those vars using a single split statement.

I assume you're using substr to remove the line terminator, but why. The normal method to remove the line terminator is to use the chomp function.

You're splitting on a single space, which may be just fine, but just in-case  there is more than a single space separating the fields and to accommodate possible leading spaces, use ' ' instead of / /.

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my $paketlimiti = 2500;
my $trafiklimiti = 10;

open(my $fh, '-|', 'sflowtool -4 -p 3601  | /scripts/DoSTargets') or die $!;

while (my $line = <$fh>) {
    
    chomp $line;
    my ($ip, $size, $reason)  = (split(' ', $line))[1,2,3];
    
    print Dumper ($line, $ip, $size, $reason);
    
    if ($reason eq 'mbps' ) {
        if ($size > $paketlimiti){
            print "trafik limiti asildi  " .$size.">".$trafiklimiti."  \n";
        }
        else {
            print "trafik limiti asildi  " .$size."<".$trafiklimiti."  \n";
        }
    }
    else {
        if ($size > $trafiklimiti) {
            print "paket limiti asildi \n";
        }
    }
}

close $fh;

Open in new window

0
 

Author Closing Comment

by:3XLcom
ID: 39734969
thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question