Write a one liner to dump out a module’s runtime dependencies…

What would this return?

$str = "This is a test";
$str2 = substr($str, -2); 

How would you interchange the keys and values to a hash like this:

%hash = ( foo => 1, bar => 2, baz => 3);  # before
%hash2 = ( 1 => foo, 2 => bar, 3 => baz); # after

Which would you use and why?

if (index($foo, "text to find") > -1) { # Option 1
if ($foo =~ /text to find/) {           # Option 1

Please explain the following and how you would re-write it:

my @sorted_list = sort{str2time($b->{$sort_by}) <=> str2time($a->{$sort_by})} @payload;

How would you re-write this? Can you spot the typo?

if (($aggregate->{m}->{rev}+$aggregate->{c}->{rec}) > 0 && ($aggregate->{m}->{imp}+$aggregate->{c}->{imp}) > 0) {
    $aggregate->{ecpm} = (($aggregate->{m}->{rev}+$aggregate->{c}->{rev}) / (($aggregate->{m}->{imp}+$aggregate->{c}->{imp}) / 1000));
}

What does this do and how would you do it differently?

my %boost_factors = (
  map {
    my $l = $_ < 0
       ? (($_ + 10) * 10)
       : (($_ + 1) * 100);

    ($_, $_ && "$l%")
  } -9 .. 9
);

Explain and show how you would re-write (if needed) the following:

  • In some perl module far, far away
    CAMPAIGN: {
        last CAMPAIGN if
          # Don't show competing campaigns
             ($seen_competing_campaigns
            and grep defined, reverse @{$seen_competing_campaigns}{@{$c_data->{competing_campaigns} ||= []}})

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-09-25 (日) 19:27:03 (446d)