LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Disable warning messages in perl.. (https://www.linuxquestions.org/questions/linux-newbie-8/disable-warning-messages-in-perl-4175540772/)

bangnagr 04-26-2015 03:07 AM

Disable warning messages in perl..
 
Hi All,

I'm not a perl programmer, so please help me to disable warning messages. I tried like commenting 'use strict' and 'use warning' in perl program. But it is not working.

All I want is to disable warning messages.

Please note its not actual ping program, But a perl wrapper for ping to display ping output in color (Cope).

Below is output:

Code:

$ ./ping google.com
given is experimental at /usr/local/share/perl/5.20.2/App/Cope.pm line 255.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope.pm line 256.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope.pm line 259.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope.pm line 262.
given is experimental at /usr/local/share/perl/5.20.2/App/Cope/Extra.pm line 119.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope/Extra.pm line 120.
given is experimental at /usr/local/share/perl/5.20.2/App/Cope/Extra.pm line 159.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope/Extra.pm line 160.
when is experimental at /usr/local/share/perl/5.20.2/App/Cope/Extra.pm line 161.
PING google.com (173.194.36.4) 56(84) bytes of data.
64 bytes from bom04s01-in-f4.1e100.net (173.194.36.4): icmp_seq=1 ttl=57 time=67.8 ms
64 bytes from bom04s01-in-f4.1e100.net (173.194.36.4): icmp_seq=2 ttl=57 time=68.1 ms
64 bytes from bom04s01-in-f4.1e100.net (173.194.36.4): icmp_seq=3 ttl=57 time=66.6 ms
64 bytes from bom04s01-in-f4.1e100.net (173.194.36.4): icmp_seq=4 ttl=57 time=66.6 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0 packet loss, time 3004ms
rtt min/avg/max/mdev = 66.687/67.353/68.155/0.743 ms

Works fine when error redirected to /dev/null
Code:

$ ./ping google.com 2>/dev/null
PING google.com (173.194.36.1) 56(84) bytes of data.
64 bytes from bom04s01-in-f1.1e100.net (173.194.36.1): icmp_seq=1 ttl=57 time=68.4 ms
64 bytes from bom04s01-in-f1.1e100.net (173.194.36.1): icmp_seq=2 ttl=57 time=66.6 ms
64 bytes from bom04s01-in-f1.1e100.net (173.194.36.1): icmp_seq=3 ttl=57 time=66.4 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0 packet loss, time 2003ms
rtt min/avg/max/mdev = 66.419/67.179/68.421/0.885 ms

Unfortunately, I cannot use output error redirection because all the perl programs are in PATH.

Actual ping perl program:
Code:

#!/usr/bin/env perl
use App::Cope;
use App::Cope::Extra qw[ping_time percent_b];
use Regexp::Common qw[net];

sub process {

  # header
  line qr{^PING (\S+)} => 'blue bold underline';

  # ping replies
  line qr{time=([0-9.]+ ms)\b}    => \&ping_time;
  mark qr{\($RE{net}{IPv4}\)}    => 'blue';
  line qr{(?:icmp_seq|ttl)=(\d+)} => 'bold';
  line qr{^(?:\d+ bytes )?[Ff]rom ([^:\s]+)} => 'blue bold';

  # final ping statistics
  line qr{(\d+% packet loss)} => \&{ percent_b 0, 1, 26 };
  line qr{min/avg/(?:max/mdev|ewma/max)\s=\s
          ([0-9.]+)/    # minimum
          ([0-9.]+)/    # average
          ([0-9.]+)/    # maximum or moving average
          ([0-9.]+\sms) # mean deviation or maximum
      }x => ( \&ping_time ) x 4;

}

run( \&process, real_path, @ARGV );

Code:

$ head -n15 /usr/local/share/perl/5.20.2/App/Cope.pm
#!/usr/bin/env perl
package App::Cope;
#use strict;
#use warnings;
use 5.010_000;
use Carp;

our $VERSION = '0.99';

=head1 NAME

App::Cope - Functions for the B<cope> program

=head1 SYNOPSIS

Code:

$ head -n15 /usr/local/share/perl/5.20.2/App/Cope/Extra.pm
#!/usr/bin/env perl
package App::Cope::Extra;
#use strict;
#use warnings;
use 5.010_000;

=head1 NAME

App::Cope::Extra - Pre-defined highlighting syntax for common patterns

=head2 SYNOPSIS

  use App::Cope::Extra;

  line qr{User: (\S+)} => \&{ user 'yellow' };

Thanks

bangnagr 04-26-2015 03:30 AM

Never mind, I figured it out. I have to add 'no warnings all'; in perl program.

Sorry to bother

Thanks


All times are GMT -5. The time now is 09:25 PM.