Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: $/ question

by convenientstore (Pilgrim)
on Jan 13, 2008 at 03:13 UTC ( [id://662145]=note: print w/replies, xml ) Need Help??


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

thanks, checking it out now

Replies are listed 'Best First'.
Re^3: $/ question
by convenientstore (Pilgrim) on Jan 13, 2008 at 03:40 UTC
    Below example do not work either.. after putting into paragraph mode
    why?
    I get --> sdfsdfsdf23423
    #!/usr/bin/perl -w
    
    use strict;
    
    sub slurpie {
          while (<DATA>) {
               local $/ = "";   # put into paragraph mode (separated by one or more blank lines
               next unless /^\w\w.+(\w\w).+(\d+).+(\w\w)/sg;  #should only match first paragraph
               print "$_\n";
          }
    }
    
    
    slurpie();
    
    __DATA__
    hi
    hi
    234
    hi
    
    hoi
    sdfsdfsdf23423
    hi
    
    hi
    hi
    1234
    
    1
    

      You're setting a local value to $/ only inside the read loop. That is, the value gets set after the first record is read. At the end of the loop, it's set back to its default value ("\n"), and the next record is read with that value. Then inside the loop, you set the local value again. Try it this way:

      sub slurpie { local $/ = ''; # paragraph mode while (<DATA>) { next unless /^\w\w.+(\w\w).+(\d+).+(\w\w)/sg; #should only ma +tch first paragraph print "$_\n"; } }
        I understand what you are saying but that didn't solve it for some reason
        
                   local $/ = "";   # put into paragraph mode (separated by one or more blank lines
        #!/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).+(\d+).+(\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
        
        
        hoi
        sdfsdfsdf23423
        hi
        
        
        hi
        hi
        1234
        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://662145]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-20 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found