ock for normal Caps toggle). Alt+Shift is also a popular combination; it will however lose its usual behavior in Emacs and other programs that use it for specific needs.\n\nNot all listed keys are present on all keyboards.
Extended_description-am.utf-8: በቁልፍ ገበታው ላይ በብሔራዊና  በላቲን ፊደል አጣጣል መሃከል የመቀየርያ መንገድ ያስፈልጎታል።\n\nየእርግን ቀኝ Alt ወይም Caps Lock ቁልፎች keys በአብዛኛው ለምቾት ሲባል ጥቅም ላይ ይውላሉ። (የኋለኛውን ወደ ተለምዶው ለመቀየር Shift+Capsን ይጠቀሙ). Alt+Shift እንዲሁ ተወዳጅ ቅንብር ነው። ነገርግን በEmacsና ሌሎች በተለየ ሁኔታ የሚጠቀሙበት ስልቶች ልይ የተለምዶ ባህሪውን ያጣል።\n\nሁሉም የተመዘገቡ ቁልፎች በሁሉም  ፊደል ገበታ ላይ አይገኙም
Extended_description-ar.utf-8: ستحتاج إلى طريقة لتبديل لوحة المفاتيح بين التخطيط المحلي والتخطيط اللاتيني القياسي.\n\nزر Alt الأيمن أو Caps Lock عادة تستخدم لأسباب راحة المستخدم (وفي حالة استخدام Caps Lock للتبديل، اضغط Shift+Caps Lock للتبديل بين الحروف الصغيرة والكبيرة). كما يشيع استخدام زرّي Alt+Shift، إلا أنها قد تفقد سلوكها المعتاد في إيماكس وفي البرامج الأخرى التي تستخدمها لأغراض معيّنة.\n\nليست جميع المفاتيح المسردة موجودة في جميع لوحات المفاتيح.
Extended_description-ast.utf-8: Necesites una manera d'alternar el tecláu ente la distribución nacional y la distribución standard Latina.\n\nAlt Derecha o tecla Caps Lock escuéyense normalmente por razones ergonómiques (nel casu caberu, usa la combinación May+Caps Lock p'alternar Caps). Alt+May ye tamién una combinación popular; Sicasí, perderáse'l so comportamientu habitual n'Emacs y otros programes que lo usen pa necesidaes específiques.\n\nNon toles tecles llistaes tán en tolos teclaos.
Extended_description-be.utf-8: Вам трэба вызначыць спосаб пераключэння клавіятуры паміж нацыянальнай і стандартнай лацінскай раскладкай.\n\nНайбольш эрганамічнымі варыянтамі ёсць правы Alt ды Caps Lock (у апошнім выпадку выкарыстоўвайце камбінацыю Shift+Caps Lock для звычайнага пераключэння Caps). Іншым папулярным выбарам ёсць камбінацыя Alt+Shift; тады яна згубіць свой эфект у Emacs ды іншых праграмах.\n\nНе ўсе паказаныя кнопкі прысутнічаюць на ўсіх клавіятурах.
Extended_description-bg.utf-8: Вашата клавиатурна подредба изисква начин за превключване между режим „латиница“ и режим „национални букви“.\n\nДесният клавиш Alt и клавишът Caps Lock често се избират от съображения за ергономичност (в последния случай използвайте комбинацията Shift+Caps Lock за нормален Caps Lock).  Комбинацията Alt+Shift също е популярен избор; тя обаче ще изгуби обичайното си действие в Emacs и други програми, които я използват за специфичните си нужди.\n\nНе всеки от изброените клавиши е наличен на всички клавиатури.
Extended_description-bn.utf-8: কীবোর্ডর ন্যাশনাল লেআউট ও ল্যাটিন লেআউটের মধ্যে টগল করতে আপনার একটা উপায় পেতে হবে।\n\nসঙ্গত কারনে ডান অল্ট  বা ক্যাপস্ লক প্রায়ই ব্যবহার হয় (পরের ‌ক্ষেত্রে শিফট্+ক্যাপস্ লক  কম্বিনেশন সাধারণ ক্যাপস্ টগল্ এর জন্য ব্যবহার হয়। অল্ট+শিফট্ ও একটি জনপ্রিয় কম্বিনেশন; তবে এর ফলে  Emacs ও অন্যান্য প্রোগ্রামে যেখানেএদের বিশেষ কাজ নির্দেশিত, সেগুলো হারাবে।\n\nতালিকাভুক্ত সব কী কীবোর্ডে নেই।
Extended_description-bo.utf-8: རང་རྒྱལ་གྱི་བཀོད་པ་དང་ཚད་ལྡན་གྱི་ལ་ཐིན་བཀོད་པའི་བར་མཐེབ་གཞོང་བརྗེ་རེས་བྱེད་སྟངས་ཞིག་ཡོད་དགོས\n\nRight Alt or Caps Lock keys are often chosen for ergonomic reasons (in the latter case, use the combination Shift+Caps Lock for normal Caps toggle). Alt+Shift is also a popular combination; it will however lose its usual behavior in Emacs and other programs that use it for specific needs.\n\nཐོ་འགོད་བྱས་ཟིན་པའི་མཐེབ་ཆ་ཚང་མཐེབ་གཞོང་གང་རུང་ཐོག་ཏུ་མེད
Extended_description-bs.utf-8: Trebat će Vam način da prebacite tastaturu između nacionalnog rasporeda i standardnog Latinskog rasporeda.\n\nDesni Alt ili Caps Lock tipke su obično izabrani iz ergonomskih razloga (u drugom slučaju, koristite kombinaciju Shift+Caps Lock kao obični Caps prekidač). Alt+Shift je također popularna kombinacija; mada će izgubiti uobičajenu ulogu u Emacs i ostalim programima koji je koriste za svoje potrebe.\n\nSvi izlistani tasteri nisu prikazani na svim tastaturama.
Extended_description-ca.utf-8: Necessitareu una manera pera commutar el teclat entre la disposició nacional i la disposició llatina estàndard.\n\nSovint se seleccionen les tecles Alt dreta o Fixació de majúscules per raons d'ergonomia (en el segon cas, emrpreu la combinació Majúscules+Fixació de majúscules per a commutar la fixació normal). Alt+Majúscules també és una combinació habitual, tot i que perdrà el seu comportament habitual a l'Emacs i altres programes que l'empren per a necessitats específiques.\n\nNo totes les tecles llistades són presents a tots els teclats.
Extended_description-cs.utf-8: Potřebujete způsob, kterým se budete přepínat mezi vaším národním rozložením a standardním rozložením latinky.\n\nNejergonomičtější se zdá použití pravého Altu nebo Caps Lock (původní funkčnost Caps Lock pak získáte kombinací kláves Shift+Caps Lock). Další populární kombinací je Alt+Shift, případně Control+Shift. V takovém případě ale tato kombinace ztratí v aplikacích svůj původní význam (např. v Emacsu).\n\nUvedené klávesy nemusí být přítomny na všech klávesnicích.
Extended_description-cy.utf-8: Mi fydd yn rhaid i chi gael ffordd o newid y bysellfwrdd rhwng y cynllun cenedlaethol a'r cynllun Lladin safonol.\n\nDewisir y bysellau Alt Dde neu Capiau Clo fel arfer am resymau hwylustder (yn yr ail ddewis, defnyddiwch y cyfuniad Shift+Capiau Clo ar gyfer toglo llythrennau mawr arferol). Mae Alt+Shift yn gyfuniad poblogaidd hefyd; ond mi fydd yn colli ei ddefnydd arferol yn Emacs a rhaglenni eraill sy'n ei ddefnyddio at bwrpas penodol.\n\nNid yw'r bysellau rhestrwyd yn bresennol ar bob bysellfwrdd.
Extended_description-da.utf-8: Du har brug for en måde at skifte tastaturet mellem national-layoutet og standard-latin-layoutet.\n\nHøjre Alt eller Caps Lock-taster bliver ofte valgt af ergonomiske grunde (brug kombinationen Shift+Caps Lock til at slå Caps til/fra på normal vis i det tilfælde). Alt+Shift er også en populær kombination; kombinationen vil dog miste sin almindelige funktion i Emacs og andre programmer, der bruger den til særlige behov.\n\nIkke alle de viste taster er til stede på alle tastaturer.
Extended_description-de.utf-8: Sie benötigen eine Möglichkeit, die Tastaturbelegung zwischen nationalem und lateinischem Standardmodus umzuschalten.\n\nAus Ergonomiegründen werden oft die Alt- oder Feststelltasten ausgewählt. Im letzteren Fall verwenden Sie die Kombination Umschalttaste+Feststelltaste für das normale Umschalten der Großschreibung. Alt+Umschalttaste ist auch eine beliebte Kombination; in Emacs und anderen Programmen, die diese Kombination benutzen, wird sie allerdings ihre gewöhnliche Bedeutung verlieren.\n\nNicht alle aufgeführten Tasten sind auf allen Tastaturen vorhanden.
Extended_description-dz.utf-8: རྒྱལ་ཡོངས་སྒྲིག་བཀོད་དང་ཚད་ལྡན་ལེ་ཊིན་སྒྲིག་བཀོད་ཀྱི་བར་ན་ ལྡེ་སྒྲོམ་སོར་སྟོན་འབད་ནི་གི་དོན་ལུ་ ང་བཅས་ལུ་ཐབས་ལམ་དགོ།\n\nགཡས་ཀྱི་གདམ་ལྡེ་ ཡང་ན་ ཚུགས་ལྡེ་ཚུ་ ཨར་གོ་ནོ་མིག་གི་དོན་ལུ་ འཕྲལ་འཕྲལ་གདམ་ཁ་རྐྱབ་ཨིན། (ཤུལ་མའི་ཡི་གུ་ནང་ ཨ་རྟག་ཧ་ལུགས་ཀྱི་ཚུགས་ཡིག་སོར་སྟོན་འབད་ནི་ལུ་ མཉམ་བསྡོམས་ སོར་ལྡེ་+ཚུགས་ལྡེ་ལག་ལེན་འཐབ་) གདམ་ལྡེ་+སོར་ལྡེ་འདི་ ཡོངས་གྲགས་ཆེ་བའི་མཉམ་བསྡོམས་ཅིག་ཨིན། དམིགས་བསལ་དགོས་མཁོ་དང་འཁྲིལ་ཏེ་ལག་ལེན་འཐབ་མི་དེ་ ཨི་མེཀསི་དང་གཞན་ལས་རིམ་ཚུ་ནང་ ཨ་རྟག་་ལུགས་སྦེ་མི་གནས།\n\nཐོ་བཀོད་འབད་ཡོད་པའི་ལྡེ་ཡིག་ཆ་མཉམ་ ལྡེ་སྒྲོམ་ག་ར་ནང་མི་འོང་།
Extended_description-el.utf-8: Θα χρειαστείτε έναν τρόπο για την εναλλαγή μεταξύ τοπικής και της συνηθισμένης λατινικής διάταξης πληκτρολογίου.\n\nΤα πλήκτρα Right Alt ή Caps Lock επιλέγονται συνήθως για εργονομικούς λόγους (στη δεύτερη περίπτωση χρησιμοποιήστε τον συνδυασμό Shift+Caps Lock για τη συνηθισμένη εναλλαγή Κεφαλαίων). Ο συνδυασμός Alt+Shift είναι ένας επίσης δημοφιλής συνδυασμός. Χάνει όμως έτσι τη συνηθισμένη συμπεριφορά που έχει στον Emacs και σε άλλα προγράμματα όπου χρησιμοποιείται για ειδικές ανάγκες.\n\nΤα πλήκτρα που αναφέρονται εδώ δεν υπάρχουν σε όλα τα πληκτρολόγια.
Extended_description-eo.utf-8: Vi bezonos manieron por baskuli la klavaron inter la nacia aranĝo kaj la ordinara latina aranĝo.\n\nDekstra Alt aŭ Majuskla Baskula klavoj ofte estas elektitaj pro ergonomio (en la lasta situacio, uzu la kombinon Shift+Majusklo-baskulo por normala baskuligo). Alt+Shift ankaŭ estas populara kombino; tamen ĝi perdos sian normalan funkcion en Emacs kaj aliaj programoj kiuj uzas ĝin por specifaj bezonoj.\n\nNe ĉiu listita klavo ĉeestas en ĉiuj klavaroj.
Extended_description-es.utf-8: Necesitará una forma para cambiar el teclado entre la distribución nacional y la distribución latina estándar.\n\nLas teclas Alt derecho y Bloqueo mayúsculas se escogen frecuentemente por razones ergonómicas (en el último caso, utilice la combinación «Shift»+Bloqueo mayúsculas para cambiar a mayúsculas). Alt+«Shift» también es una combinación popular, sin embargo, perderá su comportamiento tradicional en Emacs y otros programas que las utilicen para sus propias necesidades.\n\nTenga en cuenta que las teclas listadas no están presentes en todos los teclados.
Extended_description-et.utf-8: Klaviatuuripaigutuse vahetamiseks rahvusliku ja standardse ladina-paigutuse vahel tuleb määrata vahetamise viis.\n\nErgonoomika tõttu valitakse tihti Parem Alt või Caps Lock klahvid (kasutatakse ka Shift+Caps Lock või harilikku Caps Lock lülitamist). Alt+Shift on samuti sage kombinatsioon, kuid siis kaotab see oma tavapärase kasutuse Emacs'is ja teistes programmides, mis seda kasutavad.\n\nMitte kõik loetletud klahvid ei ole saadaval kõigil klaviatuuridel.
Extended_description-eu.utf-8: Agian latin estandar eta nazionalaren diseinuen artean teklatua kommutatzeko aukera beharko duzu.\n\nAukera ergonomikoenak Ezker Alt eta Blokeatu Maiuskulak teklek dirudite (bestela Maius+Blokeatu Maiuskulak erabili tamaina arruntera aldatzeko). Beste hautapen oso erabili bat Alt+Maius tekla-konbinazioa da, kontuan izan kasu honetan Alt+Maius tekla konbinazioak Emacs edo beste programetan duen erabilera galduko duela.\n\nZerrendatutako tekla guztiak ez daude teklatu guztietan.
Extended_description-fa.utf-8: شما نیاز به راهی دارید که بین طرح بندی صفحه کلید بومی و طرح بندی صفحه کلید لاتین جابه‌جا شوید.\n\nکلید Alt چپ و Caps Lock معمولا به دلایل ارگونومیک انتخاب می شود. Alt+Shift هم ترکیب متداولی است؛ با وجود این در برخی از نرم افزار ها که این ترکیب ها برای موارد مشخصی استفاده می شود ،خاصیت خود را از دست می دهند.\n\nتمام کلید های لیست شده بر روی تمام صفحه کلید ها وجود ندارد.
Extended_description-fi.utf-8: Näppäinasettelua halutaan usein vaihtaa paikallisen ja standardin Latin-näppäinasettelun välillä.\n\nHelpoin näistä vaihtoehdoista on ehkä oikea Alt tai Caps Lock (käytä jälkimmäisessä tapauksessa yhdistelmää Vaihto+Caps Lock normaaliin kirjainkoon vaihtoon). Toinen suosittu vaihtoehto on yhdistelmä Alt+Vaihto, joka toisaalta ei valinnan jälkeen toimi normaalisti Emacsissa tai muissa yhdistelmää erityistarkoituksiin käyttävissä ohjelmissa.\n\nKaikkia lueteltuja näppäimiä ei ole kaikissa näppäimistöissä.
Extended_description-fr.utf-8: Il est nécessaire de disposer d'un moyen pour basculer entre la disposition nationale et la disposition latine normale.\n\nLes choix les plus ergonomiques semblent être la touche Alt de droite et la touche de verrouillage majuscule (dans ce dernier cas, utilisez la combinaison Majuscule + Verrouillage majuscule pour le basculement habituel en mode majuscule). Un autre choix populaire est la combinaison Alt + Majuscule. Cependant, dans ce cas, elle perdra sa fonction habituelle dans Emacs ou dans tout autre programme qui l'utiliserait pour un besoin spécifique.\n\nLes touches indiquées ne font pas partie de tous les claviers.
Extended_description-ga.utf-8: Teastaíonn uait modh scoránaithe idir an leagan amach náisiúnta agus an gnáthleagan amach Laidineach.\n\nBaintear úsáid as an eochair Alt ar dheis nó Caps Lock go minic, ar chúiseanna eirgeanamaice (sa dara cás, úsáid Shift+Caps Lock le haghaidh an ghnáthoibríocht Caps Lock). Baintear úsáid as Alt+Shift go minic freisin; ach sa chás seo ní bheidh a ghnáthoibríocht ar fáil in Emacs nó i ríomhchláir eile a úsáideann é.\n\nNíl gach eochair anseo ar fáil ar gach méarchlár.
Extended_description-gl.utf-8: Ha precisar dun sistema para conmutar o teclado entre a disposición nacional e a disposición Latin estándar.\n\nPolo xeral escóllense Alt dereita ou Bloq maiús por ergonomía (neste último caso empregue a combinación de Maiús+Bloq maiús para conmutar entre maiúsculas/minúsculas). Alt+Maiús tamén é unha combinación popular, aínda que ha perder o seu significado habitual en Emacs e outros programas que a usen con outros propósitos.\n\nNon todas as teclas da listaxe están presentes en todos os teclados.
Extended_description-gu.utf-8: તમને રાષ્ટ્રિય દેખાવ અને પ્રમાણભૂત લેટિન દેખાવ વચ્ચે કીબોર્ડ અદલા-બદલી કરવાની રીત જોઇશે.\n\nજમણી અલ્ટર અથવા કેપ્સ લોક કળો મોટાભાગે ઇર્ગોનોમિક કારણોસર (પછીના કિસ્સામાં, શીફ્ટ + કેપ્સ લોકનું જોડાણ સામાન્ય કેપ્સની બદલી માટે) પસંદ કરવામાં આવે છે. અલ્ટર+શીફ્ટ એ પણ લોકપ્રિય જોડાણ છે; તે જોકે ઈમેક્સ અને બીજા ચોક્કસ જરૂરિયાત વાળા ઉપયોગ કરતાંકાર્યક્રમોમાં તેમની સામાન્ય વર્તણૂક ગુમાવી દેશે.\n\nયાદી કરેલ બધી કળો બધાં કીબોર્ડમાં હાજર હોતી નથી.
Extended_description-he.utf-8: חייבת להיות דרך עבורך להעביר את המקלדת בין הפריסה המקומית שלך לבין הפריסה הלטינית התקנית.\n\nמקובל לבחור במקשים Alt ימני או ב־Caps Lock מסיבות ארגונומיות (במקרה השני, נא להשתמש בצירוף Shift+Caps Lock לטובת החלפת מצב אותיות גדולות). הצירוף Alt+Shift הוא גם כן צירוף מקובל, אך צירוף זה יאבד את התנהגותו הרגילה ב־Emacs ובתכניות אחרות שמשתמשות בצירוף למטרות מיוחדות.\n\nלא כל המקשים המופיעים נמצאים בכל המקלדות.
Extended_description-hi.utf-8: देशी तथा लैटिन मोड के बीच परिवर्तन करने की विधि आवश्यक है।\n\nश्रम-दक्षता के लिए दाहिना ऑल्ट या कैप्स लॉक कुंजी चुने जाते हैं (कैप्स लॉक चुना जाए तो परिवर्तन के लिए शिफ़्ट+कैप्स लॉक का उपयोग करें)। ऑल्ट +शिफ़्ट का भी उपयोग किया जा सकता है, पर Emacs जैसे कई प्रोग्राम में इनका साधारण उपयोग असंभव हो जाता है।\n\nदिखाए गए सारी कुंजी सारी कुंजीपटल पर उपलब्ध नहीं हैं।
Extended_description-hr.utf-8: Trebati ćete način za promjenu između nacionalnog i standardnog latinskog rasporeda.\n\nTipke desni Alt ili Caps Lock često su odabrane iz ergonomskih razloga (u potonjem slučaju, koristite Shift+Caps Lock za uobičajeno uključivanje i isključivanje upisa velikih slova). Alt+Shift je također popularna kombinacija; međutim, može izgubiti svoje uobičajeno ponašanje u Emacsu i ostalim programima posebne namjene.\n\nNisu sve tipke s popisa prisutne na svim tipkovnicama.
Extended_description-hu.utf-8: Szükség lesz egy nemzeti és latin kiosztás közti váltást biztosító módra.\n\nA jobb Alt vagy Caps Lock billentyűk gyakran választják ergonomikus okokból (az utóbbi esetben használja a Shift+Caps Lock kombinációt a szokásos Caps váltáshoz). Az Alt+Shift szintén népszerű kombináció, azonban elveszti szokásos jelentését az Emacs és más őt speciálisan használó programok alatt.\n\nNem minden felsorolt billentyű létezik minden billentyűzeten.
Extended_description-id.utf-8: Anda membutuhkan cara untuk berpindah antara pola keyboard nasional dan standar Latin.\n\nTombol Alt Kanan atau Caps Lock biasanya digunakan dengan alasan ergonomis (dalam kasus Caps Lock, gunakan kombinasi Shift+Caps Lock untuk berpindah ke Caps Lock biasa). Alt+Shift juga biasa digunakan, tetapi hal ini akan menghilangkan sarana pada Emacs dan program lainnya yang juga menggunakan kombinasi yang sama.\n\nTidak semua yang ditampilkan tersedia di semua keyboard.
Extended_description-is.utf-8: Þú munt þurfa einhverja leið til að skipta á milli staðbundinar uppsetningar og þeirrar sjálfgefnu latnesku.\n\nHægri-Alt eða Caps Lock lyklarnir eru oft valdir vegna þægilegrar líkamsbeitingar (í síðara tilfellinu ætti að nota saman Shift+Caps Lock fyrir venjulega CapsLock víxlun). Alt+Shift er líka vinsæl samsetning; hún missir hinsvegar sína venjulegu hegðun í Emacs og öðrum forritum sem nota þá samsetningu til sérstakra aðgerða.\n\nEkki eru allir lyklar sem taldir eru upp til staðar á öllum lyklaborðum.
Extended_description-it.utf-8: Sarà necessario avere un modo per commutare la tastiera fra disposizione nazionale e disposizione latina standard.\n\nPer motivi ergonomici vengono spesso usati i tasti Alt destro o Bloc Maiusc (in quest'ultimo caso, usare la combinazione Maiusc + Bloc Maiusc per la commutazione Maiusc normale). Anche Alt + Maiusc è una combinazione diffusa, ma non funzionerà in Emacs e negli altri programmi che la usano per scopi specifici.\n\nNon tutti i tasti elencati sono presenti in tutte le tastiere.
Extended_description-ja.utf-8: ナショナル配置と標準ラテン配置間でキーボードを切り換える方法が必要です。\n\n右 Alt または Caps Lock キーが人間工学的な理由でよく使われます (後者の場合、普通の Caps 切り替えには Shift+Caps Lockの組み合わせを使うことになります)。Alt+Shift も一般的な組み合わせのひとつですが、この組み合わせを特に必要とするような Emacs その他プログラムでの通常の動作を損うことになります。\n\n示されたすべてのキーがすべてのキーボードで提供されるわけではありません。
Extended_description-kk.utf-8: Сізге пернетақтаның ұлттық пен латын жаймалары арасында ауысу жолы керек болады.\n\nОң жақ Alt немесе Caps Lock пернелері жиі ыңғайлылық есебінен қолданылады (соңғы жағдайда, қалыпты Caps ауыстыру үшін Shift+Caps Lock қолданылады). Alt+Shift тіркесі де жиі қолданылады; бірақта, ол тіркесті қолданатын Emacs не басқа қолданбалар оны жоғалтатын болады.\n\nТізілген пернелердің барлығы барлық пернетақталарда кездесе бермейді.
Extended_description-km.utf-8: អ្នក​​ត្រូវ​ការ​វិធី​មួយ​ ដើម្បី​បិទ/បើក​ក្ដារចុច​រវាង​ប្លង់​ភាសា​ជាតិ និង​ប្លង់​ឡាតាំង​ស្តង់ដារ ។\n\nគ្រាប់ចុច​ជំនួស (Alt) ឬ​ប្ដូរ​ជាប់ (Caps Lock) ​ជា​រឿយៗ​ត្រូវ​បាន​ជ្រើស​សម្រាប់​ហេតុផល ergonomic (នៅក្នុង​លក្ខណៈ​អក្សរ ប្រើ​បន្សំ​គ្រាប់ចុច​ប្ដូរ (Shift)+ ប្ដូរ​ជាប់ (Caps Lock) សម្រាប់​បិទ/បើក​ប្ដូរ​ជាប់ (Caps)) ។ ជំនួស(Alt)+ប្ដូរ (Shift) គឺ​ជា​បន្សំ​ដ៏​មាន​ប្រជាប្រិយភាព វា​នឹង​បាត់បង់​ឥរិយាបថ​ធម្មតា​របស់​វា​នៅ​ក្នុង Emacs និង​កម្មវិធី​ផ្សេង​ៗ​ទៀត​ដែលប្រើ​វា​សម្រាប់​តម្រូវការ​ជាក់លាក់​ ។\n\nមិនមែន​គ្រប់​ចុច​ដែល​បាន​រាយ​ទាំងអស់​បង្ហាញ​នៅ​លើ​ក្ដារចុច​ទាំង​អស់​ទេ ។
Extended_description-kn.utf-8: ನಿಮಗೆ ರಾಷ್ಟ್ರೀಯ ಹಾಗು ಲ್ಯಾಟಿನ್ ವಿಧಾನಗಳ ನಡುವೆ ಕೀಲಿಮಣೆಯನ್ನು ಅದಲುಬದಲು ಮಾಡಲು ಒಂದು ದಾರಿ ಬೇಕಾಗಬಹುದು\n\nಬಲ ಆಲ್ಟ್ ಅಥವಾ ಕ್ಯಪ್ಸ್ ಲಾಕ್ ಕೀಲಿಗಳನ್ನು ಸಾಮಾನ್ಯವಾಗಿ ದಕ್ಷತಾಶಾಸ್ತ್ರದ ಕಾರಣಗಳಿಂದಾಗಿ ಆಯ್ಕೆ ಮಾಡಲಾಗುತ್ತದೆ (ಎರಡನೆ ಸಂಧರ್ಭದಲ್ಲಿ ಸಮಾನ್ಯ ಕ್ಯಾಪ್ಸ್ ಅದಲು-ಬದಲು ಮಾಡಲು ಶಿಫ್ಟ್ + ಕ್ಯಾಪ್ಸ್ ಲಾಕ್  ಸಂಯೋಜನೆಯನ್ನು ಬಳಸಿ)\n\nಪಟ್ಟಿ ಮಾಡಿದ ಎಲ್ಲಾ ಕೀಲಿಗಳು ಎಲ್ಲ ಕೀಲಿಮಣೆಗಳ ಮೇಲೆ ಇರಬೇಕೆಂದಿಲ್ಲ
Extended_description-ko.utf-8: 지역 키보드 배치와 기본 영문 키보드 사이에 토글할 방법이 필요합니다.\n\n오른쪽 Alt 또는 Caps Lock 키를 (사용하기 편리하므로) 주로 사용합니다. (Caps Lock 키를 사용할 경우 일반 Caps Lock 토글 목적으로는 Shift+Caps Lock을 사용합니다.) Alt+Shift 키도 많이 사용하는 조합이지만, 이맥스 및 기타 프로그램의 기능에서 이 키 조합을 사용할 수 없게 됩니다.\n\n키보드에 따라 목록의 키가 모두 없는 키보드도 있습니다.
Extended_description-ku.utf-8: Ji bo guherandina di navbera neteweyî û latîniya standard de ji te re rêbazek divê.\n\nBişkojên Rast Alt an jî Caps Lock ji ber sedemên ergonomîk têne hilbijartin (di nivîsandinê de kombînasyona Shift+Caps Lock ji bo guherandina asayî ya Capsê de bi kar bîne). Her wiha Alt+Shift kombînasyona populer e.\n\nHişyarbe ku bişkojên lîstekirî di hemû klavyeyan de tune ne.
Extended_description-lo.utf-8: ທ່ານຈະຕ້ອງມີວິທີການສັບປ່ຽນໂຄງຮ່າງແປ້ນພິມລະຫວ່າງປະເທດແລະຮູບແບບລາຕິນມາດຕະຖານ\n\nAlt ຂວາຫລືປຸ່ມ Caps Lock ຖືກເລືອກສ່ວນຫລາຍຈະດ້ວຍເຫດຜົນທາງວິທະຍາສາດ (ໃນກໍລະນີຫລັງນີ້ໃຊ້ປະສົມປະສານລະຫວ່າງ Shift+Caps Lock ເພື່ອສັບປ່ຽນCaps ປົກກະຕິ). Alt+Shift ນີ້ຍັງມີການຮ່ວມກັນທີ່ນິຍົມໃຊ້ກັນກໍ່ຈະສູນເສຍ ແຕ່ພຶດຕິກຳປົກກະຕິໃນ Emacs ແລະໂປຣແກມອື່ນໆ ທີ່ໃຊ້ສຳຫລັບຄວາມຕ້ອງການສະເພາະ\n\nບໍ່ທັ້ງໝົດຄີລະບຸໄວ້ນີ້ສະແດງເທິງແປ້ນທັ້ງໝົດ
Extended_description-lt.utf-8: Jums prireiks būdo perjungti klaviatūros išdėstymą iš nacionalinio į bazinį lotynišką ir atgal.\n\nErgonomikos sumetimais dažnai pasirenkamas dešinysis Alt arba Didž klavišas (pastaruoju atveju didžiosios raidės gali būti fiksuojamos klavišų kombinacija Lyg2+Didž). Taip pat populiari Alt+Lyg2 kombinacija, tačiau tuomet ji praranda savo įprastą funkciją „Emacs“ ir kitose ją naudojančiose programose.\n\nNe visus išvardytus klavišus galima rasti visose klaviatūrose.
Extended_description-lv.utf-8: Ar šo taustiņu kombināciju varēs pārslēgties starp izvēlēto nacionālo tastatūras izkārtojumu un standarta latīņu izkārtojumu.\n\nErgonomisku apsvērumu dēļ bieži tiek lietoti taustiņi Labais Alt un Caps Lock (izvēloties šo variantu var lietot Shift+Caps Lock, lai izmantotu standarta Caps Lock funkciju). Bieži tiek lietota arī taustiņu kombinācija Alt+Shift; taču tad tiek zaudēta iespēja lietot šo kombināciju Emacs programmā un dažās citos specifiskos pielietojumos.\n\nNe visi taustiņu sarakstā ir pieejamas uz visām tastatūrām.
Extended_description-mk.utf-8: Ќе Ви треба начин да менувате меѓу националниот и стандардниот латиничен распоред.\n\nRight Alt или Caps Lock копчињата се често бирани поради ергономски причини (во вториот случај, користете ја комбинацијата Shift+Caps Lock за нормално Caps менување). Alt+Shift е исто така популарна комбинација; но ќе го изгуби вообичаеното однесување во Emacs и други програми кои ја користат за специфични потреби.\n\nНекои тастатури ги немаат сите прикажани копчиња.
Extended_description-ml.utf-8: സാധാരണ കാണുന്ന ലാറ്റിന്‍ വിന്യാസവും ദേശീയ വിന്യാസവും തമ്മില്‍ മാറ്റുന്നതിനു് നിങ്ങളൊരു വഴി കാണണം.\n\nആരോഗ്യ കാരണങ്ങളാല്‍ വലതുവശത്തെ ആള്‍ട്ട് അല്ലെങ്കില്‍ കാപ്സ് ലോക്ക് കീകളാണു് സാധാരണയായി എടുക്കാറു് (രണ്ടാമത്തേതാണെങ്കില്‍ ഷിഫ്റ്റ് + കാപ്സ് ലോക്ക് എന്നിവ ഒന്നിച്ചുപയോഗിച്ചു് സാധാരണ കാപ്സ് ലോക്ക് ഉപയോഗം നടത്താം). ആള്‍ട്ട് + ഷിഫ്റ്റ് എന്നതും സാധാരണയായി തെരഞ്ഞെടുക്കുന്നതാണു്; പക്ഷേ പ്രത്യേകാവശ്യത്തിനു് ഇവയുപയോഗിയ്ക്കുന്ന ഈമാക്സിലും മറ്റു പ്രോഗ്രാമുകളിലും ഇതിന്റെ സാധാരണ പെരുമാറ്റം നഷ്ടപ്പെടും.\n\nനിങ്ങള്‍ നല്‍കിയ കീകളെല്ലാം എല്ലാ കീബോര്‍ഡുകളിലുമുള്ളതല്ല.
Extended_description-mr.utf-8: नॅशनल आराखडा व प्रमाण लॅटिन आराखडा यांदरम्यान टॉगलिंग करण्यासाठी आपल्याला एखादी पद्धत ठरवणे गरजेचे आहे.\n\nसोयीकरिता उजवी Alt वा Caps Lock कळी या कळी बहुतेकदा निवडल्या जातात ( नंतरच्या केसमध्ये, नेहमीच्या Caps टॉगलकरिता Shift+Caps Lock संयोग वापरा). Alt+Shift हा संयोगसुद्धा प्रसिद्ध आहे; पण त्यामुळे त्याचे Emacs व अन्य प्रोग्रॅम मधील विशिष्ट गरजां करिता वापरले जाणारे नेहमीचे वर्तन बंद होईल.\n\nनोंदलेल्या सर्व कळी सर्वच कळफलकांवर उपलब्ध असतातच असे नाही.
Extended_description-nb.utf-8: Du trenger en måte å skifte mellom tastatur med nasjonal utforming og standard latinsk utformingen.\n\nHøyre Alt eller Caps Lock brukes ofte av ergonomiske grunner. Alt + Shift er også en populær kombinasjon. Den vil imidlertid miste sin vanlig oppførsel i Emacs og andre program som bruker kombinasjon internt.\n\nIkke alle listede taster fins på alle tastatur.
Extended_description-ne.utf-8: देशी तथा लैटिन मोड को बीचमा परिवर्तन गर्ने एक तरिका आवश्यक छ.\n\nदाहिने Alt वा क्याप्स लक कुञ्जीहरू अक्सर ergonomic कारणहरूका लागि चयन गरिन्छ (पछिल्लो अवस्थामा, सामान्य Caps टगलका लागि Shift + Caps Lock को प्रयोग गर्नुहोस्)। Alt + Shift पनि एक लोकप्रिय संयोजन हो। यो तथापि इमैक र अन्य कार्यक्रमहरूमा यसको सामान्य व्यवहार गुमाउने छ जुन यसको विशिष्ट आवश्यकताका लागि प्रयोग गर्दछ।\n\nसबै सूचीबद्ध कुञ्जीहरू सबै कीबोर्डमा रहेका छैनन्।
Extended_description-nl.utf-8: Er is een methode nodig om het toetsenbord te kunnen schakelen tussen de nationale indeling en de standaard Latijnse indeling.\n\nHiervoor worden om ergonomische redenen vaak de toetsen Alt-Rechts of Caps Lock gekozen (gebruik in het laatste geval de combinatie Shift+Caps Lock om de normale Caps Lock te schakelen). Alt+Shift is ook een populaire combinatie, maar dat zal dan wel zijn functie in Emacs en andere programma's waar het een bijzondere functie heeft verliezen.\n\nNiet alle vermelde toetsen komen voor op alle toetsenborden.
Extended_description-nn.utf-8: Du treng ein måte å skifte tastaturet mellom nasjonal utforming og standard latinsk utforming.\n\nHøgre Alt eller Caps Lock blir ofte brukt av ergonomiske grunnar (i det sistnevnte tilfelle, bruk kombinasjonen Shift + Caps Lock for vanleg Caps-oppførsel). Alt+Shift er òg ein vanleg kombinasjon, men den mister den vanlege oppførselen i Emacs og andre program som bruker den av særskilde grunnar.\n\nIkkje alle oppgitte tastar finst på alle tastatur.
Extended_description-no.utf-8: Du trenger en måte å skifte mellom tastatur med nasjonal utforming og standard latinsk utformingen.\n\nHøyre Alt eller Caps Lock brukes ofte av ergonomiske grunner. Alt + Shift er også en populær kombinasjon. Den vil imidlertid miste sin vanlig oppførsel i Emacs og andre program som bruker kombinasjon internt.\n\nIkke alle listede taster fins på alle tastatur.
Extended_description-pa.utf-8: ਤੁਹਾਨੂੰ ਰਾਸ਼ਟਰੀ ਲੇਆਉਟ ਤੇ ਸਟੈਂਡਰਡ ਲਾਤੀਨੀ ਲੇਆਉਟ ਵਿੱਚ ਬਦਲਣ ਦਾ ਤਰੀਕਾ ਚਾਹੀਦਾ ਹੋਵੇਗਾ।\n\nਏਰਗੋਨੋਮਿਕ ਕਾਰਨਾਂ ਕਰਕੇ ਸੱਜੀ Alt ਜਾਂ Caps Lock ਸਵਿੱਚ ਆਮ ਤੋਰ ਤੇ ਚੁਣੇ ਜਾਂਦੇ ਹਨ (ਮਗਰਲੇ ਕੇਸ ਵਿੱਚ Shift+Caps Lock ਆਮ Caps ਬਦਲਣ ਲਈ ਵਰਤੋ)। Alt+Shift ਦਾ ਜੋੜ ਆਮ ਵਰਤਿਆ ਜਾਂਦਾ ਏ, ਪਰ ਈਮੈਕਸ ਤੇ ਹੋਰ ਪਰੋਗਰਾਮ, ਜਿੰਨਾ ਦੀਆਂ ਇਸ ਜੋੜ ਤੋਂ ਸਪੈਸ਼ਲ ਲੋੜ ਏ, ਵਿੱਚ ਇਹ ਆਪਣਾ ਆਮ ਸੁਭਾਅ ਗਵਾ ਦਿੰਦਾ ਹੈ।\n\nਸਾਰੀਆਂ ਦਰਸਾਈਆਂ ਸਵਿੱਚਾਂ ਇਸ ਕੀ-ਬੋਰਡ ਤੇ ਮੋਜੂਦ ਨਹੀਂ ।
Extended_description-pl.utf-8: Potrzebny będzie sposób przełączania klawiatury pomiędzy układem narodowym a standardowym układem łacińskim.\n\nZ powodów ergonomii często wybiera się prawy klawisz Alt lub Caps Lock (w tym drugim przypadku zwykła funkcja Caps Lock jest dostępna w kombinacji z klawiszem Shift). Innym popularnym ustawieniem jest Alt+Shift, jednak ta kombinacja straci swoje zachowanie w programie Emacs lub innych, które używają je do swoich potrzeb.\n\nNie wszystkie wymienione klawisze są dostępne na wszystkich klawiaturach.
Extended_description-pt.utf-8: Precisa de um modo de alternar o teclado entre a disposição nacional e o padrão Latin.\n\nAltGr ou Caps Lock são escolhidos muitas vezes por razões ergonómicas (neste último caso para ligar as maiúsculas usa-se Shift+Caps Lock). Alt+Shift é também uma combinação popular; no entanto perderá o seu significado habitual no Emacs e noutros programas que fazem uso dela.\n\nNem todas as teclas referidas estão presentes em todos os teclados.
Extended_description-pt_br.utf-8: Você precisará de uma maneira para alternar o teclado entre o layout nacional e o layout padrão Latin.\n\nAs teclas Alt Direito ou Caps Lock são frequentemente escolhidas por razões ergonômicas (neste último caso, use a combinação Shift+Caps Lock para uma alternância normal de Caps). Alt+Shift também é uma combinação popular; no entanto, ela perderá seu comportamento habitual no Emacs e em outros programas que a usam para necessidades específicas.\n\nNem todas as teclas listadas estão presentes em todos os teclados.
Extended_description-ro.utf-8: Veți avea nevoie de o metodă de a comuta tastatura între aranjamentul național și cel standard latin.\n\nTastele Alt dreapta sau Caps Lock sunt frecvent alese din motive de ergonomie (pentru cea din urmă, folosiți Shift+Caps Lock pentru comutarea între litere mici și litere mari). Alt+Shift este și ea o combinație populară; totuși i se va pierde comportamentul în Emacs și în alte programe care o folosesc deja.\n\nUnele din tastele afișate aici pot lipsi de pe unele tastaturi.
Extended_description-ru.utf-8: Вам нужно указать способ переключения клавиатуры между национальной раскладкой и стандартной латинской раскладкой.\n\nНаиболее эргономичным способом считаются правая клавиша Alt или Caps Lock (в последнем случае для переключения между заглавными и строчными буквами используется комбинация Shift+Caps Lock). Ещё одна популярная комбинация: Alt+Shift; заметим, что в этом случае комбинация Alt+Shift потеряет своё привычное действие в Emacs и других, использующих её, программах.\n\nНе на всех клавиатурах есть перечисленные клавиши.
Extended_description-si.utf-8: ඔබට යතුරුපුවරුව ජාතික සැකැස්ම හා සම්මත ලතින් සැකැස්ම අතර මාරුවීමේ ක්‍රමයක් අවශ්‍යයි.\n\nදකුණු Alt යතුර හෝ Caps අගුළු යතුර බොහෝවිට කාර්යක්‍ෂමතා හේතූන් සඳහා යොදාගැනේ (දෙවන කරුණේදී, Shift+Caps අගුළු යතුරු සංයුක්තය සාමාන්‍ය Caps මාරුවට යොදාගැනේ). Alt +Shift යනුද ප්‍රකට සංයුක්තයකි; කෙසේවුවත් එය Emacs හෝ එවැනි විශේෂ කාර්යයන් භාවිත වන වැඩසටහන් වලදී සාමාන්‍ය හැසිරීම හැරදමයි.\n\nලැයිස්තු ගත කර ඇති සියළුම යතුරු සෑම යතුරුපුවරුවකම දක්නට නැත.
Extended_description-sk.utf-8: Budete potrebovať spôsob prepínania medzi národným rozložením a štandardným rozložením Latin.\n\nZ  ergonomických dôvodov sa často sa volia klávesy pravý Alt alebo Caps Lock (v druhom prípade použite na normálne prepnutie veľkosti písmen Shift+Caps Lock). Alt+Shift je tiež populárna kombinácia; tým však stratí mnoho zo svojho pôvodného významu v Emacs a iným programoch, ktoré ho využívajú.\n\nNie všetky uvedené klávesy sa nachádzajú na všetkých klávesniciach.
Extended_description-sl.utf-8: Potrebujete način, da tipkovnica preide iz narodne razporeditve na standardno razporeditev Latin.\n\nIz ergonomskih razlogov se pogosto izbere Desno izmenjalko ali Caps Lock (v tem primeru uporabite kombinacijo Dvigalka+Caps Lock za običajen preklop velikih črk). Izmenjalka+Dvigalka je tudi razširjena kombinacija; pri tem se bo pa izgubila običajna uporaba v programu Emacs in drugih programih, ki to kombinacijo uporabljajo za svoje specifičen potrebe.\n\nTipke na spisku niso vedno prisotne na vseh tipkovnicah.
Extended_description-sq.utf-8: Ju duhet një mënyrë për të këmbyer tastierën mes paraqitjes nacionale dheparaqitjes standarde Latine\n\nAlt i djathte ose Caps lock zgjidhen zakonisht per arsye ergonomike (në rastin e fundit, përdor kombinimin Shift+Caps Lock për Caps toggle normal). Alt+Shift është gjithashtu një kombinim i njohur; megjithatë do te humbasi sjelljen e tij të zakonshme në Emacs dhe programe të tjera mund ta përdorin për nevoja specifike.\n\nJo të gjithë çelësat e rradhitur janë prezent në të gjithe tastierët.
Extended_description-sr.utf-8: Требаће вам начин за пребацивање тастатуре на национални или латинични распоред.\n\nДесни Alt или Caps Lock тастери обично се користе због ергономских разлога (уколико се користи Caps Lock, пребацивање на велика и мала слова се врши помоћу Shift+Caps Lock). Популарна комбинација је и Alt+Shift, али се тако губе неке функције Emacs едитора и осталих програма који користе ту комбинацију.\n\nНису сви излистани тастери присутни на свим тастатурама.
Extended_description-sr@latin.utf-8: Trebaće vam način za prebacivanje tastature na nacionalni ili latinični raspored.\n\nDesni Alt ili Caps Lock tasteri obično se koriste zbog ergonomskih razloga (ukoliko se koristi Caps Lock, prebacivanje na velika i mala slova se vrši pomoću Shift+Caps Lock). Popularna kombinacija je i Alt+Shift, ali se tako gube neke funkcije Emacs editora i ostalih programa koji koriste tu kombinaciju.\n\nNisu svi izlistani tasteri prisutni na svim tastaturama.
Extended_description-sv.utf-8: Du behöver ett sätt att byta tangentbordslayout mellan din nationella layout och Latin som är standardvalet.\n\nDet mest ergonomiska valet verkar vara höger Alt- och Caps Lock-tangenterna. Ett annat vanligt val är kombinationen Alt+Shift, här ska man dock vara medveten om att en del program (t.ex. Emacs) använder sig av denna kombination till andra saker och dessa blir därmed omöjliga att utföra.\n\nKom ihåg att alla tangenterna som anges här inte finns på alla tangentbord.
Extended_description-ta.utf-8: தேசிய இட அமைவு மற்றும் செந்தர இலத்தீன் இட அமைவுகளுக்கு இடையே பாங்குகளுக்கு நிலை மாற்றுதலுக்கு ஒரு முறை தேவையிருக்கும்.\n\nஉயிரியல்சார் தொழிலமைப்பு காரணங்களுக்காக வலது ஆல்ட் அல்லது கேப்ஸ் விசைகள் தேர்ந்தெடுக்கப்படுகின்றன. பின்னதில் வழக்கமான மேல் கீழ் நிலை எழுத்து நிலை மாற்றத்துக்கு ஷிப்ட்+கேப்ஸ் பூட்டு விசைஜோடியை பயன்படுத்தவும். ஆல்ட்+ஷிப்ட் கூட பரவலான ஜோடியாகும். ஆயின் ஈமேக்ஸ் மற்றும் சில நிரல்களில் இவைகுறிப்பிட்ட தேவைகளுக்கு பயனாவதால் அவற்றின் வழக்கமான நடத்தை மாறிவிடும்\n\nபட்டியலிட்ட அனைத்து விசைகளும் அனத்து விசைப்பலகைகளிலும் இரா.
Extended_description-te.utf-8: కీ బోర్డు ను జాతీయ లేఔట్ మరియు ప్రామాణిక లాటిన్ లేఔట్ కి మార్చుటకు పద్ధతి కావాలి.\n\nకుడి ఆల్ట్ లేక కేప్స్ లాక్  కీలు సౌకర్యవంతంగా వుండటానికి  ఎంచుకుంటారు(రెండవది వాడేటప్పుడు షిఫ్ట్+ కేప్స్ లాక్ వాడి మామూలు కేప్స్ లాక్ కి మారవచ్చు). ఆల్ట్ + షిఫ్ట్ కూడా ప్రజాదరణ పొందినది; కాని ఈమాక్స్ మరియి ఇతర ప్రోగ్రాములలో ప్రత్యేక అవసరం కోసం వాడబడుతుంది.\n\nజాబితా లోని కీలన్నీ అన్ని కీబోర్డు లేఔట్ల మీద లేవు.
Extended_description-tg.utf-8: Ба шумо усуле лозим мешавад, ки ҳарфкалидро дар байни тарҳбандии миллӣ ва тарҳбандии стандартии лотинӣ интихоб мекунад.\n\nТугмаҳои Alt-и рост ё Caps Lock одатан барои сабабҳои эргономӣ интихоб карда мешаванд (дар ҳолати пешина, вобастагии тугмаҳои Shift+Caps Lock-ро барои интихобкунии муқаррарии ҳарфҳои калон истифода баред). Alt+Shift низ вобастагии машҳур мебошад; аммо, он рафтори оддии худро дар Emacs ва барномаҳои дигаре, ки онро барои эҳтиёҷоти мушаххаси худ истифода мебаранд, гум мекунад.\n\nНа ҳамаи тугмаҳои номбаршуда дар ҳамаи ҳарфкалидҳо мавҷуданд.
Extended_description-th.utf-8: คุณต้องกำหนดวิธีสลับภาษาแป้นพิมพ์ ระหว่างผังภาษาท้องถิ่นกับผังละตินมาตรฐาน\n\nAlt ขวา และ Caps Lock เป็นตัวเลือกที่มักจะเลือกกัน ด้วยเหตุผลด้านสุขลักษณะ (โดยในกรณีหลัง คุณสามารถใช้ Shift+Caps Lock สำหรับการยกแคร่ค้างตามปกติได้) ในขณะที่ Alt+Shift ก็เป็นตัวเลือกยอดนิยม แต่การใช้ปุ่มดังกล่าวจะทำให้ไม่สามารถใช้ Alt+Shift ตามปกติใน Emacs และโปรแกรมอื่นๆ ที่ใช้ปุ่มดังกล่าวได้\n\nปุ่มในรายชื่อนี้ไม่ได้มีในทุกแป้นพิมพ์
Extended_description-tr.utf-8: Klavyenizde ulusal düzen ve standart Latin düzeni arasında geçiş yapabilmek için bir yönteme ihtiyacınız olacak.\n\nSağ Alt ya da Caps Lock tuşları genelde kullanımı kolay olduğu için tercih edilir. (Caps Lock'ı tercih ettiğiniz takdirde bu tuşu normal işlevle kullanmak için Shift+Caps Lock bileşimini kullanın.) Alt+Shift de popüler bir bileşimdir, ama bu durumda bu bileşimi kullanan Emacs ve diğer programların bazı işlevlerini kullanamayabilirsiniz.\n\nListelenen tuşların tümü her klavyede bulunmayabilir.
Extended_description-ug.utf-8: ھەرپتاختىڭىزنى دۆلەتلىك جايلاشتۇرۇش بىلەن ئۆلچەملىك لاتىنچە جايلاشتۇرۇش ئارىسىدا ئالماشتۇرۇش ئۇسۇلىغا موھتاج بولىسىز.\n\nئوڭ تەرەپتىكى Alt ياكى Caps Lock كۆپىنچە ھاللاردا ئىنسان بەدەن قۇرۇلمىسى سەۋەبلىرىدىن تاللىنىلىدۇ (كېيىنكى ئەھۋالدا، نورمال Caps ئالماشتۇرۇش مەشغۇلاتىنى Shift+Caps Lock كۇنۇپكا بىرىكمىسى ئارقىلىق ئېلىپ بېرىڭ). Alt+Shift مۇ كۆپ ئۇچرايدىغان كۇنۇپكا بىرىكمىسى؛ ئەمما بۇ كۇنۇپكا بىرىكمىسى Emacs ۋە باشقا ئۇنىڭغا ئالاھىدە ئېھتىياجى بار پروگراممىلاردا ئۆزىنىڭ ئادەتتىكى ئىقتىدارىدىن مەھرۇم بولىدۇ.\n\nكۆرسىتىلگەن كۇنۇپكىلارنىڭ ھەممىسى بارلىق كۇنۇپكا تاختىلىرىدا بار بولۇشى ناتايىن.
Extended_description-uk.utf-8: Потрібно вказати спосіб перемикання між національною та стандартною латинською розкладкою клавіатури.\n\nПраву клавішу Alt або Caps Lock часто обирають з огляду на ергономічність (в останньому випадку звичний функціонал Caps Lock замінює комбінація клавіш Shift+Caps Lock). Досить популярною також є комбінація Alt+Shift; проте при цьому втрачається її звична поведінка в Emacs та інших програмах, в яких вона використовується для специфічних потреб.\n\nНе всі перелічені клавіші наявні на всіх клавіатурах.
Extended_description-vi.utf-8: Bạn cần một phương pháp chuyển đổi giữa bố trí quốc gia và bố trí La-tinh tiêu chuẩn.\n\nPhím Alt bên phải hay Caps Lock thường được chọn vì lý do tối ưu nhân tố (trong trường hợp sau, dùng tổ hợp phím Shift+Caps Lock để bật/tắt chữ
package Tie::File;
require 5.005;
use Carp ':DEFAULT', 'confess';
use POSIX 'SEEK_SET';
use Fcntl 'O_CREAT', 'O_RDWR', 'LOCK_EX', 'LOCK_SH', 'O_WRONLY', 'O_RDONLY';
sub O_ACCMODE () { O_RDONLY | O_RDWR | O_WRONLY }


$VERSION = "1.02";
my $DEFAULT_MEMORY_SIZE = 1<<21;    # 2 megabytes
my $DEFAULT_AUTODEFER_THRESHHOLD = 3; # 3 records
my $DEFAULT_AUTODEFER_FILELEN_THRESHHOLD = 65536; # 16 disk blocksful

my %good_opt = map {$_ => 1, "-$_" => 1}
                 qw(memory dw_size mode recsep discipline 
                    autodefer autochomp autodefer_threshhold concurrent);

sub TIEARRAY {
  if (@_ % 2 != 0) {
    croak "usage: tie \@array, $_[0], filename, [option => value]...";
  }
  my ($pack, $file, %opts) = @_;

  # transform '-foo' keys into 'foo' keys
  for my $key (keys %opts) {
    unless ($good_opt{$key}) {
      croak("$pack: Unrecognized option '$key'\n");
    }
    my $okey = $key;
    if ($key =~ s/^-+//) {
      $opts{$key} = delete $opts{$okey};
    }
  }

  if ($opts{concurrent}) {
    croak("$pack: concurrent access not supported yet\n");
  }

  unless (defined $opts{memory}) {
    # default is the larger of the default cache size and the 
    # deferred-write buffer size (if specified)
    $opts{memory} = $DEFAULT_MEMORY_SIZE;
    $opts{memory} = $opts{dw_size}
      if defined $opts{dw_size} && $opts{dw_size} > $DEFAULT_MEMORY_SIZE;
    # Dora Winifred Read
  }
  $opts{dw_size} = $opts{memory} unless defined $opts{dw_size};
  if ($opts{dw_size} > $opts{memory}) {
      croak("$pack: dw_size may not be larger than total memory allocation\n");
  }
  # are we in deferred-write mode?
  $opts{defer} = 0 unless defined $opts{defer};
  $opts{deferred} = {};         # no records are presently deferred
  $opts{deferred_s} = 0;        # count of total bytes in ->{deferred}
  $opts{deferred_max} = -1;     # empty

  # What's a good way to arrange that this class can be overridden?
  $opts{cache} = Tie::File::Cache->new($opts{memory});

  # autodeferment is enabled by default
  $opts{autodefer} = 1 unless defined $opts{autodefer};
  $opts{autodeferring} = 0;     # but is not initially active
  $opts{ad_history} = [];
  $opts{autodefer_threshhold} = $DEFAULT_AUTODEFER_THRESHHOLD
    unless defined $opts{autodefer_threshhold};
  $opts{autodefer_filelen_threshhold} = $DEFAULT_AUTODEFER_FILELEN_THRESHHOLD
    unless defined $opts{autodefer_filelen_threshhold};

  $opts{offsets} = [0];
  $opts{filename} = $file;
  unless (defined $opts{recsep}) { 
    $opts{recsep} = _default_recsep();
  }
  $opts{recseplen} = length($opts{recsep});
  if ($opts{recseplen} == 0) {
    croak "Empty record separator not supported by $pack";
  }

  $opts{autochomp} = 1 unless defined $opts{autochomp};

  $opts{mode} = O_CREAT|O_RDWR unless defined $opts{mode};
  $opts{rdonly} = (($opts{mode} & O_ACCMODE) == O_RDONLY);
  $opts{sawlastrec} = undef;

  my $fh;

  if (UNIVERSAL::isa($file, 'GLOB')) {
    # We use 1 here on the theory that some systems 
    # may not indicate failure if we use 0.
    # MSWin32 does not indicate failure with 0, but I don't know if
    # it will indicate failure with 1 or not.
    unless (seek $file, 1, SEEK_SET) {
      croak "$pack: your filehandle does not appear to be seekable";
    }
    seek $file, 0, SEEK_SET;    # put it back
    $fh = $file;                # setting binmode is the user's problem
  } elsif (ref $file) {
    croak "usage: tie \@array, $pack, filename, [option => value]...";
  } else {
    # $fh = \do { local *FH };  # XXX this is buggy
    if ($] < 5.006) {
	# perl 5.005 and earlier don't autovivify filehandles
	require Symbol;
	$fh = Symbol::gensym();
    }
    sysopen $fh, $file, $opts{mode}, 0666 or return;
    binmode $fh;
    ++$opts{ourfh};
  }
  { my $ofh = select $fh; $| = 1; select $ofh } # autoflush on write
  if (defined $opts{discipline} && $] >= 5.006) {
    # This avoids a compile-time warning under 5.005
    eval 'binmode($fh, $opts{discipline})';
    croak $@ if $@ =~ /unknown discipline/i;
    die if $@;
  }
  $opts{fh} = $fh;

  bless \%opts => $pack;
}

sub FETCH {
  my ($self, $n) = @_;
  my $rec;

  # check the defer buffer
  $rec = $self->{deferred}{$n} if exists $self->{deferred}{$n};
  $rec = $self->_fetch($n) unless defined $rec;

  # inlined _chomp1
  substr($rec, - $self->{recseplen}) = ""
    if defined $rec && $self->{autochomp};
  $rec;
}

# Chomp many records in-place; return nothing useful
sub _chomp {
  my $self = shift;
  return unless $self->{autochomp};
  if ($self->{autochomp}) {
    for (@_) {
      next unless defined;
      substr($_, - $self->{recseplen}) = "";
    }
  }
}

# Chomp one record in-place; return modified record
sub _chomp1 {
  my ($self, $rec) = @_;
  return $rec unless $self->{autochomp};
  return unless defined $rec;
  substr($rec, - $self->{recseplen}) = "";
  $rec;
}

sub _fetch {
  my ($self, $n) = @_;

  # check the record cache
  { my $cached = $self->{cache}->lookup($n);
    return $cached if defined $cached;
  }

  if ($#{$self->{offsets}} < $n) {
    return if $self->{eof};  # request for record beyond end of file
    my $o = $self->_fill_offsets_to($n);
    # If it's still undefined, there is no such record, so return 'undef'
    return unless defined $o;
  }

  my $fh = $self->{FH};
  $self->_seek($n);             # we can do this now that offsets is populated
  my $rec = $self->_read_record;

# If we happen to have just read the first record, check to see if
# the length of the record matches what 'tell' says.  If not, Tie::File
# won't work, and should drop dead.
#
#  if ($n == 0 && defined($rec) && tell($self->{fh}) != length($rec)) {
#    if (defined $self->{discipline}) {
#      croak "I/O discipline $self->{discipline} not supported";
#    } else {
#      croak "File encoding not supported";
#    }
#  }

  $self->{cache}->insert($n, $rec) if defined $rec && not $self->{flushing};
  $rec;
}

sub STORE {
  my ($self, $n, $rec) = @_;
  die "STORE called from _check_integrity!" if $DIAGNOSTIC;

  $self->_fixrecs($rec);

  if ($self->{autodefer}) {
    $self->_annotate_ad_history($n);
  }

  return $self->_store_deferred($n, $rec) if $self->_is_deferring;


  # We need this to decide whether the new record will fit
  # It incidentally populates the offsets table 
  # Note we have to do this before we alter the cache
  # 20020324 Wait, but this DOES alter the cache.  TODO BUG?
  my $oldrec = $self->_fetch($n);

  if (not defined $oldrec) {
    # We're storing a record beyond the end of the file
    $self->_extend_file_to($n+1);
    $oldrec = $self->{recsep};
  }
#  return if $oldrec eq $rec;    # don't bother
  my $len_diff = length($rec) - length($oldrec);

  # length($oldrec) here is not consistent with text mode  TODO XXX BUG
  $self->_mtwrite($rec, $self->{offsets}[$n], length($oldrec));
  $self->_oadjust([$n, 1, $rec]);
  $self->{cache}->update($n, $rec);
}

sub _store_deferred {
  my ($self, $n, $rec) = @_;
  $self->{cache}->remove($n);
  my $old_deferred = $self->{deferred}{$n};

  if (defined $self->{deferred_max} && $n > $self->{deferred_max}) {
    $self->{deferred_max} = $n;
  }
  $self->{deferred}{$n} = $rec;

  my $len_diff = length($rec);
  $len_diff -= length($old_deferred) if defined $old_deferred;
  $self->{deferred_s} += $len_diff;
  $self->{cache}->adj_limit(-$len_diff);
  if ($self->{deferred_s} > $self->{dw_size}) {
    $self->_flush;
  } elsif ($self->_cache_too_full) {
    $self->_cache_flush;
  }
}

# Remove a single record from the deferred-write buffer without writing it
# The record need not be present
sub _delete_deferred {
  my ($self, $n) = @_;
  my $rec = delete $self->{deferred}{$n};
  return unless defined $rec;

  if (defined $self->{deferred_max} 
      && $n == $self->{deferred_max}) {
    undef $self->{deferred_max};
  }

  $self->{deferred_s} -= length $rec;
  $self->{cache}->adj_limit(length $rec);
}

sub FETCHSIZE {
  my $self = shift;
  my $n = $self->{eof} ? $#{$self->{offsets}} : $self->_fill_offsets;

  my $top_deferred = $self->_defer_max;
  $n = $top_deferred+1 if defined $top_deferred && $n < $top_deferred+1;
  $n;
}

sub STORESIZE {
  my ($self, $len) = @_;

  if ($self->{autodefer}) {
    $self->_annotate_ad_history('STORESIZE');
  }

  my $olen = $self->FETCHSIZE;
  return if $len == $olen;      # Woo-hoo!

  # file gets longer
  if ($len > $olen) {
    if ($self->_is_deferring) {
      for ($olen .. $len-1) {
        $self->_store_deferred($_, $self->{recsep});
      }
    } else {
      $self->_extend_file_to($len);
    }
    return;
  }

  # file gets shorter
  if ($self->_is_deferring) {
    # TODO maybe replace this with map-plus-assignment?
    for (grep $_ >= $len, keys %{$self->{deferred}}) {
      $self->_delete_deferred($_);
    }
    $self->{deferred_max} = $len-1;
  }

  $self->_seek($len);
  $self->_chop_file;
  $#{$self->{offsets}} = $len;
#  $self->{offsets}[0] = 0;      # in case we just chopped this

  $self->{cache}->remove(grep $_ >= $len, $self->{cache}->ckeys);
}

### OPTIMIZE ME
### It should not be necessary to do FETCHSIZE
### Just seek to the end of the file.
sub PUSH {
  my $self = shift;
  $self->SPLICE($self->FETCHSIZE, scalar(@_), @_);

  # No need to return:
  #  $self->FETCHSIZE;  # because av.c takes care of this for me
}

sub POP {
  my $self = shift;
  my $size = $self->FETCHSIZE;
  return if $size == 0;
#  print STDERR "# POPPITY POP POP POP\n";
  scalar $self->SPLICE($size-1, 1);
}

sub SHIFT {
  my $self = shift;
  scalar $self->SPLICE(0, 1);
}

sub UNSHIFT {
  my $self = shift;
  $self->SPLICE(0, 0, @_);
  # $self->FETCHSIZE; # av.c takes care of this for me
}

sub CLEAR {
  my $self = shift;

  if ($self->{autodefer}) {
    $self->_annotate_ad_history('CLEAR');
  }

  $self->_seekb(0);
  $self->_chop_file;
    $self->{cache}->set_limit($self->{memory});
    $self->{cache}->empty;
  @{$self->{offsets}} = (0);
  %{$self->{deferred}}= ();
    $self->{deferred_s} = 0;
    $self->{deferred_max} = -1;
}

sub EXTEND {
  my ($self, $n) = @_;

  # No need to pre-extend anything in this case
  return if $self->_is_deferring;

  $self->_fill_offsets_to($n);
  $self->_extend_file_to($n);
}

sub DELETE {
  my ($self, $n) = @_;

  if ($self->{autodefer}) {
    $self->_annotate_ad_history('DELETE');
  }

  my $lastrec = $self->FETCHSIZE-1;
  my $rec = $self->FETCH($n);
  $self->_delete_deferred($n) if $self->_is_deferring;
  if ($n == $lastrec) {
    $self->_seek($n);
    $self->_chop_file;
    $#{$self->{offsets}}--;
    $self->{cache}->remove($n);
    # perhaps in this case I should also remove trailing null records?
    # 20020316
    # Note that delete @a[-3..-1] deletes the records in the wrong order,
    # so we only chop the very last one out of the file.  We could repair this
    # by tracking deleted records inside the object.
  } elsif ($n < $lastrec) {
    $self->STORE($n, "");
  }
  $rec;
}

sub EXISTS {
  my ($self, $n) = @_;
  return 1 if exists $self->{deferred}{$n};
  $n < $self->FETCHSIZE;
}

sub SPLICE {
  my $self = shift;

  if ($self->{autodefer}) {
    $self->_annotate_ad_history('SPLICE');
  }

  $self->_flush if $self->_is_deferring; # move this up?
  if (wantarray) {
    $self->_chomp(my @a = $self->_splice(@_));
    @a;
  } else {
    $self->_chomp1(scalar $self->_splice(@_));
  }
}

sub DESTROY {
  my $self = shift;
  $self->flush if $self->_is_deferring;
  $self->{cache}->delink if defined $self->{cache}; # break circular link
  if ($self->{fh} and $self->{ourfh}) {
      delete $self->{ourfh};
      close delete $self->{fh};
  }
}

sub _splice {
  my ($self, $pos, $nrecs, @data) = @_;
  my @result;

  $pos = 0 unless defined $pos;

  # Deal with negative and other out-of-range positions
  # Also set default for $nrecs 
  {
    my $oldsize = $self->FETCHSIZE;
    $nrecs = $oldsize unless defined $nrecs;
    my $oldpos = $pos;

    if ($pos < 0) {
      $pos += $oldsize;
      if ($pos < 0) {
        croak "Modification of non-creatable array value attempted, " .
              "subscript $oldpos";
      }
    }

    if ($pos > $oldsize) {
      return unless @data;
      $pos = $oldsize;          # This is what perl does for normal arrays
    }

    # The manual is very unclear here
    if ($nrecs < 0) {
      $nrecs = $oldsize - $pos + $nrecs;
      $nrecs = 0 if $nrecs < 0;
    }

    # nrecs is too big---it really means "until the end"
    # 20030507
    if ($nrecs + $pos > $oldsize) {
      $nrecs = $oldsize - $pos;
    }
  }

  $self->_fixrecs(@data);
  my $data = join '', @data;
  my $datalen = length $data;
  my $oldlen = 0;

  # compute length of data being removed
  for ($pos .. $pos+$nrecs-1) {
    last unless defined $self->_fill_offsets_to($_);
    my $rec = $self->_fetch($_);
    last unless defined $rec;
    push @result, $rec;

    # Why don't we just use length($rec) here?
    # Because that record might have come from the cache.  _splice
    # might have been called to flush out the deferred-write records,
    # and in this case length($rec) is the length of the record to be
    # *written*, not the length of the actual record in the file.  But
    # the offsets are still true. 20020322
    $oldlen += $self->{offsets}[$_+1] - $self->{offsets}[$_]
      if defined $self->{offsets}[$_+1];
  }
  $self->_fill_offsets_to($pos+$nrecs);

  # Modify the file
  $self->_mtwrite($data, $self->{offsets}[$pos], $oldlen);
  # Adjust the offsets table
  $self->_oadjust([$pos, $nrecs, @data]);

  { # Take this read cache stuff out into a separate function
    # You made a half-attempt to put it into _oadjust.  
    # Finish something like that up eventually.
    # STORE also needs to do something similarish

    # update the read cache, part 1
    # modified records
    for ($pos .. $pos+$nrecs-1) {
      my $new = $data[$_-$pos];
      if (defined $new) {
        $self->{cache}->update($_, $new);
      } else {
        $self->{cache}->remove($_);
      }
    }
    
    # update the read cache, part 2
    # moved records - records past the site of the change
    # need to be renumbered
    # Maybe merge this with the previous block?
    {
      my @oldkeys = grep $_ >= $pos + $nrecs, $self->{cache}->ckeys;
      my @newkeys = map $_-$nrecs+@data, @oldkeys;
      $self->{cache}->rekey(\@oldkeys, \@newkeys);
    }

    # Now there might be too much data in the cache, if we spliced out
    # some short records and spliced in some long ones.  If so, flush
    # the cache.
    $self->_cache_flush;
  }

  # Yes, the return value of 'splice' *is* actually this complicated
  wantarray ? @result : @result ? $result[-1] : undef;
}


# write data into the file
# $data is the data to be written.
# it should be written at position $pos, and should overwrite
# exactly $len of the following bytes.  
# Note that if length($data) > $len, the subsequent bytes will have to 
# be moved up, and if length($data) < $len, they will have to
# be moved down
sub _twrite {
  my ($self, $data, $pos, $len) = @_;

  unless (defined $pos) {
    die "\$pos was undefined in _twrite";
  }

  my $len_diff = length($data) - $len;

  if ($len_diff == 0) {          # Woo-hoo!
    my $fh = $self->{fh};
    $self->_seekb($pos);
    $self->_write_record($data);
    return;                     # well, that was easy.
  }

  # the two records are of different lengths
  # our strategy here: rewrite the tail of the file,
  # reading ahead one buffer at a time
  # $bufsize is required to be at least as large as the data we're overwriting
  my $bufsize = _bufsize($len_diff);
  my ($writepos, $readpos) = ($pos, $pos+$len);
  my $next_block;
  my $more_data;

  # Seems like there ought to be a way to avoid the repeated code
  # and the special case here.  The read(1) is also a little weird.
  # Think about this.
  do {
    $self->_seekb($readpos);
    my $br = read $self->{fh}, $next_block, $bufsize;
    $more_data = read $self->{fh}, my($dummy), 1;
    $self->_seekb($writepos);
    $self->_write_record($data);
    $readpos += $br;
    $writepos += length $data;
    $data = $next_block;
  } while $more_data;
  $self->_seekb($writepos);
  $self->_write_record($next_block);

  # There might be leftover data at the end of the file
  $self->_chop_file if $len_diff < 0;
}

# _iwrite(D, S, E)
# Insert text D at position S.
# Let C = E-S-|D|.  If C < 0; die.  
# Data in [S,S+C) is copied to [S+D,S+D+C) = [S+D,E).
# Data in [S+C = E-D, E) is returned.  Data in [E, oo) is untouched.
#
# In a later version, don't read the entire intervening area into
# memory at once; do the copying block by block.
sub _iwrite {
  my $self = shift;
  my ($D, $s, $e) = @_;
  my $d = length $D;
  my $c = $e-$s-$d;
  local *FH = $self->{fh};
  confess "Not enough space to insert $d bytes between $s and $e"
    if $c < 0;
  confess "[$s,$e) is an invalid insertion range" if $e < $s;

  $self->_seekb($s);
  read FH, my $buf, $e-$s;

  $D .= substr($buf, 0, $c, "");

  $self->_seekb($s);
  $self->_write_record($D);

  return $buf;
}

# Like _twrite, but the data-pos-len triple may be repeated; you may
# write several chunks.  All the writing will be done in
# one pass.   Chunks SHALL be in ascending order and SHALL NOT overlap.
sub _mtwrite {
  my $self = shift;
  my $unwritten = "";
  my $delta = 0;

  @_ % 3 == 0 
    or die "Arguments to _mtwrite did not come in groups of three";

  while (@_) {
    my ($data, $pos, $len) = splice @_, 0, 3;
    my $end = $pos + $len;  # The OLD end of the segment to be replaced
    $data = $unwritten . $data;
    $delta -= length($unwritten);
    $unwritten  = "";
    $pos += $delta;             # This is where the data goes now
    my $dlen = length $data;
    $self->_seekb($pos);
    if ($len >= $dlen) {        # the data will fit
      $self->_write_record($data);
      $delta += ($dlen - $len); # everything following moves down by this much
      $data = ""; # All the data in the buffer has been written
    } else {                    # won't fit
      my $writable = substr($data, 0, $len - $delta, "");
      $self->_write_record($writable);
      $delta += ($dlen - $len); # everything following moves down by this much
    } 

    # At this point we've written some but maybe not all of the data.
    # There might be a gap to close up, or $data might still contain a
    # bunch of unwritten data that didn't fit.
    my $ndlen = length $data;
    if ($delta == 0) {
      $self->_write_record($data);
    } elsif ($delta < 0) {
      # upcopy (close up gap)
      if (@_) {
        $self->_upcopy($end, $end + $delta, $_[1] - $end);  
      } else {
        $self->_upcopy($end, $end + $delta);  
      }
    } else {
      # downcopy (insert data that didn't fit; replace this data in memory
      # with _later_ data that doesn't fit)
      if (@_) {
        $unwritten = $self->_downcopy($data, $end, $_[1] - $end);
      } else {
        # Make the file longer to accommodate the last segment that doesn't
        $unwritten = $self->_downcopy($data, $end);
      }
    }
  }
}

# Copy block of data of length $len from position $spos to position $dpos
# $dpos must be <= $spos
#
# If $len is undefined, go all the way to the end of the file
# and then truncate it ($spos - $dpos bytes will be removed)
sub _upcopy {
  my $blocksize = 8192;
  my ($self, $spos, $dpos, $len) = @_;
  if ($dpos > $spos) {
    die "source ($spos) was upstream of destination ($dpos) in _upcopy";
  } elsif ($dpos == $spos) {
    return;
  }

  while (! defined ($len) || $len > 0) {
    my $readsize = ! defined($len) ? $blocksize
               : $len > $blocksize ? $blocksize
               : $len;
      
    my $fh = $self->{fh};
    $self->_seekb($spos);
    my $bytes_read = read $fh, my($data), $readsize;
    $self->_seekb($dpos);
    if ($data eq "") { 
      $self->_chop_file;
      last;
    }
    $self->_write_record($data);
    $spos += $bytes_read;
    $dpos += $bytes_read;
    $len -= $bytes_read if defined $len;
  }
}

# Write $data into a block of length $len at position $pos,
# moving everything in the block forwards to make room.
# Instead of writing the last length($data) bytes from the block
# (because there isn't room for them any longer) return them.
#
# Undefined $len means 'until the end of the file'
sub _downcopy {
  my $blocksize = 8192;
  my ($self, $data, $pos, $len) = @_;
  my $fh = $self->{fh};

  while (! defined $len || $len > 0) {
    my $readsize = ! defined($len) ? $blocksize 
      : $len > $blocksize? $blocksize : $len;
    $self->_seekb($pos);
    read $fh, my($old), $readsize;
    my $last_read_was_short = length($old) < $readsize;
    $data .= $old;
    my $writable;
    if ($last_read_was_short) {
      # If last read was short, then $data now contains the entire rest
      # of the file, so there's no need to write only one block of it
      $writable = $data;
      $data = "";
    } else {
      $writable = substr($data, 0, $readsize, "");
    }
    last if $writable eq "";
    $self->_seekb($pos);
    $self->_write_record($writable);
    last if $last_read_was_short && $data eq "";
    $len -= $readsize if defined $len;
    $pos += $readsize;
  }
  return $data;
}

# Adjust the object data structures following an '_mtwrite'
# Arguments are
#  [$pos, $nrecs, @length]  items
# indicating that $nrecs records were removed at $recpos (a record offset)
# and replaced with records of length @length...
# Arguments guarantee that $recpos is strictly increasing.
# No return value
sub _oadjust {
  my $self = shift;
  my $delta = 0;
  my $delta_recs = 0;
  my $prev_end = -1;
  my %newkeys;

  for (@_) {
    my ($pos, $nrecs, @data) = @$_;
    $pos += $delta_recs;

    # Adjust the offsets of the records after the previous batch up
    # to the first new one of this batch
    for my $i ($prev_end+2 .. $pos - 1) {
      $self->{offsets}[$i] += $delta;
      $newkey{$i} = $i + $delta_recs;
    }

    $prev_end = $pos + @data - 1; # last record moved on this pass 

    # Remove the offsets for the removed records;
    # replace with the offsets for the inserted records
    my @newoff = ($self->{offsets}[$pos] + $delta);
    for my $i (0 .. $#data) {
      my $newlen = length $data[$i];
      push @newoff, $newoff[$i] + $newlen;
      $delta += $newlen;
    }

    for my $i ($pos .. $pos+$nrecs-1) {
      last if $i+1 > $#{$self->{offsets}};
      my $oldlen = $self->{offsets}[$i+1] - $self->{offsets}[$i];
      $delta -= $oldlen;
    }

#    # also this data has changed, so update it in the cache
#    for (0 .. $#data) {
#      $self->{cache}->update($pos + $_, $data[$_]);
#    }
#    if ($delta_recs) {
#      my @oldkeys = grep $_ >= $pos + @data, $self->{cache}->ckeys;
#      my @newkeys = map $_ + $delta_recs, @oldkeys;
#      $self->{cache}->rekey(\@oldkeys, \@newkeys);
#    }

    # replace old offsets with new
    splice @{$self->{offsets}}, $pos, $nrecs+1, @newoff;
    # What if we just spliced out the end of the offsets table?
    # shouldn't we clear $self->{eof}?   Test for this XXX BUG TODO

    $delta_recs += @data - $nrecs; # net change in total number of records
  }

  # The trailing records at the very end of the file
  if ($delta) {
    for my $i ($prev_end+2 .. $#{$self->{offsets}}) {
      $self->{offsets}[$i] += $delta;
    }
  }

  # If we scrubbed out all known offsets, regenerate the trivial table
  # that knows that the file does indeed start at 0.
  $self->{offsets}[0] = 0 unless @{$self->{offsets}};
  # If the file got longer, the offsets table is no longer complete
  # $self->{eof} = 0 if $delta_recs > 0;

  # Now there might be too much data in the cache, if we spliced out
  # some short records and spliced in some long ones.  If so, flush
  # the cache.
  $self->_cache_flush;
}

# If a record does not already end with the appropriate terminator
# string, append one.
sub _fixrecs {
  my $self = shift;
  for (@_) {
    $_ = "" unless defined $_;
    $_ .= $self->{recsep}
      unless substr($_, - $self->{recseplen}) eq $self->{recsep};
  }
}


################################################################
#
# Basic read, write, and seek
#

# seek to the beginning of record #$n
# Assumes that the offsets table is already correctly populated
#
# Note that $n=-1 has a special meaning here: It means the start of
# the last known record; this may or may not be the very last record
# in the file, depending on whether the offsets table is fully populated.
#
sub _seek {
  my ($self, $n) = @_;
  my $o = $self->{offsets}[$n];
  defined($o)
    or confess("logic error: undefined offset for record $n");
  seek $self->{fh}, $o, SEEK_SET
    or confess "Couldn't seek filehandle: $!";  # "Should never happen."
}

# seek to byte $b in the file
sub _seekb {
  my ($self, $b) = @_;
  seek $self->{fh}, $b, SEEK_SET
    or die "Couldn't seek filehandle: $!";  # "Should never happen."
}

# populate the offsets table up to the beginning of record $n
# return the offset of record $n
sub _fill_offsets_to {
  my ($self, $n) = @_;

  return $self->{offsets}[$n] if $self->{eof};

  my $fh = $self->{fh};
  local *OFF = $self->{offsets};
  my $rec;

  until ($#OFF >= $n) {
    $self->_seek(-1);           # tricky -- see comment at _seek
    $rec = $self->_read_record;
    if (defined $rec) {
      push @OFF, int(tell $fh);  # Tels says that int() saves memory here
    } else {
      $self->{eof} = 1;
      return;                   # It turns out there is no such record
    }
  }

  # we have now read all the records up to record n-1,
  # so we can return the offset of record n
  $OFF[$n];
}

sub _fill_offsets {
  my ($self) = @_;

  my $fh = $self->{fh};
  local *OFF = $self->{offsets};

  $self->_seek(-1);           # tricky -- see comment at _seek

  # Tels says that inlining read_record() would make this loop
  # five times faster. 20030508
  while ( defined $self->_read_record()) {
    # int() saves us memory here
    push @OFF, int(tell $fh);
  }

  $self->{eof} = 1;
  $#OFF;
}

# assumes that $rec is already suitably terminated
sub _write_record {
  my ($self, $rec) = @_;
  my $fh = $self->{fh};
  local $\ = "";
  print $fh $rec
    or die "Couldn't write record: $!";  # "Should never happen."
#  $self->{_written} += length($rec);
}

sub _read_record {
  my $self = shift;
  my $rec;
  { local $/ = $self->{recsep};
    my $fh = $self->{fh};
    $rec = <$fh>;
  }
  return unless defined $rec;
  if (substr($rec, -$self->{recseplen}) ne $self->{recsep}) {
    # improperly terminated final record --- quietly fix it.
#    my $ac = substr($rec, -$self->{recseplen});
#    $ac =~ s/\n/\\n/g;
    $self->{sawlastrec} = 1;
    unless ($self->{rdonly}) {
      local $\ = "";
      my $fh = $self->{fh};
      print $fh $self->{recsep};
    }
    $rec .= $self->{recsep};
  }
#  $self->{_read} += length($rec) if defined $rec;
  $rec;
}

sub _rw_stats {
  my $self = shift;
  @{$self}{'_read', '_written'};
}

################################################################
#
# Read cache management

sub _cache_flush {
  my ($self) = @_;
  $self->{cache}->reduce_size_to($self->{memory} - $self->{deferred_s});
}

sub _cache_too_full {
  my $self = shift;
  $self->{cache}->bytes + $self->{deferred_s} >= $self->{memory};
}

################################################################
#
# File custodial services
#


# We have read to the end of the file and have the offsets table
# entirely populated.  Now we need to write a new record beyond
# the end of the file.  We prepare for this by writing
# empty records into the file up to the position we want
#
# assumes that the offsets table already contains the offset of record $n,
# if it exists, and extends to the end of the file if not.
sub _extend_file_to {
  my ($self, $n) = @_;
  $self->_seek(-1);             # position after the end of the last record
  my $pos = $self->{offsets}[-1];

  # the offsets table has one entry more than the total number of records
  my $extras = $n - $#{$self->{offsets}};

  # Todo : just use $self->{recsep} x $extras here?
  while ($extras-- > 0) {
    $self->_write_record($self->{recsep});
    push @{$self->{offsets}}, int(tell $self->{fh});
  }
}

# Truncate the file at the current position
sub _chop_file {
  my $self = shift;
  truncate $self->{fh}, tell($self->{fh});
}


# compute the size of a buffer suitable for moving
# all the data in a file forward $n bytes
# ($n may be negative)
# The result should be at least $n.
sub _bufsize {
  my $n = shift;
  return 8192 if $n <= 0;
  my $b = $n & ~8191;
  $b += 8192 if $n & 8191;
  $b;
}

################################################################
#
# Miscellaneous public methods
#

# Lock the file
sub flock {
  my ($self, $op) = @_;
  unless (@_ <= 3) {
    my $pack = ref $self;
    croak "Usage: $pack\->flock([OPERATION])";
  }
  my $fh = $self->{fh};
  $op = LOCK_EX unless defined $op;
  my $locked = flock $fh, $op;

  if ($locked && ($op & (LOCK_EX | LOCK_SH))) {
    # If you're locking the file, then presumably it's because
    # there might have been a write access by another process.
    # In that case, the read cache contents and the offsets table
    # might be invalid, so discard them.  20030508
    $self->{offsets} = [0];
    $self->{cache}->empty;
  }

  $locked;
}

# Get/set autochomp option
sub autochomp {
  my $self = shift;
  if (@_) {
    my $old = $self->{autochomp};
    $self->{autochomp} = shift;
    $old;
  } else {
    $self->{autochomp};
  }
}

# Get offset table entries; returns offset of nth record
sub offset {
  my ($self, $n) = @_;

  if ($#{$self->{offsets}} < $n) {
    return if $self->{eof};     # request for record beyond the end of file
    my $o = $self->_fill_offsets_to($n);
    # If it's still undefined, there is no such record, so return 'undef'
    return unless defined $o;
   }

  $self->{offsets}[$n];
}

sub discard_offsets {
  my $self = shift;
  $self->{offsets} = [0];
}

################################################################
#
# Matters related to deferred writing
#

# Defer writes
sub defer {
  my $self = shift;
  $self->_stop_autodeferring;
  @{$self->{ad_history}} = ();
  $self->{defer} = 1;
}

# Flush deferred writes
#
# This could be better optimized to write the file in one pass, instead
# of one pass per block of records.  But that will require modifications
# to _twrite, so I should have a good _twrite test suite first.
sub flush {
  my $self = shift;

  $self->_flush;
  $self->{defer} = 0;
}

sub _old_flush {
  my $self = shift;
  my @writable = sort {$a<=>$b} (keys %{$self->{deferred}});

  while (@writable) {
    # gather all consecutive records from the front of @writable
    my $first_rec = shift @writable;
    my $last_rec = $first_rec+1;
    ++$last_rec, shift @writable while @writable && $last_rec == $writable[0];
    --$last_rec;
    $self->_fill_offsets_to($last_rec);
    $self->_extend_file_to($last_rec);
    $self->_splice($first_rec, $last_rec-$first_rec+1, 
                   @{$self->{deferred}}{$first_rec .. $last_rec});
  }

  $self->_discard;               # clear out defered-write-cache
}

sub _flush {
  my $self = shift;
  my @writable = sort {$a<=>$b} (keys %{$self->{deferred}});
  my @args;
  my @adjust;

  while (@writable) {
    # gather all consecutive records from the front of @writable
    my $first_rec = shift @writable;
    my $last_rec = $first_rec+1;
    ++$last_rec, shift @writable while @writable && $last_rec == $writable[0];
    --$last_rec;
    my $end = $self->_fill_offsets_to($last_rec+1);
    if (not defined $end) {
      $self->_extend_file_to($last_rec);
      $end = $self->{offsets}[$last_rec];
    }
    my ($start) = $self->{offsets}[$first_rec];
    push @args,
         join("", @{$self->{deferred}}{$first_rec .. $last_rec}), # data
         $start,                                                  # position
         $end-$start;                                             # length
    push @adjust, [$first_rec, # starting at this position...
                   $last_rec-$first_rec+1,  # this many records...
                   # are replaced with these...
                   @{$self->{deferred}}{$first_rec .. $last_rec},
                  ];
  }

  $self->_mtwrite(@args);  # write multiple record groups
  $self->_discard;               # clear out defered-write-cache
  $self->_oadjust(@adjust);
}

# Discard deferred writes and disable future deferred writes
sub discard {
  my $self = shift;
  $self->_discard;
  $self->{defer} = 0;
}

# Discard deferred writes, but retain old deferred writing mode
sub _discard {
  my $self = shift;
  %{$self->{deferred}} = ();
  $self->{deferred_s}  = 0;
  $self->{deferred_max}  = -1;
  $self->{cache}->set_limit($self->{memory});
}

# Deferred writing is enabled, either explicitly ($self->{defer})
# or automatically ($self->{autodeferring})
sub _is_deferring {
  my $self = shift;
  $self->{defer} || $self->{autodeferring};
}

# The largest record number of any deferred record
sub _defer_max {
  my $self = shift;
  return $self->{deferred_max} if defined $self->{deferred_max};
  my $max = -1;
  for my $key (keys %{$self->{deferred}}) {
    $max = $key if $key > $max;
  }
  $self->{deferred_max} = $max;
  $max;
}

################################################################
#
# Matters related to autodeferment
#

# Get/set autodefer option
sub autodefer {
  my $self = shift;
  if (@_) {
    my $old = $self->{autodefer};
    $self->{autodefer} = shift;
    if ($old) {
      $self->_stop_autodeferring;
      @{$self->{ad_history}} = ();
    }
    $old;
  } else {
    $self->{autodefer};
  }
}

# The user is trying to store record #$n Record that in the history,
# and then enable (or disable) autodeferment if that seems useful.
# Note that it's OK for $n to be a non-number, as long as the function
# is prepared to deal with that.  Nobody else looks at the ad_history.
#
# Now, what does the ad_history mean, and what is this function doing?
# Essentially, the idea is to enable autodeferring when we see that the
# user has made three consecutive STORE calls to three consecutive records.
# ("Three" is actually ->{autodefer_threshhold}.)
# A STORE call for record #$n inserts $n into the autodefer history,
# and if the history contains three consecutive records, we enable 
# autodeferment.  An ad_history of [X, Y] means that the most recent
# STOREs were for records X, X+1, ..., Y, in that order.  
#
# Inserting a nonconsecutive number erases the history and starts over.
#
# Performing a special operation like SPLICE erases the history.
#
# There's one special case: CLEAR means that CLEAR was just called.
# In this case, we prime the history with [-2, -1] so that if the next
# write is for record 0, autodeferring goes on immediately.  This is for
# the common special case of "@a = (...)".
#
sub _annotate_ad_history {
  my ($self, $n) = @_;
  return unless $self->{autodefer}; # feature is disabled
  return if $self->{defer};     # already in explicit defer mode
  return unless $self->{offsets}[-1] >= $self->{autodefer_filelen_threshhold};

  local *H = $self->{ad_history};
  if ($n eq 'CLEAR') {
    @H = (-2, -1);              # prime the history with fake records
    $self->_stop_autodeferring;
  } elsif ($n =~ /^\d+$/) {
    if (@H == 0) {
      @H =  ($n, $n);
    } else {                    # @H == 2
      if ($H[1] == $n-1) {      # another consecutive record
        $H[1]++;
        if ($H[1] - $H[0] + 1 >= $self->{autodefer_threshhold}) {
          $self->{autodeferring} = 1;
        }
      } else {                  # nonconsecutive- erase and start over
        @H = ($n, $n);
        $self->_stop_autodeferring;
      }
    }
  } else {                      # SPLICE or STORESIZE or some such
    @H = ();
    $self->_stop_autodeferring;
  }
}

# If autodeferring was enabled, cut it out and discard the history
sub _stop_autodeferring {
  my $self = shift;
  if ($self->{autodeferring}) {
    $self->_flush;
  }
  $self->{autodeferring} = 0;
}

################################################################


# This is NOT a method.  It is here for two reasons:
#  1. To factor a fairly complicated block out of the constructor
#  2. To provide access for the test suite, which need to be sure
#     files are being written properly.
sub _default_recsep {
  my $recsep = $/;
  if ($^O eq 'MSWin32') {       # Dos too?
    # Windows users expect files to be terminated with \r\n
    # But $/ is set to \n instead
    # Note that this also transforms \n\n into \r\n\r\n.
    # That is a feature.
    $recsep =~ s/\n/\r\n/g;
  }
  $recsep;
}

# Utility function for _check_integrity
sub _ci_warn {
  my $msg = shift;
  $msg =~ s/\n/\\n/g;
  $msg =~ s/\r/\\r/g;
  print "# $msg\n";
}

# Given a file, make sure the cache is consistent with the
# file contents and the internal data structures are consistent with
# each other.  Returns true if everything checks out, false if not
#
# The $file argument is no longer used.  It is retained for compatibility
# with the existing test suite.
sub _check_integrity {
  my ($self, $file, $warn) = @_;
  my $rsl = $self->{recseplen};
  my $rs  = $self->{recsep};
  my $good = 1; 
  local *_;                     # local $_ does not work here
  local $DIAGNOSTIC = 1;

  if (not defined $rs) {
    _ci_warn("recsep is undef!");
    $good = 0;
  } elsif ($rs eq "") {
    _ci_warn("recsep is empty!");
    $good = 0;
  } elsif ($rsl != length $rs) {
    my $ln = length $rs;
    _ci_warn("recsep <$rs> has length $ln, should be $rsl");
    $good = 0;
  }

  if (not defined $self->{offsets}[0]) {
    _ci_warn("offset 0 is missing!");
    $good = 0;

  } elsif ($self->{offsets}[0] != 0) {
    _ci_warn("rec 0: offset <$self->{offsets}[0]> s/b 0!");
    $good = 0;
  }

  my $cached = 0;
  {
    local *F = $self->{fh};
    seek F, 0, SEEK_SET;
    local $. = 0;
    local $/ = $rs;

    while (<F>) {
      my $n = $. - 1;
      my $cached = $self->{cache}->_produce($n);
      my $offset = $self->{offsets}[$.];
      my $ao = tell F;
      if (defined $offset && $offset != $ao) {
        _ci_warn("rec $n: offset <$offset> actual <$ao>");
        $good = 0;
      }
      if (defined $cached && $_ ne $cached && ! $self->{deferred}{$n}) {
        $good = 0;
        _ci_warn("rec $n: cached <$cached> actual <$_>");
      }
      if (defined $cached && substr($cached, -$rsl) ne $rs) {
        $good = 0;
        _ci_warn("rec $n in the cache is missing the record separator");
      }
      if (! defined $offset && $self->{eof}) {
        $good = 0;
        _ci_warn("The offset table was marked complete, but it is missing " .
                 "element $.");
      }
    }
    if (@{$self->{offsets}} > $.+1) {
        $good = 0;
        my $n = @{$self->{offsets}};
        _ci_warn("The offset table has $n items, but the file has only $.");
    }

    my $deferring = $self->_is_deferring;
    for my $n ($self->{cache}->ckeys) {
      my $r = $self->{cache}->_produce($n);
      $cached += length($r);
      next if $n+1 <= $.;         # checked this already
      _ci_warn("spurious caching of record $n");
      $good = 0;
    }
    my $b = $self->{cache}->bytes;
    if ($cached != $b) {
      _ci_warn("cache size is $b, should be $cached");
      $good = 0;
    }
  }

  # That cache has its own set of tests
  $good = 0 unless $self->{cache}->_check_integrity;

  # Now let's check the deferbuffer
  # Unless deferred writing is enabled, it should be empty
  if (! $self->_is_deferring && %{$self->{deferred}}) {
    _ci_warn("deferred writing disabled, but deferbuffer nonempty");
    $good = 0;
  }

  # Any record in the deferbuffer should *not* be present in the readcache
  my $deferred_s = 0;
  while (my ($n, $r) = each %{$self->{deferred}}) {
    $deferred_s += length($r);
    if (defined $self->{cache}->_produce($n)) {
      _ci_warn("record $n is in the deferbuffer *and* the readcache");
      $good = 0;
    }
    if (substr($r, -$rsl) ne $rs) {
      _ci_warn("rec $n in the deferbuffer is missing the record separator");
      $good = 0;
    }
  }

  # Total size of deferbuffer should match internal total
  if ($deferred_s != $self->{deferred_s}) {
    _ci_warn("buffer size is $self->{deferred_s}, should be $deferred_s");
    $good = 0;
  }

  # Total size of deferbuffer should not exceed the specified limit
  if ($deferred_s > $self->{dw_size}) {
    _ci_warn("buffer size is $self->{deferred_s} which exceeds the limit " .
             "of $self->{dw_size}");
    $good = 0;
  }

  # Total size of cached data should not exceed the specified limit
  if ($deferred_s + $cached > $self->{memory}) {
    my $total = $deferred_s + $cached;
    _ci_warn("total stored data size is $total which exceeds the limit " .
             "of $self->{memory}");
    $good = 0;
  }

  # Stuff related to autodeferment
  if (!$self->{autodefer} && @{$self->{ad_history}}) {
    _ci_warn("autodefer is disabled, but ad_history is nonempty");
    $good = 0;
  }
  if ($self->{autodeferring} && $self->{defer}) {
    _ci_warn("both autodeferring and explicit deferring are active");
    $good = 0;
  }
  if (@{$self->{ad_history}} == 0) {
    # That's OK, no additional tests required
  } elsif (@{$self->{ad_history}} == 2) {
    my @non_number = grep !/^-?\d+$/, @{$self->{ad_history}};
    if (@non_number) {
      my $msg;
      { local $" = ')(';
        $msg = "ad_history contains non-numbers (@{$self->{ad_history}})";
      }
      _ci_warn($msg);
      $good = 0;
    } elsif ($self->{ad_history}[1] < $self->{ad_history}[0]) {
      _ci_warn("ad_history has nonsensical values @{$self->{ad_history}}");
      $good = 0;
    }
  } else {
    _ci_warn("ad_history has bad length <@{$self->{ad_history}}>");
    $good = 0;
  }

  $good;
}

################################################################
#
# Tie::File::Cache
#
# Read cache

package Tie::File::Cache;
$Tie::File::Cache::VERSION = $Tie::File::VERSION;
use Carp ':DEFAULT', 'confess';

sub HEAP () { 0 }
sub HASH () { 1 }
sub MAX  () { 2 }
sub BYTES() { 3 }
#sub STAT () { 4 } # Array with request statistics for each record
#sub MISS () { 5 } # Total number of cache misses
#sub REQ  () { 6 } # Total number of cache requests 
use strict 'vars';

sub new {
  my ($pack, $max) = @_;
  local *_;
  croak "missing argument to ->new" unless defined $max;
  my $self = [];
  bless $self => $pack;
  @$self = (Tie::File::Heap->new($self), {}, $max, 0);
  $self;
}

sub adj_limit {
  my ($self, $n) = @_;
  $self->[MAX] += $n;
}

sub set_limit {
  my ($self, $n) = @_;
  $self->[MAX] = $n;
}

# For internal use only
# Will be called by the heap structure to notify us that a certain 
# piece of data has moved from one heap element to another.
# $k is the hash key of the item
# $n is the new index into the heap at which it is stored
# If $n is undefined, the item has been removed from the heap.
sub _heap_move {
  my ($self, $k, $n) = @_;
  if (defined $n) {
    $self->[HASH]{$k} = $n;
  } else {
    delete $self->[HASH]{$k};
  }
}

sub insert {
  my ($self, $key, $val) = @_;
  local *_;
  croak "missing argument to ->insert" unless defined $key;
  unless (defined $self->[MAX]) {
    confess "undefined max" ;
  }
  confess "undefined val" unless defined $val;
  return if length($val) > $self->[MAX];

#  if ($self->[STAT]) {
#    $self->[STAT][$key] = 1;
#    return;
#  }

  my $oldnode = $self->[HASH]{$key};
  if (defined $oldnode) {
    my $oldval = $self->[HEAP]->set_val($oldnode, $val);
    $self->[BYTES] -= length($oldval);
  } else {
    $self->[HEAP]->insert($key, $val);
  }
  $self->[BYTES] += length($val);
  $self->flush if $self->[BYTES] > $self->[MAX];
}

sub expire {
  my $self = shift;
  my $old_data = $self->[HEAP]->popheap;
  return unless defined $old_data;
  $self->[BYTES] -= length $old_data;
  $old_data;
}

sub remove {
  my ($self, @keys) = @_;
  my @result;

#  if ($self->[STAT]) {
#    for my $key (@keys) {
#      $self->[STAT][$key] = 0;
#    }
#    return;
#  }

  for my $key (@keys) {
    next unless exists $self->[HASH]{$key};
    my $old_data = $self->[HEAP]->remove($self->[HASH]{$key});
    $self->[BYTES] -= length $old_data;
    push @result, $old_data;
  }
  @result;
}

sub lookup {
  my ($self, $key) = @_;
  local *_;
  croak "missing argument to ->lookup" unless defined $key;

#  if ($self->[STAT]) {
#    $self->[MISS]++  if $self->[STAT][$key]++ == 0;
#    $self->[REQ]++;
#    my $hit_rate = 1 - $self->[MISS] / $self->[REQ];
#    # Do some testing to determine this threshhold
#    $#$self = STAT - 1 if $hit_rate > 0.20; 
#  }

  if (exists $self->[HASH]{$key}) {
    $self->[HEAP]->lookup($self->[HASH]{$key});
  } else {
    return;
  }
}

# For internal use only
sub _produce {
  my ($self, $key) = @_;
  my $loc = $self->[HASH]{$key};
  return unless defined $loc;
  $self->[HEAP][$loc][2];
}

# For internal use only
sub _promote {
  my ($self, $key) = @_;
  $self->[HEAP]->promote($self->[HASH]{$key});
}

sub empty {
  my ($self) = @_;
  %{$self->[HASH]} = ();
    $self->[BYTES] = 0;
    $self->[HEAP]->empty;
#  @{$self->[STAT]} = ();
#    $self->[MISS] = 0;
#    $self->[REQ] = 0;
}

sub is_empty {
  my ($self) = @_;
  keys %{$self->[HASH]} == 0;
}

sub update {
  my ($self, $key, $val) = @_;
  local *_;
  croak "missing argument to ->update" unless defined $key;
  if (length($val) > $self->[MAX]) {
    my ($oldval) = $self->remove($key);
    $self->[BYTES] -= length($oldval) if defined $oldval;
  } elsif (exists $self->[HASH]{$key}) {
    my $oldval = $self->[HEAP]->set_val($self->[HASH]{$key}, $val);
    $self->[BYTES] += length($val);
    $self->[BYTES] -= length($oldval) if defined $oldval;
  } else {
    $self->[HEAP]->insert($key, $val);
    $self->[BYTES] += length($val);
  }
  $self->flush;
}

sub rekey {
  my ($self, $okeys, $nkeys) = @_;
  local *_;
  my %map;
  @map{@$okeys} = @$nkeys;
  croak "missing argument to ->rekey" unless defined $nkeys;
  croak "length mismatch in ->rekey arguments" unless @$nkeys == @$okeys;
  my %adjusted;                 # map new keys to heap indices
  # You should be able to cut this to one loop TODO XXX
  for (0 .. $#$okeys) {
    $adjusted{$nkeys->[$_]} = delete $self->[HASH]{$okeys->[$_]};
  }
  while (my ($nk, $ix) = each %adjusted) {
    # @{$self->[HASH]}{keys %adjusted} = values %adjusted;
    $self->[HEAP]->rekey($ix, $nk);
    $self->[HASH]{$nk} = $ix;
  }
}

sub ckeys {
  my $self = shift;
  my @a = keys %{$self->[HASH]};
  @a;
}

# Return total amount of cached data
sub bytes {
  my $self = shift;
  $self->[BYTES];
}

# Expire oldest item from cache until cache size is smaller than $max
sub reduce_size_to {
  my ($self, $max) = @_;
  until ($self->[BYTES] <= $max) {
    # Note that Tie::File::Cache::expire has been inlined here
    my $old_data = $self->[HEAP]->popheap;
    return unless defined $old_data;
    $self->[BYTES] -= length $old_data;
  }
}

# Why not just $self->reduce_size_to($self->[MAX])?
# Try this when things stabilize   TODO XXX
# If the cache is too full, expire the oldest records
sub flush {
  my $self = shift;
  $self->reduce_size_to($self->[MAX]) if $self->[BYTES] > $self->[MAX];
}

# For internal use only
sub _produce_lru {
  my $self = shift;
  $self->[HEAP]->expire_order;
}

BEGIN { *_ci_warn = \&Tie::File::_ci_warn }

sub _check_integrity {          # For CACHE
  my $self = shift;
  my $good = 1;

  # Test HEAP
  $self->[HEAP]->_check_integrity or $good = 0;

  # Test HASH
  my $bytes = 0;
  for my $k (keys %{$self->[HASH]}) {
    if ($k ne '0' && $k !~ /^[1-9][0-9]*$/) {
      $good = 0;
      _ci_warn "Cache hash key <$k> is non-numeric";
    }

    my $h = $self->[HASH]{$k};
    if (! defined $h) {
      $good = 0;
      _ci_warn "Heap index number for key $k is undefined";
    } elsif ($h == 0) {
      $good = 0;
      _ci_warn "Heap index number for key $k is zero";
    } else {
      my $j = $self->[HEAP][$h];
      if (! defined $j) {
        $good = 0;
        _ci_warn "Heap contents key $k (=> $h) are undefined";
      } else {
        $bytes += length($j->[2]);
        if ($k ne $j->[1]) {
          $good = 0;
          _ci_warn "Heap contents key $k (=> $h) is $j->[1], should be $k";
        }
      }
    }
  }

  # Test BYTES
  if ($bytes != $self->[BYTES]) {
    $good = 0;
    _ci_warn "Total data in cache is $bytes, expected $self->[BYTES]";
  }

  # Test MAX
  if ($bytes > $self->[MAX]) {
    $good = 0;
    _ci_warn "Total data in cache is $bytes, exceeds maximum $self->[MAX]";
  }

  return $good;
}

sub delink {
  my $self = shift;
  $self->[HEAP] = undef;        # Bye bye heap
}

################################################################
#
# Tie::File::Heap
#
# Heap data structure for use by cache LRU routines

package Tie::File::Heap;
use Carp ':DEFAULT', 'confess';
$Tie::File::Heap::VERSION = $Tie::File::Cache::VERSION;
sub SEQ () { 0 };
sub KEY () { 1 };
sub DAT () { 2 };

sub new {
  my ($pack, $cache) = @_;
  die "$pack: Parent cache object $cache does not support _heap_move method"
    unless eval { $cache->can('_heap_move') };
  my $self = [[0,$cache,0]];
  bless $self => $pack;
}

# Allocate a new sequence number, larger than all previously allocated numbers
sub _nseq {
  my $self = shift;
  $self->[0][0]++;
}

sub _cache {
  my $self = shift;
  $self->[0][1];
}

sub _nelts {
  my $self = shift;
  $self->[0][2];
}

sub _nelts_inc {
  my $self = shift;
  ++$self->[0][2];
}  

sub _nelts_dec {
  my $self = shift;
  --$self->[0][2];
}  

sub is_empty {
  my $self = shift;
  $self->_nelts == 0;
}

sub empty {
  my $self = shift;
  $#$self = 0;
  $self->[0][2] = 0;
  $self->[0][0] = 0;            # might as well reset the sequence numbers
}

# notify the parent cache object that we moved something
sub _heap_move {
  my $self = shift;
  $self->_cache->_heap_move(@_);
}

# Insert a piece of data into the heap with the indicated sequence number.
# The item with the smallest sequence number is always at the top.
# If no sequence number is specified, allocate a new one and insert the
# item at the bottom.
sub insert {
  my ($self, $key, $data, $seq) = @_;
  $seq = $self->_nseq unless defined $seq;
  $self->_insert_new([$seq, $key, $data]);
}

# Insert a new, fresh item at the bottom of the heap
sub _insert_new {
  my ($self, $item) = @_;
  my $i = @$self;
  $i = int($i/2) until defined $self->[$i/2];
  $self->[$i] = $item;
  $self->[0][1]->_heap_move($self->[$i][KEY], $i);
  $self->_nelts_inc;
}

# Insert [$data, $seq] pair at or below item $i in the heap.
# If $i is omitted, default to 1 (the top element.)
sub _insert {
  my ($self, $item, $i) = @_;
#  $self->_check_loc($i) if defined $i;
  $i = 1 unless defined $i;
  until (! defined $self->[$i]) {
    if ($self->[$i][SEQ] > $item->[SEQ]) { # inserted item is older
      ($self->[$i], $item) = ($item, $self->[$i]);
      $self->[0][1]->_heap_move($self->[$i][KEY], $i);
    }
    # If either is undefined, go that way.  Otherwise, choose at random
    my $dir;
    $dir = 0 if !defined $self->[2*$i];
    $dir = 1 if !defined $self->[2*$i+1];
    $dir = int(rand(2)) unless defined $dir;
    $i = 2*$i + $dir;
  }
  $self->[$i] = $item;
  $self->[0][1]->_heap_move($self->[$i][KEY], $i);
  $self->_nelts_inc;
}

# Remove the item at node $i from the heap, moving child items upwards.
# The item with the smallest sequence number is always at the top.
# Moving items upwards maintains this condition.
# Return the removed item.  Return undef if there was no item at node $i.
sub remove {
  my ($self, $i) = @_;
  $i = 1 unless defined $i;
  my $top = $self->[$i];
  return unless defined $top;
  while (1) {
    my $ii;
    my ($L, $R) = (2*$i, 2*$i+1);

    # If either is undefined, go the other way.
    # Otherwise, go towards the smallest.
    last unless defined $self->[$L] || defined $self->[$R];
    $ii = $R if not defined $self->[$L];
    $ii = $L if not defined $self->[$R];
    unless (defined $ii) {
      $ii = $self->[$L][SEQ] < $self->[$R][SEQ] ? $L : $R;
    }

    $self->[$i] = $self->[$ii]; # Promote child to fill vacated spot
    $self->[0][1]->_heap_move($self->[$i][KEY], $i);
    $i = $ii; # Fill new vacated spot
  }
  $self->[0][1]->_heap_move($top->[KEY], undef);
  undef $self->[$i];
  $self->_nelts_dec;
  return $top->[DAT];
}

sub popheap {
  my $self = shift;
  $self->remove(1);
}

# set the sequence number of the indicated item to a higher number
# than any other item in the heap, and bubble the item down to the
# bottom.
sub promote {
  my ($self, $n) = @_;
#  $self->_check_loc($n);
  $self->[$n][SEQ] = $self->_nseq;
  my $i = $n;
  while (1) {
    my ($L, $R) = (2*$i, 2*$i+1);
    my $dir;
    last unless defined $self->[$L] || defined $self->[$R];
    $dir = $R unless defined $self->[$L];
    $dir = $L unless defined $self->[$R];
    unless (defined $dir) {
      $dir = $self->[$L][SEQ] < $self->[$R][SEQ] ? $L : $R;
    }
    @{$self}[$i, $dir] = @{$self}[$dir, $i];
    for ($i, $dir) {
      $self->[0][1]->_heap_move($self->[$_][KEY], $_) if defined $self->[$_];
    }
    $i = $dir;
  }
}

# Return item $n from the heap, promoting its LRU status
sub lookup {
  my ($self, $n) = @_;
#  $self->_check_loc($n);
  my $val = $self->[$n];
  $self->promote($n);
  $val->[DAT];
}


# Assign a new value for node $n, promoting it to the bottom of the heap
sub set_val {
  my ($self, $n, $val) = @_;
#  $self->_check_loc($n);
  my $oval = $self->[$n][DAT];
  $self->[$n][DAT] = $val;
  $self->promote($n);
  return $oval;
}

# The hash key has changed for an item;
# alter the heap's record of the hash key
sub rekey {
  my ($self, $n, $new_key) = @_;
#  $self->_check_loc($n);
  $self->[$n][KEY] = $new_key;
}

sub _check_loc {
  my ($self, $n) = @_;
  unless (1 || defined $self->[$n]) {
    confess "_check_loc($n) failed";
  }
}

BEGIN { *_ci_warn = \&Tie::File::_ci_warn }

sub _check_integrity {
  my $self = shift;
  my $good = 1;
  my %seq;

  unless (eval {$self->[0][1]->isa("Tie::File::Cache")}) {
    _ci_warn "Element 0 of heap corrupt";
    $good = 0;
  }
  $good = 0 unless $self->_satisfies_heap_condition(1);
  for my $i (2 .. $#{$self}) {
    my $p = int($i/2);          # index of parent node
    if (defined $self->[$i] && ! defined $self->[$p]) {
      _ci_warn "Element $i of heap defined, but parent $p isn't";
      $good = 0;
    }

    if (defined $self->[$i]) {
      if ($seq{$self->[$i][SEQ]}) {
        my $seq = $self->[$i][SEQ];
        _ci_warn "Nodes $i and $seq{$seq} both have SEQ=$seq";
        $good = 0;
      } else {
        $seq{$self->[$i][SEQ]} = $i;
      }
    }
  }

  return $good;
}

sub _satisfies_heap_condition {
  my $self = shift;
  my $n = shift || 1;
  my $good = 1;
  for (0, 1) {
    my $c = $n*2 + $_;
    next unless defined $self->[$c];
    if ($self->[$n][SEQ] >= $self->[$c]) {
      _ci_warn "Node $n of heap does not predate node $c";
      $good = 0 ;
    }
    $good = 0 unless $self->_satisfies_heap_condition($c);
  }
  return $good;
}

# Return a list of all the values, sorted by expiration order
sub expire_order {
  my $self = shift;
  my @nodes = sort {$a->[SEQ] <=> $b->[SEQ]} $self->_nodes;
  map { $_->[KEY] } @nodes;
}

sub _nodes {
  my $self = shift;
  my $i = shift || 1;
  return unless defined $self->[$i];
  ($self->[$i], $self->_nodes($i*2), $self->_nodes($i*2+1));
}

"Cogito, ergo sum.";  # don't forget to return a true value from the file

__END__

=head1 NAME

Tie::File - Access the lines of a disk file via a Perl array

=head1 SYNOPSIS

 # This file documents Tie::File version 0.98
 use Tie::File;

 tie @array, 'Tie::File', filename or die ...;

 $array[13] = 'blah';     # line 13 of the file is now 'blah'
 print $array[42];        # display line 42 of the file

 $n_recs = @array;        # how many records are in the file?
 $#array -= 2;            # chop two records off the end


 for (@array) {
   s/PERL/Perl/g;        # Replace PERL with Perl everywhere in the file
 }

 # These are just like regular push, pop, unshift, shift, and splice
 # Except that they modify the file in the way you would expect

 push @array, new recs...;
 my $r1 = pop @array;
 unshift @array, new recs...;
 my $r2 = shift @array;
 @old_recs = splice @array, 3, 7, new recs...;

 untie @array;            # all finished


=head1 DESCRIPTION

C<Tie::File> represents a regular text file as a Perl array.  Each
element in the array corresponds to a record in the file.  The first
line of the file is element 0 of the array; the second line is element
1, and so on.

The file is I<not> loaded into memory, so this will work even for
gigantic files.

Changes to the array are reflected in the file immediately.

Lazy people and beginners may now stop reading the manual.

=head2 C<recsep>

What is a 'record'?  By default, the meaning is the same as for the
C<E<lt>...E<gt>> operator: It's a string terminated by C<$/>, which is
probably C<"\n">.  (Minor exception: on DOS and Win32 systems, a
'record' is a string terminated by C<"\r\n">.)  You may change the
definition of "record" by supplying the C<recsep> option in the C<tie>
call:

	tie @array, 'Tie::File', $file, recsep => 'es';

This says that records are delimited by the string C<es>.  If the file
contained the following data:

	Curse these pesky flies!\n

then the C<@array> would appear to have four elements:

	"Curse th"
	"e p"
	"ky fli"
	"!\n"

An undefined value is not permitted as a record separator.  Perl's
special "paragraph mode" semantics (E<agrave> la C<$/ = "">) are not
emulated.

Records read from the tied array do not have the record separator
string on the end; this is to allow

	$array[17] .= "extra";

to work as expected.

(See L<"autochomp">, below.)  Records stored into the array will have
the record separator string appended before they are written to the
file, if they don't have one already.  For example, if the record
separator string is C<"\n">, then the following two lines do exactly
the same thing:

	$array[17] = "Cherry pie";
	$array[17] = "Cherry pie\n";

The result is that the contents of line 17 of the file will be
replaced with "Cherry pie"; a newline character will separate line 17
from line 18.  This means that this code will do nothing:

	chomp $array[17];

Because the C<chomp>ed value will have the separator reattached when
it is written back to the file.  There is no way to create a file
whose trailing record separator string is missing.

Inserting records that I<contain> the record separator string is not
supported by this module.  It will probably produce a reasonable
result, but what this result will be may change in a future version.
Use 'splice' to insert records or to replace one record with several.

=head2 C<autochomp>

Normally, array elements have the record separator removed, so that if
the file contains the text

	Gold
	Frankincense
	Myrrh

the tied array will appear to contain C<("Gold", "Frankincense",
"Myrrh")>.  If you set C<autochomp> to a false value, the record
separator will not be removed.  If the file above was tied with

	tie @gifts, "Tie::File", $gifts, autochomp => 0;

then the array C<@gifts> would appear to contain C<("Gold\n",
"Frankincense\n", "Myrrh\n")>, or (on Win32 systems) C<("Gold\r\n",
"Frankincense\r\n", "Myrrh\r\n")>.

=head2 C<mode>

Normally, the specified file will be opened for read and write access,
and will be created if it does not exist.  (That is, the flags
C<O_RDWR | O_CREAT> are supplied in the C<open> call.)  If you want to
change this, you may supply alternative flags in the C<mode> option.
See L<Fcntl> for a listing of available flags.
For example:

	# open the file if it exists, but fail if it does not exist
	use Fcntl 'O_RDWR';
	tie @array, 'Tie::File', $file, mode => O_RDWR;

	# create the file if it does not exist
	use Fcntl 'O_RDWR', 'O_CREAT';
	tie @array, 'Tie::File', $file, mode => O_RDWR | O_CREAT;

	# open an existing file in read-only mode
	use Fcntl 'O_RDONLY';
	tie @array, 'Tie::File', $file, mode => O_RDONLY;

Opening the data file in write-only or append mode is not supported.

=head2 C<memory>

This is an upper limit on the amount of memory that C<Tie::File> will
consume at any time while managing the file.  This is used for two
things: managing the I<read cache> and managing the I<deferred write
buffer>.

Records read in from the file are cached, to avoid having to re-read
them repeatedly.  If you read the same record twice, the first time it
will be stored in memory, and the second time it will be fetched from
the I<read cache>.  The amount of data in the read cache will not
exceed the value you specified for C<memory>.  If C<Tie::File> wants
to cache a new record, but the read cache is full, it will make room
by expiring the least-recently visited records from the read cache.

The default memory limit is 2Mib.  You can adjust the maximum read
cache size by supplying the C<memory> option.  The argument is the
desired cache size, in bytes.

 # I have a lot of memory, so use a large cache to speed up access
 tie @array, 'Tie::File', $file, memory => 20_000_000;

Setting the memory limit to 0 will inhibit caching; records will be
fetched from disk every time you examine them.

The C<memory> value is not an absolute or exact limit on the memory
used.  C<Tie::File> objects contains some structures besides the read
cache and the deferred write buffer, whose sizes are not charged
against C<memory>. 

The cache itself consumes about 310 bytes per cached record, so if
your file has many short records, you may want to decrease the cache
memory limit, or else the cache overhead may exceed the size of the
cached data.


=head2 C<dw_size>

(This is an advanced feature.  Skip this section on first reading.)

If you use deferred writing (See L<"Deferred Writing">, below) then
data you write into the array will not be written directly to the
file; instead, it will be saved in the I<deferred write buffer> to be
written out later.  Data in the deferred write buffer is also charged
against the memory limit you set with the C<memory> option.

You may set the C<dw_size> option to limit the amount of data that can
be saved in the deferred write buffer.  This limit may not exceed the
total memory limit.  For example, if you set C<dw_size> to 1000 and
C<memory> to 2500, that means that no more than 1000 bytes of deferred
writes will be saved up.  The space available for the read cache will
vary, but it will always be at least 1500 bytes (if the deferred write
buffer is full) and it could grow as large as 2500 bytes (if the
deferred write buffer is empty.)

If you don't specify a C<dw_size>, it defaults to the entire memory
limit.

=head2 Option Format

C<-mode> is a synonym for C<mode>.  C<-recsep> is a synonym for
C<recsep>.  C<-memory> is a synonym for C<memory>.  You get the
idea.

=head1 Public Methods

The C<tie> call returns an object, say C<$o>.  You may call

	$rec = $o->FETCH($n);
	$o->STORE($n, $rec);

to fetch or store the record at line C<$n>, respectively; similarly
the other tied array methods.  (See L<perltie> for details.)  You may
also call the following methods on this object:

=head2 C<flock>

	$o->flock(MODE)

will lock the tied file.  C<MODE> has the same meaning as the second
argument to the Perl built-in C<flock> function; for example
C<LOCK_SH> or C<LOCK_EX | LOCK_NB>.  (These constants are provided by
the C<use Fcntl ':flock'> declaration.)

C<MODE> is optional; the default is C<LOCK_EX>.

C<Tie::File> maintains an internal table of the byte offset of each
record it has seen in the file.  

When you use C<flock> to lock the file, C<Tie::File> assumes that the
read cache is no longer trustworthy, because another process might
have modified the file since the last time it was read.  Therefore, a
successful call to C<flock> discards the contents of the read cache
and the internal record offset table.

C<Tie::File> promises that the following sequence of operations will
be safe:

	my $o = tie @array, "Tie::File", $filename;
	$o->flock;

In particular, C<Tie::File> will I<not> read or write the file during
the C<tie> call.  (Exception: Using C<mode =E<gt> O_TRUNC> will, of
course, erase the file during the C<tie> call.  If you want to do this
safely, then open the file without C<O_TRUNC>, lock the file, and use
C<@array = ()>.)

The best way to unlock a file is to discard the object and untie the
array.  It is probably unsafe to unlock the file without also untying
it, because if you do, changes may remain unwritten inside the object.
That is why there is no shortcut for unlocking.  If you really want to
unlock the file prematurely, you know what to do; if you don't know
what to do, then don't do it.

All the usual warnings about file locking apply here.  In particular,
note that file locking in Perl is B<advisory>, which means that
holding a lock will not prevent anyone else from reading, writing, or
erasing the file; it only prevents them from getting another lock at
the same time.  Locks are analogous to green traffic lights: If you
have a green light, that does not prevent the idiot coming the other
way from plowing into you sideways; it merely guarantees to you that
the idiot does not also have a green light at the same time.

=head2 C<autochomp>

	my $old_value = $o->autochomp(0);    # disable autochomp option
	my $old_value = $o->autochomp(1);    #  enable autochomp option

	my $ac = $o->autochomp();   # recover current value

See L<"autochomp">, above.

=head2 C<defer>, C<flush>, C<discard>, and C<autodefer>

See L<"Deferred Writing">, below.

=head2 C<offset>

	$off = $o->offset($n);

This method returns the byte offset of the start of the C<$n>th record
in the file.  If there is no such record, it returns an undefined
value.

=head1 Tying to an already-opened filehandle

If C<$fh> is a filehandle, such as is returned by C<IO::File> or one
of the other C<IO> modules, you may use:

	tie @array, 'Tie::File', $fh, ...;

Similarly if you opened that handle C<FH> with regular C<open> or
C<sysopen>, you may use:

	tie @array, 'Tie::File', \*FH, ...;

Handles that were opened write-only won't work.  Handles that were
opened read-only will work as long as you don't try to modify the
array.  Handles must be attached to seekable sources of data---that
means no pipes or sockets.  If C<Tie::File> can detect that you
supplied a non-seekable handle, the C<tie> call will throw an
exception.  (On Unix systems, it can detect this.)

Note that Tie::File will only close any filehandles that it opened
internally.  If you passed it a filehandle as above, you "own" the
filehandle, and are responsible for closing it after you have untied
the @array.

=head1 Deferred Writing

(This is an advanced feature.  Skip this section on first reading.)

Normally, modifying a C<Tie::File> array writes to the underlying file
immediately.  Every assignment like C<$a[3] = ...> rewrites as much of
the file as is necessary; typically, everything from line 3 through
the end will need to be rewritten.  This is the simplest and most
transparent behavior.  Performance even for large files is reasonably
good.

However, under some circumstances, this behavior may be excessively
slow.  For example, suppose you have a million-record file, and you
want to do:

	for (@FILE) {
	  $_ = "> $_";
	}

The first time through the loop, you will rewrite the entire file,
from line 0 through the end.  The second time through the loop, you
will rewrite the entire file from line 1 through the end.  The third
time through the loop, you will rewrite the entire file from line 2 to
the end.  And so on.

If the performance in such cases is unacceptable, you may defer the
actual writing, and then have it done all at once.  The following loop
will perform much better for large files:

	(tied @a)->defer;
	for (@a) {
	  $_ = "> $_";
	}
	(tied @a)->flush;

If C<Tie::File>'s memory limit is large enough, all the writing will
done in memory.  Then, when you call C<-E<gt>flush>, the entire file
will be rewritten in a single pass.

(Actually, the preceding discussion is something of a fib.  You don't
need to enable deferred writing to get good performance for this
common case, because C<Tie::File> will do it for you automatically
unless you specifically tell it not to.  See L<"Autodeferring">,
below.)

Calling C<-E<gt>flush> returns the array to immediate-write mode.  If
you wish to discard the deferred writes, you may call C<-E<gt>discard>
instead of C<-E<gt>flush>.  Note that in some cases, some of the data
will have been written already, and it will be too late for
C<-E<gt>discard> to discard all the changes.  Support for
C<-E<gt>discard> may be withdrawn in a future version of C<Tie::File>.

Deferred writes are cached in memory up to the limit specified by the
C<dw_size> option (see above).  If the deferred-write buffer is full
and you try to write still more deferred data, the buffer will be
flushed.  All buffered data will be written immediately, the buffer
will be emptied, and the now-empty space will be used for future
deferred writes.

If the deferred-write buffer isn't yet full, but the total size of the
buffer and the read cache would exceed the C<memory> limit, the oldest
records will be expired from the read cache until the total size is
under the limit.

C<push>, C<pop>, C<shift>, C<unshift>, and C<splice> cannot be
deferred.  When you perform one of these operations, any deferred data
is written to the file and the operation is performed immediately.
This may change in a future version.

If you resize the array with deferred writing enabled, the file will
be resized immediately, but deferred records will not be written.
This has a surprising consequence: C<@a = (...)> erases the file
immediately, but the writing of the actual data is deferred.  This
might be a bug.  If it is a bug, it will be fixed in a future version.

=head2 Autodeferring

C<Tie::File> tries to guess when deferred writing might be helpful,
and to turn it on and off automatically. 

	for (@a) {
	  $_ = "> $_";
	}

In this example, only the first two assignments will be done
immediately; after this, all the changes to the file will be deferred
up to the user-specified memory limit.

You should usually be able to ignore this and just use the module
without thinking about deferring.  However, special applications may
require fine control over which writes are deferred, or may require
that all writes be immediate.  To disable the autodeferment feature,
use

	(tied @o)->autodefer(0);

or

       	tie @array, 'Tie::File', $file, autodefer => 0;


Similarly, C<-E<gt>autodefer(1)> re-enables autodeferment, and 
C<-E<gt>autodefer()> recovers the current value of the autodefer setting.


=head1 CONCURRENT ACCESS TO FILES

Caching and deferred writing are inappropriate if you want the same
file to be accessed simultaneously from more than one process.  Other
optimizations performed internally by this module are also
incompatible with concurrent access.  A future version of this module will
support a C<concurrent =E<gt> 1> option that enables safe concurrent access.

Previous versions of this documentation suggested using C<memory
=E<gt> 0> for safe concurrent access.  This was mistaken.  Tie::File
will not support safe concurrent access before version 0.96.

=head1 CAVEATS

(That's Latin for 'warnings'.)

=over 4

=item *

Reasonable effort was made to make this module efficient.  Nevertheless,
changing the size of a record in the middle of a large file will
always be fairly slow, because everything after the new record must be
moved.

=item *

The behavior of tied arrays is not precisely the same as for regular
arrays.  For example:

	# This DOES print "How unusual!"
	undef $a[10];  print "How unusual!\n" if defined $a[10];

C<undef>-ing a C<Tie::File> array element just blanks out the
corresponding record in the file.  When you read it back again, you'll
get the empty string, so the supposedly-C<undef>'ed value will be
defined.  Similarly, if you have C<autochomp> disabled, then

	# This DOES print "How unusual!" if 'autochomp' is disabled
	undef $a[10];
        print "How unusual!\n" if $a[10];

Because when C<autochomp> is disabled, C<$a[10]> will read back as
C<"\n"> (or whatever the record separator string is.)  

There are other minor differences, particularly regarding C<exists>
and C<delete>, but in general, the correspondence is extremely close.

=item *

I have supposed that since this module is concerned with file I/O,
almost all normal use of it will be heavily I/O bound.  This means
that the time to maintain complicated data structures inside the
module will be dominated by the time to actually perform the I/O.
When there was an opportunity to spend CPU time to avoid doing I/O, I
usually tried to take it.

=item *

You might be tempted to think that deferred writing is like
transactions, with C<flush> as C<commit> and C<discard> as
C<rollback>, but it isn't, so don't.

=item *

There is a large memory overhead for each record offset and for each
cache entry: about 310 bytes per cached data record, and about 21 bytes
per offset table entry.

The per-record overhead will limit the maximum number of records you
can access per file. Note that I<accessing> the length of the array
via C<$x = scalar @tied_file> accesses B<all> records and stores their
offsets.  The same for C<foreach (@tied_file)>, even if you exit the
loop early.

=back

=head1 SUBCLASSING

This version promises absolutely nothing about the internals, which
may change without notice.  A future version of the module will have a
well-defined and stable subclassing API.

=head1 WHAT ABOUT C<DB_File>?

People sometimes point out that L<DB_File> will do something similar,
and ask why C<Tie::File> module is necessary.

There are a number of reasons that you might prefer C<Tie::File>.
A list is available at C<http://perl.plover.com/TieFile/why-not-DB_File>.

=head1 AUTHOR

Mark Jason Dominus

To contact the author, send email to: C<mjd-perl-tiefile+@plover.com>

To receive an announcement whenever a new version of this module is
released, send a blank email message to
C<mjd-perl-tiefile-subscribe@plover.com>.

The most recent version of this module, including documentation and
any news of importance, will be available at

	http://perl.plover.com/TieFile/


=head1 LICENSE

C<Tie::File> version 0.96 is copyright (C) 2003 Mark Jason Dominus.

This library is free software; you may redistribute it and/or modify
it under the same terms as Perl itself.

These terms are your choice of any of (1) the Perl Artistic Licence,
or (2) version 2 of the GNU General Public License as published by the
Free Software Foundation, or (3) any later version of the GNU General
Public License.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this library program; it should be in the file C<COPYING>.
If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
Fifth Floor, Boston, MA  02110-1301, USA

For licensing inquiries, contact the author at:

	Mark Jason Dominus
	255 S. Warnock St.
	Philadelphia, PA 19107

=head1 WARRANTY

C<Tie::File> version 0.98 comes with ABSOLUTELY NO WARRANTY.
For details, see the license.

=head1 THANKS

Gigantic thanks to Jarkko Hietaniemi, for agreeing to put this in the
core when I hadn't written it yet, and for generally being helpful,
supportive, and competent.  (Usually the rule is "choose any one.")
Also big thanks to Abhijit Menon-Sen for all of the same things.

Special thanks to Craig Berry and Peter Prymmer (for VMS portability
help), Randy Kobes (for Win32 portability help), Clinton Pierce and
Autrijus Tang (for heroic eleventh-hour Win32 testing above and beyond
the call of duty), Michael G Schwern (for testing advice), and the
rest of the CPAN testers (for testing generally).

Special thanks to Tels for suggesting several speed and memory
optimizations.

Additional thanks to:
Edward Avis /
Mattia Barbon /
Tom Christiansen /
Gerrit Haase /
Gurusamy Sarathy /
Jarkko Hietaniemi (again) /
Nikola Knezevic /
John Kominetz /
Nick Ing-Simmons /
Tassilo von Parseval /
H. Dieter Pearcey /
Slaven Rezic /
Eric Roode /
Peter Scott /
Peter Somu /
Autrijus Tang (again) /
Tels (again) /
Juerd Waalboer /
Todd Rinaldo

=head1 TODO

More tests.  (Stuff I didn't think of yet.)

Paragraph mode?

Fixed-length mode.  Leave-blanks mode.

Maybe an autolocking mode?

For many common uses of the module, the read cache is a liability.
For example, a program that inserts a single record, or that scans the
file once, will have a cache hit rate of zero.  This suggests a major
optimization: The cache should be initially disabled.  Here's a hybrid
approach: Initially, the cache is disabled, but the cache code
maintains statistics about how high the hit rate would be *if* it were
enabled.  When it sees the hit rate get high enough, it enables
itself.  The STAT comments in this code are the beginning of an
implementation of this.

Record locking with fcntl()?  Then the module might support an undo
log and get real transactions.  What a tour de force that would be.

Keeping track of the highest cached record. This would allow reads-in-a-row
to skip the cache lookup faster (if reading from 1..N with empty cache at
start, the last cached value will be always N-1).

More tests.

=cut

