Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Regular expressions

by GrandFather (Saint)
on Jul 20, 2005 at 10:16 UTC ( [id://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?

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others musing on the Monastery: (5)
    As of 2024-06-21 18:15 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found

      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.