ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
dracco@death ~ $ iwconfig eth1 |grep "Link"
Link Quality=83/100 Signal level=-47 dBm Noise level=-82 dBm
I'm trying to get the link quality so I need the 83 and 100 as 2 separate variables. My perl book isn't helping. I'm confused as to how to parse a string and pick out strings within in that.... Any help would be appreciated....
dracco@death ~/.superkaramba/sysinfo/scripts $ ./link_quality.pl
Unmatched ( in regex; marked by <-- HERE in m/.*=( <-- HERE d+/ at ./link_quality.pl line 8.
dracco@death ~/.superkaramba/sysinfo/scripts $ ./link_quality.pl
\1 better written as $1 at ./link_quality.pl line 9.
Name "main::total" used only once: possible typo at ./link_quality.pl line 14.
Name "main::link" used only once: possible typo at ./link_quality.pl line 13.
Use of uninitialized value in concatenation (.) or string at ./link_quality.pl line 13.
Link Quality :
Use of uninitialized value in concatenation (.) or string at ./link_quality.pl line 14.
total :
open IWC, 'iwconfig eth1 |' or
die "Could not execute iwconfig eth1: $!\n";
while (<IWC>) {
if (/Link Quality=(\d+)\/(\d+)/) {
my ($link, $total) = ($1, $2);
print "link: $link, total: $total\n";
last;
}
}
close IWC;
that's untested also (lazy) but easier to read/debug perhaps...
keefaz: I think you've got a \1 where you want a $1 in the replacement part of s///
also, iwconfig might complain about "broken pipe" with my code. that's because it doesn't read (necessarily) all of the output from iwconfig. you can fix that if you like : )
dracco@death ~/.superkaramba/sysinfo/scripts $ ./link_quality.pl
\1 better written as $1 at ./link_quality.pl line 9.
Name "main::link" used only once: possible typo at ./link_quality.pl line 13.
Use of uninitialized value in concatenation (.) or string at ./link_quality.pl line 13.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.