[Perl] Новичкам: задаем вопросы

Discussion in 'PHP' started by _Great_, 26 May 2007.

Thread Status:
Not open for further replies.
  1. $p01nt

    $p01nt Elder - Старейшина

    Joined:
    19 Feb 2008
    Messages:
    116
    Likes Received:
    20
    Reputations:
    1
    помогите с регуляркой ! <font style="font-size: 12pt; font-family:Arial; color:#335DA3; text-decoration: none "><b>XXXXXXXXXXXXXX</b></font>
    найти XXXXXXXXXXXXXX
     
  2. Piflit

    Piflit Banned

    Joined:
    11 Aug 2006
    Messages:
    1,249
    Likes Received:
    585
    Reputations:
    31
    $a = '<font style="font-size: 12pt; font-family:Arial; color:#335DA3; text-decoration: none "><b>XXXXXXXXXXXXXX</b></font>';
    my ($b) = $a =~ /<b>[^<]+<\/b>/;
     
  3. Roba

    Roba Banned

    Joined:
    24 Oct 2007
    Messages:
    237
    Likes Received:
    299
    Reputations:
    165
    Code:
    if ($s =~ /text-decoration: none \"><b>(\d{1,10})<\/b>/) { print $1 }
    
    поясни конкретней, какие могут входить символы в захват
     
    #423 Roba, 30 Apr 2008
    Last edited: 30 Apr 2008
  4. desTiny

    desTiny Elder - Старейшина

    Joined:
    4 Feb 2007
    Messages:
    1,006
    Likes Received:
    444
    Reputations:
    94
    Нехорошо так делать...

    <font style="font-size: 12pt; font-family:Arial; color:#335DA3; text-decoration: none "><B>Hello <i>to</i> all!</b></font>

    вообще ничего не выдаст, и

    <font style="font-size: 12pt; font-family:Arial; color:#335DA3; text-decoration: none "><и>Hello <i>to</i> all!</b></font>

    тоже обломится...
     
  5. $p01nt

    $p01nt Elder - Старейшина

    Joined:
    19 Feb 2008
    Messages:
    116
    Likes Received:
    20
    Reputations:
    1
    Pifit Ответ не верный ) если искать только по тегу <b> то у меня еще куча не нужного найдется , поэтому я и дал с тегом <font> . ZAMUT нет текст
     
    #425 $p01nt, 30 Apr 2008
    Last edited: 30 Apr 2008
  6. $p01nt

    $p01nt Elder - Старейшина

    Joined:
    19 Feb 2008
    Messages:
    116
    Likes Received:
    20
    Reputations:
    1
    Zamut - там русские символы ) пробывал А-я н подходит (
     
  7. FooBar

    FooBar Banned

    Joined:
    28 Jan 2008
    Messages:
    13
    Likes Received:
    6
    Reputations:
    -5
    /<font style="font-size: 12pt; font-family:Arial; color:#335DA3; text-decoration: none "><b>(.*)<\/b><\/font>/;
     
    1 person likes this.
  8. Piflit

    Piflit Banned

    Joined:
    11 Aug 2006
    Messages:
    1,249
    Likes Received:
    585
    Reputations:
    31
    $p01nt ты покажи типы возможных вариантов. от них зависит регулярка
     
  9. $p01nt

    $p01nt Elder - Старейшина

    Joined:
    19 Feb 2008
    Messages:
    116
    Likes Received:
    20
    Reputations:
    1
    #!usr/bin/perl

    use strict;
    use LWP::Simple;

    open(FIL,">spars.txt");

    my $url='http://mariel.ru/index.html';
    my $content=get $url;

    my $pervzagal=$content;
    my $pervtext=$content;
    $pervzagal=~/<font style="font-size: 12pt; font-family:Arial; color:#335DA3; text-decoration: none "><b>(.*)<\/b><\/font>/g;
    print FIL $1;
    $pervtext=~/<div style="margin-top: 8px; margin-bottom: 2px">(.*)&nbsp;<a href=Article1579.html style="font-size: 8pt; font-weight: normal; font-family:Arial; color:#335da3; text-decoration: underline ">/g;
    print FIL $2;

    не получается спарсить pervtext , в чем ошибка ?
     
  10. FooBar

    FooBar Banned

    Joined:
    28 Jan 2008
    Messages:
    13
    Likes Received:
    6
    Reputations:
    -5
    во втором надо $1 у тебя ведь только одно вхождение
     
    1 person likes this.
  11. $p01nt

    $p01nt Elder - Старейшина

    Joined:
    19 Feb 2008
    Messages:
    116
    Likes Received:
    20
    Reputations:
    1
    я пробывал - он выводит то же что и в pervzagal
     
  12. z01b

    z01b Муджахид

    Joined:
    5 Jan 2007
    Messages:
    494
    Likes Received:
    382
    Reputations:
    22
    Нужен хороший туториал по регексам для новичков.
     
  13. demonoid

    demonoid Banned

    Joined:
    12 Jan 2007
    Messages:
    101
    Likes Received:
    111
    Reputations:
    27
    Code:
    perldoc perlre
     
  14. $p01nt

    $p01nt Elder - Старейшина

    Joined:
    19 Feb 2008
    Messages:
    116
    Likes Received:
    20
    Reputations:
    1
    и опять вопрос и опять по регуляркам :) Допустим есть такой текст :

    http://www.mail.com http://www.gmail.com http://www.yahoo.com

    Нужно найти только mail.com gmail.com yahoo.com
    Я делаю так

    $text="http://www.mail.com http://www.gmail.com http://www.yahoo.com";
    $text=~/http:\/\/www\.(.?) h/ig;
    print $1;
    print $2;
    print $3;

    И мне выводит только www.mail.com . В чем ошибка ? И как можно заменять $1 , $2 etc. одним выражением?
     
  15. Piflit

    Piflit Banned

    Joined:
    11 Aug 2006
    Messages:
    1,249
    Likes Received:
    585
    Reputations:
    31
    while($text=~/http:\/\/www\.(\S+)/ig)
    print $1;
     
  16. z01b

    z01b Муджахид

    Joined:
    5 Jan 2007
    Messages:
    494
    Likes Received:
    382
    Reputations:
    22
    Кукую Ide вы используете для создания скриптов на перл?
     
  17. $p01nt

    $p01nt Elder - Старейшина

    Joined:
    19 Feb 2008
    Messages:
    116
    Likes Received:
    20
    Reputations:
    1
    Piflit что то не компилится:(

    ZOB - vi :)
     
  18. demonoid

    demonoid Banned

    Joined:
    12 Jan 2007
    Messages:
    101
    Likes Received:
    111
    Reputations:
    27
    Эхх.
    Code:
    $text = "http://www.mail.com http://www.gmail.com http://www.yahoo.com";
    @a = $text =~ m[http://www.(\w+.com)]g;
    vi - редактор не более
    Komodo - отличный Ide
     
  19. grishka

    grishka Active Member

    Joined:
    11 Aug 2007
    Messages:
    157
    Likes Received:
    255
    Reputations:
    4
    Есть скрипт приглашения вконтакте:
    Code:
    #!/usr/bin/perl
    use strict;
    use warnings;
    use threads;
    use threads::shared;
    use IO::Socket::INET;
    
    my $startId : shared;
    
    $startId = 4762539;
    my $cookie = 'remixpass=ПАРОЛЬ; remixemail=ЛОГИН%40(mail.ru); remixmid=ВАШ АЙДИ;
    my $threads = 4;
    my @thread;
    for(0..$threads) { $thread[$_] = threads->create(\&flood); }
    for(0..$threads) { $thread[$_]->join; }
    
    sub flood {
         while (1) {
             if ( my $socket = new IO::Socket::INET(PeerAddr => 'vkontakte.ru', PeerPort => 80, Proto    => 'tcp') ) {
              { lock($startId); $startId++; print $startId."\n"}
                  print $socket "HEAD http://vkontakte.ru/matches.php?act=a_sent&to_id=$startId&dec=1 HTTP/1.1\r\n".
                         "Host: vkontakte.ru\r\n".
                               "Cookie: $cookie\r\n\r\n";
                 close $socket
                 }
             }
    }
    Можите подсказать где ошибка?
     
    7 people like this.
  20. demonoid

    demonoid Banned

    Joined:
    12 Jan 2007
    Messages:
    101
    Likes Received:
    111
    Reputations:
    27
    Code:
    my $cookie = 'remixpass=ПАРОЛЬ.....Ш АЙДИ;
    Скобу не закрыл
     
    1 person likes this.
Thread Status:
Not open for further replies.