FAQ
Hi,

I have two lines (well, 1 line is headers, then there follows a range of
data)...

# INTERFACE
RADIO-NAME MAC-ADDRESS AP SIGNAL-STRENGTH TX-RATE UPTIME
0 interface_name radio
00:0C:42:1F:2C:8D yes -63dBm@18Mbps 9Mbps 2h2m38s

I'm looking for a
foreach my $Line (@Output) {
my ($interface, $radio, $mac, $ap, $signal, $txrate, uptime) =
split(/whatidontknow/, $Line, 7);
}

Can anyone perhaps help out with the what I don't know bit?? FYI - The
columns should be fixed lengths, if that helps perhaps...

Thanks,
Chris.

Search Discussions

  • Paolo Gianrossi at Jan 9, 2009 at 1:26 pm

    Chris Knipe ha scritto:
    Hi,

    I have two lines (well, 1 line is headers, then there follows a range of
    data)...

    # INTERFACE
    RADIO-NAME MAC-ADDRESS AP SIGNAL-STRENGTH TX-RATE UPTIME
    0 interface_name radio
    00:0C:42:1F:2C:8D yes -63dBm@18Mbps 9Mbps 2h2m38s

    I'm looking for a
    foreach my $Line (@Output) {
    my ($interface, $radio, $mac, $ap, $signal, $txrate, uptime) =
    split(/whatidontknow/, $Line, 7);
    }

    Can anyone perhaps help out with the what I don't know bit?? FYI - The
    columns should be fixed lengths, if that helps perhaps...

    Thanks,
    Chris.




    Hi.
    Could maybe a simple split(/\s+/ $Line, 7); work?

    cheers
    paolino
  • Chris Knipe at Jan 9, 2009 at 1:43 pm

    # INTERFACE
    RADIO-NAME MAC-ADDRESS AP SIGNAL-STRENGTH TX-RATE UPTIME
    0 interface_name radio
    00:0C:42:1F:2C:8D yes -63dBm@18Mbps 9Mbps 2h2m38s

    I'm looking for a
    foreach my $Line (@Output) {
    my ($interface, $radio, $mac, $ap, $signal, $txrate, uptime) =
    split(/whatidontknow/, $Line, 7);
    }

    Can anyone perhaps help out with the what I don't know bit?? FYI - The
    columns should be fixed lengths, if that helps perhaps...
    Hi.
    Could maybe a simple split(/\s+/ $Line, 7); work?
    Almost, but we're not *quite* there yet... It will do though, I think
    (Really just need to get $interface name and $signal)...

    foreach my $Line (@Output) {
    my ($tmp, $number, $interface, $radio, $mac, $ap, $signal, $txrate,
    $uptime) = split(/\s+/, $Line, 9);
    print "Number: " . $number . "\n";
    print "Interface: " . $interface . "\n";
    print "Radio: " . $radio . "\n";
    print "MAC: " . $mac . "\n";
    print "AP: " . $ap . "\n";
    print "Signal: " . $signal . "\n";
    print "TX Rate: " . $txrate . "\n";
    print "Uptime: " . $uptime . "\n";

    }

    Number: 0
    Interface: interface_name
    Radio: radio
    MAC: 00:0C:42:1F:2C:8D
    AP: yes
    Signal: -63dBm...
    TX Rate: 24Mbps
    Uptime:

    I'm not sure why I am required to have 9 fields in the split to get the
    values now...

    --
    Chris.
  • Paolo Gianrossi at Jan 9, 2009 at 1:55 pm

    Chris Knipe ha scritto:
    # INTERFACE
    RADIO-NAME MAC-ADDRESS AP SIGNAL-STRENGTH TX-RATE UPTIME
    0 interface_name radio
    00:0C:42:1F:2C:8D yes -63dBm@18Mbps 9Mbps 2h2m38s

    I'm looking for a
    foreach my $Line (@Output) {
    my ($interface, $radio, $mac, $ap, $signal, $txrate, uptime) =
    split(/whatidontknow/, $Line, 7);
    }

    Can anyone perhaps help out with the what I don't know bit?? FYI - The
    columns should be fixed lengths, if that helps perhaps...
    Hi.
    Could maybe a simple split(/\s+/ $Line, 7); work?
    Almost, but we're not *quite* there yet... It will do though, I think
    (Really just need to get $interface name and $signal)...

    foreach my $Line (@Output) {
    my ($tmp, $number, $interface, $radio, $mac, $ap, $signal, $txrate,
    $uptime) = split(/\s+/, $Line, 9);
    print "Number: " . $number . "\n";
    print "Interface: " . $interface . "\n";
    print "Radio: " . $radio . "\n";
    print "MAC: " . $mac . "\n";
    print "AP: " . $ap . "\n";
    print "Signal: " . $signal . "\n";
    print "TX Rate: " . $txrate . "\n";
    print "Uptime: " . $uptime . "\n";

    }

    Number: 0
    Interface: interface_name
    Radio: radio
    MAC: 00:0C:42:1F:2C:8D
    AP: yes
    Signal: -63dBm...
    TX Rate: 24Mbps
    Uptime:

    I'm not sure why I am required to have 9 fields in the split to get the
    values now...

    --
    Chris.


    I am not sure about what's not working for you... It seems to work fine
    for me:

    my ($number, $interface, $radio, $mac, $ap, $signal, $txrate, $uptime) =
    split(/\s+/, $Line, 8);
    print "Number: " . $number . "\n";
    print "Interface: " . $interface . "\n";
    print "Radio: " . $radio . "\n";
    print "MAC: " . $mac . "\n";
    print "AP: " . $ap . "\n";
    print "Signal: " . $signal . "\n";
    print "TX Rate: " . $txrate . "\n";
    print "Uptime: " . $uptime . "\n";

    and 8 should be right, 'cause it's 8 fields you have there..

    Could you clarify what you find not working?

    Cheers
    paolino
  • Gunnar Hjalmarsson at Jan 9, 2009 at 2:34 pm

    Chris Knipe wrote:
    Paolo Gianrossi wrote:
    Could maybe a simple split(/\s+/ $Line, 7); work?
    Almost, but we're not *quite* there yet...
    ...
    I'm not sure why I am required to have 9 fields in the split to get the
    values now...
    It appears from your initial post as if there is a leading space before
    the zero value. If that's the case, your question is answered at the
    very first line of "perldoc -f split". If you exchange /\s+/ for ' ' you
    can skip that $tmp variable.

    No need to use the LIMIT parameter, btw.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
  • Gunnar Hjalmarsson at Jan 9, 2009 at 2:56 pm

    Chris Knipe wrote:
    (Really just need to get $interface name and $signal)...
    Then you may prefer a list slice.

    my ($interface, $signal) = (split ' ', $Line)[1,5];

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
  • John W. Krahn at Jan 9, 2009 at 1:54 pm

    Chris Knipe wrote:
    Hi, Hello,
    I have two lines (well, 1 line is headers, then there follows a range of
    data)...

    # INTERFACE
    RADIO-NAME MAC-ADDRESS AP SIGNAL-STRENGTH TX-RATE UPTIME
    0 interface_name radio
    00:0C:42:1F:2C:8D yes -63dBm@18Mbps 9Mbps 2h2m38s

    I'm looking for a
    foreach my $Line (@Output) {
    my ($interface, $radio, $mac, $ap, $signal, $txrate, uptime) =
    split(/whatidontknow/, $Line, 7);
    }

    Can anyone perhaps help out with the what I don't know bit?? FYI - The
    columns should be fixed lengths, if that helps perhaps...
    If you are dealing with fixed length fields then you probably want to
    use unpack:

    perldoc -f unpack
    perldoc -f pack
    perldoc perlpacktut



    John
    --
    Those people who think they know everything are a great
    annoyance to those of us who do. -- Isaac Asimov

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJan 9, '09 at 1:05p
activeJan 9, '09 at 2:56p
posts7
users4
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase