in reply to Re^5: $/ question
in thread $/ question

Your pattern (/^\w\w.+(\w\w).+(\d+).+(\w\w)/sg), which "should only match the first paragraph", actually matches them all (except the one that's only "1").

/^\w\w.+(\w\w).+(\d+).+(\w\w)/sg h i\n h i \n 234 \n h i /^\w\w.+(\w\w).+ (\d+) .+(\w\w)/xsg h o i\ns d fsdfsdf 23423\n h i /^\w\w.+(\w\w).+(\d+).+(\w\w)/sg h i \n h i \n 1 2 3 4

Try just enumerating the paragraphs:

sub slurpie { local $/ = ''; my $n = 1; while (<DATA>) { printf "*** paragraph %d ***\n", $n++; print; } } slurpie(); __END__ *** paragraph 1 *** hi hi 234 hi *** paragraph 2 *** hoi sdfsdfsdf23423 hi *** paragraph 3 *** hi hi 1234 *** paragraph 4 *** 1

Replies are listed 'Best First'.
Re^7: $/ question
by convenientstore (Pilgrim) on Jan 13, 2008 at 04:22 UTC
    You are right
    thanks

    #!/usr/bin/perl -w
    
    use strict;
    
    sub slurpie {
          local $/ = '';   # put into paragraph mode (separated by one or more blank lines
          while (<DATA>) {
               next unless /^\w\w.+(\w\w).+(\b\d\d\d\b).+(\w\w)/sg;  #should only match first paragraph
               print "$_\n";
          }
    }
    
    
    slurpie();
    
    __DATA__
    hi
    hi
    234
    hi
    
    hoi
    sdfsdfsdf23423
    hi
    
    hi
    hi
    1234
    
    1
    
    
    :!././././././././././perl_slurp.pl
    hi
    hi
    234
    hi