Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Remove text after and before

by Neighbour (Friar)
on May 22, 2012 at 09:47 UTC ( #971751=note: print w/ replies, xml ) Need Help??


in reply to Remove text after and before

You could replace your source data with this:
my @NIC = split("\n", `ip link | sed -n 1~2p | cut -d':' -f2 | tr -d ' '`);
and go from there, though that's not really the Perl way :P

A more perlish way would be like this:

my @raw_data = `ip link`; my @NIC = grep { /^\d+:\ /; } @raw_data; for (@NIC) { chomp; s/^[0-9]+:\ ([a-z]+[0-9]*):\ .*$/$1/; } Data::Dump::dd(@NIC);
(For some reason map { s/^[0-9]+:\ ([a-z]+[0-9]*):\ .*$/$1/; } grep ... doesn't seem to work).


Comment on Re: Remove text after and before
Select or Download Code
Replies are listed 'Best First'.
Re^2: Remove text after and before
by moritz (Cardinal) on May 22, 2012 at 10:07 UTC
    (For some reason map { s/^[0-9]+:\ ([a-z]+[0-9]*):\ .*$/$1/; } grep ... doesn't seem to work).

    That's because s/// returns the number of substitutions, not the substituted string, and map picks up the return value of the block. So adding a $_; to the end of the block might help, then the block returns the substituted text.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://971751]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (18)
As of 2015-07-31 16:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (279 votes), past polls