Perl

Print all the linux system users that starts with d or D

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

  • With a Perl one liner :D
open(my $fh, ';
map { print $& . "\n" if $_ =~ /^d([^:]*)/  } @user_info;
close $fh;
  • Avoiding one-liners
foreach my $user_line (@user_info) {
    if ($user_line =~ /^d([^:]*)/) {
        print $& . "\n";
    }
}