Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can this be done in one line?

Tags:

perl

I am extracting the MAC address like so

my @tmp = split / /, "domain (123.123.123.123) at 00:11:22:33:44:55 [ether] on eth0";
my $vip = $tmp[3];

but can it be done without using a temporary variable?

like image 871
Sandra Schlichting Avatar asked Nov 03 '11 15:11

Sandra Schlichting


People also ask

How do you write a conditional statement in one line?

Writing a one-line if-else statement in Python is possible by using the ternary operator, also known as the conditional expression. This works just fine. But you can get the job done by writing the if-else statement as a neat one-liner expression.

Can we write if else in one line in Python?

Python If Statement In One Line In Python, we can write “if” statements, “if-else” statements and “elif” statements in one line without worrying about the indentation. In Python, it is permissible to write the above block in one line, which is similar to the above block.


1 Answers

Yes it can:

my $vip = (split / /, "domain (123.123.123.123) at 00:11:22:33:44:55 [ether] on eth0")[3];
like image 115
Toto Avatar answered Sep 22 '22 16:09

Toto