Skip to Content

<

Computer Cache #7

A cache by PaBa Send Message to Owner Message this owner
Hidden : 7/31/2007
Difficulty:
4 out of 5
Terrain:
1.5 out of 5

Size: Size: micro (micro)

Join now to view geocache location details. It's free!

Watch

How Geocaching Works

Please note Use of geocaching.com services is subject to the terms and conditions in our disclaimer.

Geocache Description:

Perl / Regular Expressions

POZOR: Cache na vyse uvedenych souradnicich nenajdete!! Ty pouze smeruji na jednu Perl-u prazske architektury .
POZOR: 16.8.2009 doslo ke zmene umisteni finalky (a hintu) - nyni je nutno pridat k vypocitane souradnici N ctyri tisiciny!!!!

Perl je zajimavy programovaci jazyk, ktery vytvoril Larry Wall v roce 1987. Jedna se o takzvany interpret, coz znamena, ze se vysledny program nepreklada, ale interpretuje radek po radku podobne jako u Basicu.

Perl je dodnes velice popularni treba pri tvorbe CGI skriptu ci zpracovani dat. Je vhodny pro reseni malych programku (utilit) ale i velkych a rozsahlych projektu.

K nejvetsim vyhodam jazyka Perl patri to, ze umoznuje rychly vyvoj programu bez nutnosti kompilace a linkovani, nabizi spoustu jiz hotovych knihoven a modulu vcetne napojeni na nejrozsirenejsi databazove systemy, snadnou praci s textem a znackovacimi jazyky (XML, HTML…). K casto pouzivanym metodam pro praci s textem slouzi velice efektivni regularnimi vyrazy, kterymi se na CC#7 budeme krome Perlu zabyvat.

Ucelem teto kesky neni vas naucit programovani v jazyce Perl, ale ukazat Vam, jake moznosti prace s textem nabizeji regularni vyrazy (RE - Regular Expressions), a jak snadno lze s daty s jejich pomoci manipulovat. RE se pouzivaji i v rade jinych jazyku nebo aplikaci. Jazyk Perl jsem vybral proto, ze je prave pro nej pouziti RE charakteristicke. Pomoci RE je mozno jednoduchym zpusobem ziskavat z textovych dat udaje a pretvaret je do jine podoby.

Co je vlastne regularni vyraz? Je to jednoduse retezec, ktery popisuje urcity vzorek. S jejich jednoduchou formou jste se pravdepodobne setkali - napriklad prikaz dir *.* vypise vsechny soubory v danem adresari, znak '*' zde funguje jako metaznak s vyznamem 'libovolny pocet libovolnych znaku'. Jake dalsi takove metaznaky se nam pri reseni CC#7 budou hodit?

vyraz vyhovuje priklad poznamka
znak libovolny znak r najde 'r' ve slove Perl
. libovolný znak (krome noveho radku)    . najde 'P' ve slove Perl
* 0 ci vice libovolnych znaku P*l najde 'er' ve slove Perl
+ 1 ci vice libovolnych znaku P+ najde 'erl' ve slove Perl
? 0 ci 1 libovolny znak P? najde 'e' ve slove Perl
[znaky] jeden z uvedenych znaku [0-9] libovolna cislice
[^znaky]    libovolny znak krome uvedenych [^0-9]    libovolny znak krome cislic
\x vyradí/zapne vyznam metaznaku x \.\.\. znaky ... (opravdove tecky)
^ zacatek radku ^Pe najde 'Perl' na zacatku radku
$ konec radku l$ najde 'Perl' na konci radku
{n} presny pocet n znaku .{2} libovolne DVA znaky ('Pe')
{n,} minimalne alespon n znaku .{2,} minimalne DVA znaky ('Perl')
{n,m} n az m znaku (vcetne) .{2,3} 2-3 znaky ('Per')
| znak pro nebo [a|b|c] 'a' nebo 'b' nebo 'c'
() vytvareni skupin

Uz se vam z toho toci hlava? Nebojte, nic to neni, je to jen vec cviku! Uvedme si par jednoduchych prikladu:
"Hello World" =~ /World/; v prvnim retezci se hleda slovo World (a najde se)
"dilbert" =~ /^bert/; nenajde se (bert neni na zacatku radku)
/[bcr]at/; odpovida slovum 'bat, 'cat' a 'rat'
/pol[0-9]/; odpovida slovu 'pol' nasledovanym jednim cislem

Pokud chcete pouzit misto metaznaku skutecny znak, musite pred nej dat zpetne lomitko (napriklad misto '?' napsat '\?'), jinak se interpretuje jako metaznak. Na druhou stranu existuji specialni metaznaky, ktere funguji jen se zpetnym lomitkem a ktere z normalnich znaku delaji prave zvlastni metaznak:

\d cislo, tj. [0-9]
\s 'obecna mezera', tedy i novy radek atd - tj. [\ \t\r\n\f]
\w znak ve slovu, tj. [0-9a-zA-Z_]
\D negace \d - cokoli krome cislice, tj. [^0-9]
\S negace \s - cokoli krome 'obecne mezery' [^\s]
\W      negace \w - cokoli krome znaku ve slovu [^\w]

Opet si uvedme priklad:
/\d\d:\d\d:\d\d/; # odpovida casovemu formatu hh:mm:ss

