Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Regular expressions

by GrandFather (Saint)
on Jul 20, 2005 at 10:16 UTC ( #476453=note: print w/replies, xml ) Need Help??


in reply to Regular expressions

Two problems:

  • Missing space in <!--Start_of_revision-->
  • if rather than while

    A working version of your code in a form that is better for stand alone testing is:

    use strict; use warnings; my $text = join "", <DATA>; while($text =~ /<!-- Start_of_revision-->(.*?)<!-- End_of_revision-->/ +sg) { print $1; } __DATA__ <!-- Start_of_revision--> revision1 <!-- End_of_revision--> <!-- Start_of_revision--> revision2 <!-- End_of_revision--> <!-- Start_of_revision--> revision3 <!-- End_of_revision-->
    revision1 revision2 revision3

    Perl is Huffman encoded by design.
  • Replies are listed 'Best First'.
    Re^2: Regular expressions
    by ikegami (Patriarch) on Jul 20, 2005 at 14:56 UTC

      That's an aweful way of reading a file. It means every line must be pushed onto the stack. The OP's method was better, and the following is even better because it avoids a call to stat and works will all kinds of IO handles:

      my $text; { local $/; $text = <DATA>; }

      Visually, I prefer
      my $text = do { local $/; <DATA> };
      but I think I determined the above is equivalent to
      my $text; { local $/; my $temp = <DATA>; $text = $temp; }

        The reason I am a monk is to learn from the masters. I keep forgetting about $/! I hope I have learned :). Thank you.


        Perl is Huffman encoded by design.

    Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (2)
    As of 2023-03-25 05:12 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Which type of climate do you prefer to live in?






      Results (62 votes). Check out past polls.

      Notices?