se strict;

Produces the error message:

Can't locate object method "se" via package "strict" (perhaps you forg +ot to load "strict"?)
my $data = `/sbin/ifconfig | grep “RX bytes” | head -1`;

I guess you are assuming that the "certain device" you want information on is the first device listed by ifconfig?

$data =~ /RX bytes\:(\d+) .*TX bytes\:(\d+) .*/; my $recv = $1/1024; my $sent=$2/1024; $recv =~ s/\..*//; $sent =~ s/\..*//;

You shouldn't use the variables $1 and $2 unless the regular expression matched correctly otherwise the values in $1 and $2 will be from the last successful match. Is there any reason that you didn't use the int function instead of the substitution operator?

You probably want something like this:

sub get_measures { my $device = qr/\A\Q$_[0]\E\s/; # pass device name as first argum +ent local $/ = ''; # paragraph mode my ( $recv, $sent ) = map { /$device/ && /RX bytes\:(\d+) .*?TX bytes\:(\d+)/ ? int( $1 / 1024 ), int( $2 / 1024 ) : () } qx[/sbin/ifconfig]; return $recv, $sent; }

In reply to Re: measuring IN/OUT traffic on your computer by jwkrahn
in thread measuring IN/OUT traffic on your computer by spx2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.