There html-form:

<form method=post action='../testing.cgi'> <label> Имя: &nbsp&nbsp&nbsp&nbsp&nbsp <input id='name' name='name' type='text'> </label> <br><label>Пароль: <input id='pass' name='pass' type='password'> </label> <br>Пол: &nbsp&nbsp&nbsp&nbsp&nbsp <select id='selectsex' name=sex[]> <option value='мужской'>мужской</option> <option value='женский'>женский</option> </select> <br>Возраст: <br><input type='radio' name='age' value='18'> 18 <br><input type='radio' name='age' value='19'> 19 <br><input type='radio' name='age' value='20'> 20 <br>Какие языки вы знаете? <br><input type='checkbox' name='languages[]' value='english'> Английский <br><input type='checkbox' name='languages[]' value='russian'> Русский <br><input type='checkbox' name='languages[]' value='ukrainian'> Украинский <br><input type='checkbox' name='languages[]' value='polish'> Польский <br><input type='checkbox' name='languages[]' value='german'> Немецкий <br><input type='checkbox' name='languages[]' value='french'> Французкий <br><br>Можете добавить некоторый комментарий, если хотите:<br> <textarea name='textarea' placeholder='Hello. My name is Tom Riddle...'></textarea> <br><button id='send'>Отправить</button> </form> 

And the Perl-script, which decodes information from the form (only Cyrillic, because it reproduces the Latin alphabet adequately), as I suppose, by this line (taken from examples in Google):

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

Generally speaking, explain what is happening here? As I understand it, the current value of the variable $ value is compared to match the specified regexp pattern, after which ... is divided by the result of the pack function ?? wtf? I want to understand

And another question, when I display the name attribute of a form element in a perl script, then if there are square brackets, I get dirty: enter image description here

How to get rid of it and display the real name?

  • one
    The string you give should just in $ value replace all% NN with the corresponding characters. The pack function with the 'C' parameter does just the characters with the code that was given, and gave the decimal value of what stands after % . Although it should be noted that the chr function will do the same - Mike
  • @Mike, is this like a hex value? Type: name =% D0% 94% D0% B5% D0% BD% D0% B8% D1% 81 - Anque
  • Well, hex does hexadecimal decimal - Mike
  • By the way, I realized that you probably do not. The same line decodes the value of the parameter. And we need to decode the parameter name with the same line - Mike
  • I understood everything, thank you all !! like everyone ... Pink Tux and Mike = y) - Anque

1 answer 1

All this manual decoding of GET and POST not needed by anyone for 20 years already. Moreover, it will have so many pitfalls and a rake that you get tired of reinventing bicycles.

If you have found some kind of CGI manual where this is recommended, throw it in the trash and forget it. If you so want to mess around with CGI (in the 21st century, then ...), then at least look at the CGI module, which is exactly what it is intended for.

Here is just an example:

when I display the name attribute of a form element in a perl script

Deduce you wrong in principle. You should get an output array containing all the marked items. And with your manual analysis, you will get something completely different. The CGI module copes with such things with a bang.

is divided into the result of the function pack?

What does the division? It is about replacing:

 $value =~ s/ЧТО_МЕНЯЕМ/НА_ЧТО_МЕНЯЕМ/как_именно; 

The modifier e in part как_меняем says that the result must be pre-processed with the function pack() (which in this case decodes sequences of the form %XX into normal characters). That is, the regular expressions manual is also worth a look, and indeed in some textbook on Perl. Only not so ancient, in which manual work with form parameters is advised.

  • thanks for the answer) I understand that these are already all outdated technologies and generally yuzless, but I just do laboratory work with the given conditions. 1. What does 'eg' mean at the end? 2. Why is the mask twice the same set? ([a-fA-F0-9] [a-fA-F0-9]) 3. Why does the mask face%? 4. what is the argument function hex with variable argument $ 1? I apologize so many questions. it is clear that it will be easier for you to send me read the guides for the downs, but I would like in this case to go the way easier for you ... albeit difficult for you. - Anque
  • @Anhk e considers something as an executable, i.e. the pack function calls, not the text substitutes. g - globally, changes all such places in the string. Without g only the first entry would change - Mike
  • @Anhk Wikipedia - "regular expressions". it must be read anyway. And $ 1 is the first substring that is in parentheses, i.e. two hexadecimal digits, which by the way, just like these square brackets, how the lists of characters are given - Mike
  • @Anhk about other obscure places - a direct way such, you want to know what hex is, go to Google, write "perl hex". all - the issue is resolved and by the way I wrote to you in the comment to your question what it does - Mike
  • one
    @Anhk here is citforum.ru/internet/perl_tut/dat.shtml read - Mike