----- Original Message ----- 
From: "Jorge Goncalves" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: <[EMAIL PROTECTED]>
Sent: Friday, June 18, 2004 4:35 AM
Subject: Re:seach a number in a file


> Hi, I have a text file like this:

[snip file contents, they're posted below]

> How can i do in Perl to get the first number if the last part of the
> line doesn't contains extractStat.
> for exemple here to get only the number 7.
>
> Thanks

Hello Jorge,
This code will do what you want. You may also want to check:

    For the 'm' modifier
        perldoc perlretut (see using character classes)
        perldoc perlre

    Could not find docs for the 'g' modifier. Maybe someone else could point
out where it is best explained.

Chris

#!/usr/bin/perl
use strict;
use warnings;

{
     local $/;    # undefine input record separator - read in whole file as
1 line ($file).
     my $file = <DATA>;
    # m modifier allows ^ to match immediately after a newline, and $ to
match preceding a newline
    # g modifier is for a progressive match - start next match immediately
after end of previous one
     while ($file =~ /^\s+(\d+).+\n(.+)$/mg) {
          print $1 unless $2 =~ /extractStat/;
     }
}

__DATA__
        1   Chaque L Ma Me J V S D  00:20
D:\muse\lotus\notes\extractStat.exe StatA090 j
        2   Chaque L Ma Me J V S D  00:21
D:\muse\lotus\notes\extractStat.exe StatA090 m
        3   Chaque L Ma Me J V S D  00:22
D:\muse\lotus\notes\extractStat.exe StatA090 h
        4   Chaque L Ma Me J V S D  00:23
D:\muse\lotus\notes\extractStat.exe StatB090 j
        5   Chaque L Ma Me J V S D  00:27
D:\muse\lotus\notes\extractStat.exe StatPMF090 m
        6   Chaque L Ma Me J V S D  00:28
D:\muse\lotus\notes\extractStat.exe StatPMF090 h
        7  Aujourd'hui                          20:00
D:\muse3\test.exe
        8   Chaque L Ma Me J V S D  00:28
D:\muse\lotus\notes\extractStat.exe StatPMF090 h



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to