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

Re: Help!! Regular Expressions

by providencia (Pilgrim)
on Apr 12, 2001 at 20:06 UTC ( [id://72081]=note: print w/replies, xml ) Need Help??


in reply to Regular expression to match text between two tags (was: Help!! Regular Expressions)

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found