Главная страница


ru.perl

 
 - RU.PERL ----------------------------------------------------------------------
 From : Nick Knutov                          2:5054/67.4    24 Dec 2003  18:01:59
 To : All
 Subject : <без заголовка>
 -------------------------------------------------------------------------------- 
 
 
         Помогите плиз пеpевести все нижепpиведенное из php в perl. Я в php не
 настолько силен чтобы сделать это.
 //============================================================================
 function sqlFormat($sql_str) {    // Defines reserved words to deal with
 $res_words_arr = array('DROP','SELECT','DELETE','UPDATE','INSERT','LOAD',
 'EXPLAIN', 'SHOW','FROM','INTO','OUTFILE','DATA','REPLACE','CHECK',
 'ANALYZE','REPAIR','OPTIMIZE','TABLE','ORDER','HAVING','LIMIT','GROUP',
 'DISTINCT');
 while (list(, $w) = each($res_words_arr)) {
     // Separates a backquoted expression with spaces
     $pattern = '[[:space:]]' . $w . '`([^`]*)`(.*)';
     $replace = ' ' . $w . ' `\\1` \\2';
     $sql_str = substr(eregi_replace($pattern, $replace, ' ' . $sql_str), 1);
     // Separates a parenthesized expression with spaces
     $pattern = '[[:space:]]' . $w . '\(([^)]*)\)(.*)';
     $replace = ' ' . $w . ' (\\1) \\2';
     $sql_str = substr(eregi_replace($pattern, $replace, ' ' . $sql_str), 1);
     // Converts reservered words to upper case if not yet done
     $sql_str = substr(eregi_replace('[[:space:]]' . $w . '[[:space:]]', ' ' . $w
 . ' ', ' ' . $sql_str), 1);
     // add color -- not really tested yet... -- NK -- And it's not work
 properly...
 }  // end while
 // Removes repeated spaces
 $sql_str = ereg_replace('[[:space:]]+', ' ', $sql_str);
 // GROUP or ORDER: "BY" to uppercase too
 $sql_str = eregi_replace('(GROUP|ORDER) BY', '\\1 BY', $sql_str);
 return $sql_str;
 }  // end of the "sqlFormat()" function
 
 //============================================================================
 function sqlColor($sql_str) {    // Color defined words and turned them into
 upcases     (с) NK.
 
 $words1 =
 array('DROP','SELECT','DELETE','UPDATE','INSERT','LOAD','EXPLAIN','SHOW','FROM' 
 ,'INTO','OUTFILE','DATA','REPLACE','CHECK','ANALYZE','REPAIR','OPTIMIZE','TABLE 
 ','ORDER','HAVING','LIMIT','GROUP','DISTINCT');
 $color1on = '<font color="red"><b>';
 $color1off= '</b></font>';
 while (list(, $w) = each($words1)) {
     // Converts reservered words to upper case if not yet done
        $sql_str = substr(eregi_replace('[[:space:]]' . $w . '[[:space:]]', '
 '.$color1on . $w  . $color1off.' ', ' ' . $sql_str), 1);
 //     $sql_str = substr(eregi_replace('[[:space:]]' . $w . '[[:space:]]', '
 '.$color2on . $w  . $color2off.' ', ' ' . $sql_str), 1);
 };  // end while
 $words2 = array('AND','=','>','<','>=','<=','OR','NOT');
 $color2on = '<font color="green"><b>';
 $color2off= '</b></font>';
 while (list(, $w) = each($words2)) {
     // Converts reservered words to upper case if not yet done
        $sql_str = substr(eregi_replace('[[:space:]]' . $w . '[[:space:]]', '
 '.$color2on . $w  . $color2off.' ', ' ' . $sql_str), 1);
 }  // end while
 $words3 = array('WHERE','VALUES');
 $color3on = '<font color="#654564"><b>';
 $color3off= '</b></font>';
 while (list(, $w) = each($words3)) {
     // Converts reservered words to upper case if not yet done
        $sql_str = substr(eregi_replace('[[:space:]]' . $w . '[[:space:]]', '
 '.$color3on . $w  . $color3off.' ', ' ' . $sql_str), 1);
 }  // end while
 $words4 = array('IGNORE');
 $color4on = '<font color="#ff22ff"><b>';
 $color4off= '</b></font>';
 while (list(, $w) = each($words4)) {
     // Converts reservered words to upper case if not yet done
        $sql_str = substr(eregi_replace('[[:space:]]' . $w . '[[:space:]]', '
 '.$color4on . $w  . $color4off.' ', ' ' . $sql_str), 1);
 }  // end while
 return $sql_str;
 }   // end of the "sqlColor()" function
 
 //============================================================================
                                                       --
                                                       Nick Knutov
 --- [Жизнеpадостная депpессия]
  * Origin: Just Smile. There is another choice... (2:5054/67.4)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 <без заголовка>   Nick Knutov   24 Dec 2003 18:01:59 
Архивное /ru.perl/147373fe98074.html, оценка 3 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional