LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-01-2005, 06:45 PM   #1
Ateo
Member
 
Registered: Sep 2004
Location: Long Beach, CA
Distribution: FreeBSD,Ubuntu,Gentoo,MacOS
Posts: 139

Rep: Reputation: 15
perl assistance...


I'm trying to grab 2 variables from this output:
Code:
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....
 
Old 07-01-2005, 07:02 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Is it a % value ? If yes 100 is a constant not a variable
I will assume it is a variable tough

Code:
open IWC, 'iwconfig eth1 |' or 
    die "Could not execute iwconfig eth1: $!\n";

while(<IWC>) {
    next unless /Link Quality/;
    my $s = $_;
    $s =~ s/.*=(\d+\/\d+).*/\1/;
    my($link, $total) = split /\//, $s;
}
close IWC;
print "Link Quality : $link\n";
print "total : $total\n";

Last edited by keefaz; 07-01-2005 at 07:05 PM.
 
Old 07-01-2005, 07:08 PM   #3
Ateo
Member
 
Registered: Sep 2004
Location: Long Beach, CA
Distribution: FreeBSD,Ubuntu,Gentoo,MacOS
Posts: 139

Original Poster
Rep: Reputation: 15
Didn't work..

Code:
dracco@death ~/.superkaramba/sysinfo/scripts $ ./link_quality.pl
Unmatched ( in regex; marked by <-- HERE in m/.*=( <-- HERE d+/ at ./link_quality.pl line 8.
It was a cut and paste job... so.. hmm.
 
Old 07-01-2005, 07:13 PM   #4
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Please retry the copy and paste, I edited my post
 
Old 07-01-2005, 07:34 PM   #5
Ateo
Member
 
Registered: Sep 2004
Location: Long Beach, CA
Distribution: FreeBSD,Ubuntu,Gentoo,MacOS
Posts: 139

Original Poster
Rep: Reputation: 15
Still no.. hmm

Code:
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 :
 
Old 07-01-2005, 08:31 PM   #6
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
perhaps

Code:
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 : )
 
Old 07-02-2005, 12:42 PM   #7
Ateo
Member
 
Registered: Sep 2004
Location: Long Beach, CA
Distribution: FreeBSD,Ubuntu,Gentoo,MacOS
Posts: 139

Original Poster
Rep: Reputation: 15
The last code did not work either...

Code:
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.
 
Old 07-02-2005, 12:47 PM   #8
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
that error is not for the snippet I posted.
 
Old 07-02-2005, 08:07 PM   #9
Ateo
Member
 
Registered: Sep 2004
Location: Long Beach, CA
Distribution: FreeBSD,Ubuntu,Gentoo,MacOS
Posts: 139

Original Poster
Rep: Reputation: 15
You were correct. My apologies. Your last code worked perfect. My gratitude.

Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl assistance requested... Ateo Programming 2 05-26-2005 03:01 PM
Problem with perl module for w3c validator to work on my local Apache+PHP+perl instal tbamt Linux - Software 0 12-16-2004 05:37 PM
Need assistance spotslayer Linux - Software 1 11-18-2004 06:49 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
chrooting apache v2 (php, ssl, perl support) ; perl configuration markus1982 Linux - Security 3 01-26-2003 06:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration