Okay here's what I learned today from a friend.
"You are sipping when you should be slurping."
Of course if I had told you all what I was doing before
that line you would have definitely seen my real problem.
Okay here's close to what I did have (I burned that code long ago):
#!/usr/bin/perl -w
use strict;
open(FH, '-'); # using STDIN instead of a real file.
while (<FH>){
my $entry = $_ =~ /:::(.*?):::/ms;
open(FH2,'>filename');
print FH2 "$entry";
}
Of course this didn't work because I was only working with
the first line and what I wanted was further in the file
and on multiple lines.
Here's what I am using.
#!/usr/bin/perl -w
use strict;
open(FH,'-');
my $file = do {local $/; <FH>};
#A really elegant way to slurp an entire file and fast too.
#It creates a "disposable subroutine" in effect.
#I can't take credit for coming up with it though.
close FH;
open(FH2,">filename");
my $entry = $file =~ /:::(.*?):::/ms;
#Thanks Corion
print FH2 "$1\n";
Thanks everyone. I liked the hint dws.
Thanks Corion for telling me about the not so greedy (.*?).
I liked the hint dws.
I learned from that hint but it wouldn't work for me until I slurped. :)
I'm REAL glad to know about perlre until I can make time for Mastering Regular Expressions