Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Removing with regexps

by roboticus (Chancellor)
on Apr 21, 2012 at 17:58 UTC ( [id://966395]=note: print w/replies, xml ) Need Help??


in reply to Removing with regexps

Looking at your data, it looks like you have a word "type" followed by a list of numbered definitions. I think I'd split each record apart at the numbers, discarding the numbers (since otherwise you'll get gaps in numbering anyway). Then I'd filter out the ones I don't want. It goes like this:

use strict; use warnings; while (<DATA>) { s/\s+$//; my ($type, @defs) = split /\(\d+\)/,$_; print "\n------ Word type: $type\n"; @defs = grep { ! m{\(arch\)} } @defs; print "\t$_\n" for @defs; } __DATA__ (n,vs) (1) look; glimpse; glance; (vs) (2) to glance; to glimpse; (3) +(arch) first meeting; (adv) (4) apparently; seemingly; (n-t,n-adv) (1) moment; a (short) time; a while; (2) former times; (3) + (arch) two-hour period;

When I run it, I get this:

$ perl 966375.pl ------ Word type: (n,vs) look; glimpse; glance; (vs) to glance; to glimpse; apparently; seemingly; ------ Word type: (n-t,n-adv) moment; a (short) time; a while; former times;

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

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

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

    No recent polls found