Operator s /// je vyuzivan k nahrazeni jednoho znaku jinym. Napriklad v nasledujicim prikladu se kocka zmeni v krysu:
$x = "I like cats and bats!";
$x =~ s/.at/rat/;

Pokud na konci prikazu pro nahrazeni nasleduje modifikator 'g', provadi se toto nahrazeni opakovane:
$x = "I like cats and bats!";
$x =~ s/.at/rat/g;

Ted uz mame krysu nejen z kocky ale i z netopyra !

K vytvareni skupin znaku slouzi zavorky (). Ty jsou vhodne i k dalsimu ucelu - umoznuji prirazeni casti stringu, ktery odpovida danemu regularnimu vyrazu, do specialnich promennych: $1, $2, atd. Ty pak mohou byt pouzity jako normalni promenne.
# oddel hodiny, minuty a sekundy
if ($time =~ /(\d\d):(\d\d):(\d\d)/) { # test, zda vstup odpovida formatu hh:mm:ss
   $hours = $1;
   $minutes = $2;
   $seconds = $3; }

Myslim si, za jako kratky uvod do jazyka Perl a RE to stacilo, ne? Pokud si chcete precist vice, zkuste treba ceskou Wikipedii, o regularnich vyrazech se doctete vice treba v moc peknem serialu Pavla Satrapy.

Tak a ted mate k dispozici veskere indicie, abyste mohli vyresit nas velmi zapeklity sedmiradkovy program . Upozorneni: Je v nem schvalne 'zavlecena' jedna syntakticka chyba, abyste nemohli svindlovat pomoci nejakeho stazeneho interpretru Perl. Bud musite chybicku najit a odstranit, nebo budete muset vypocty provadet rucne. Mnoho stesti pri lusteni i pri hledani! Pozor - mikrocache obsahuje pouze logbook, prineste si proto vlastni tuzku a v logu setrete mistem - staci napsat pouze nick a datum. Kolem je casto docela dost lidi. Cache ulozte na sve misto presne tak, jak byla predtim. Diky!!!

#!/usr/local/bin/perl
my $string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.*! ";
$string =~ s/(.)(.)(.)(.)(.)(.)(.)(.)/$3$7$6$1$8$5$4$2/g;
$string =~ /(^.{5})(\w)(.{4})(.)(.*)([rR])(.)(.)(.)([Y])
(.)(\d)(.)(\D)(.)(\W{2})(.)(\s)(.)(\w)(\S)/;
print "Cache Coordinates : $4$11$7$18$7$9$19$21$11$21$18";
print "$2$7$13$8$18$12$11$19$17$15$12\n";
print "Attention : since 16/08/09 add 0.004 to the North!!\n";


POZOR: 16.8.2009 doslo ke zmene umisteni finalky (a hintu) - nyni je nutno pridat k vypocitane souradnici N ctyri tisiciny!!!!

Perl
ATTENTION: There is no cache at given coordinates!!.
Perl is a very interesting programming language. It was created by Larry Wall at 1987. It is so called interpreter, which means that the source code is not compiled but intrepreted line by line like Basic.

Perl is very popular till today for example in creating CGI scripts or in a data manipulation. You can create small utilities or very large projects with Perl.

The biggest advantages of Perl are the fast program development (without the need of compiling and linking), there are many ready to use libraries and modules including the connection to widely used database systems. Perl programs can easily manipulate with the text and markup languages (XML, HTML…). The Regular Expressions (RE) are mainly used for this purpose. And Perl together with regular expressions will be used to solve this CC#7 mystery cache.

I will not explain to you here how to use the Perl or RE, you can find it out for yourself. There are many sources about these subjects on the Internet. I can recommend you for example this Perl Beginners Quide", RE Quick Guide" or RE Tutorial.

Ready to solve the Perl script above (the last one in the Czech section)? Go on! I have a small warning though - there is a small syntactic error inside, so it cannot be solved mechanicaly by the program itself. You must either find the error and remove it or to solve just by your head . Good luck while solving or searching! Attention - microcache contains only the logbook. You need to bring your own pen! Also please save the space in the logbook, please put only the date and nick there. Watch the people around. Please put the cache exactly at the same place as it was before. Thanks!!!

ATTENTION: At 16.8.2009 the final cache has been moved (and hint changed) - You need to add 0.004 to the North coordinate!!!!

Viz tez/See also:
Computer Cache #1
Computer Cache #2
Computer Cache #3
Computer Cache #4
Computer Cache #5
Computer Cache #6

Additional Hints (Decrypt)

mnoenqyv / envyvatf

Decryption Key

A|B|C|D|E|F|G|H|I|J|K|L|M
-------------------------
N|O|P|Q|R|S|T|U|V|W|X|Y|Z

(letter above equals below, and vice versa)



 

Find...

1,518 Logged Visits

Found it 1,358     Didn't find it 89     Write note 21     Temporarily Disable Listing 9     Enable Listing 9     Publish Listing 1     Needs Maintenance 18     Owner Maintenance 13     

View Logbook | View the Image Gallery of 17 images

**Warning! Spoilers may be included in the descriptions or links.

Current Time:
Last Updated:
Rendered From:Unknown
Coordinates are in the WGS84 datum

Return to the Top of the Page

Reviewer notes

Use this space to describe your geocache location, container, and how it's hidden to your reviewer. If you've made changes, tell the reviewer what changes you made. The more they know, the easier it is for them to publish your geocache. This note will not be visible to the public when your geocache is published.