ocehb: (Default)
[personal profile] ocehb
задача:

есть файл:

Вася (1)
Маша (1)
Федя (2)
Коля (1)
Никита (2)



формат — имя + глубина вложенности.
написать обрамление через <ul> и <li>



решение:


# perl -lne 'BEGIN { $curr = 0; } 
  if (m#(.+?)\s+\((\d+)\)$#) { print "<ul>" if ($curr < $2);
                               print "</ul>" if ($curr > $2);
                               $curr = $2; print "<li>$1</li>"; }
  END { print "</ul>" x $curr }'


результат:



  • Вася

  • Маша


    • Федя


  • Коля


    • Никита





Date: 2009-12-16 12:44 pm (UTC)
From: [identity profile] gerdlerin.livejournal.com
А если

Маша (1)
Федя (2)
Коля (3)
Никита (1)

Profile

ocehb: (Default)
ocehb

January 2021

S M T W T F S
     12
345 6789
10111213141516
17181920212223
24252627282930
31      

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Feb. 5th, 2026 11:53 pm
Powered by Dreamwidth Studios