Beefy Boxes and Bandwidth Generously Provided by pair Networks Russ
No such thing as a small change
 
PerlMonks  

Re: regular expression help

by amphiplex (Monk)
on Jul 17, 2002 at 12:38 UTC ( [id://182499]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to regular expression help

This should do the job:
my @results; while (<>) { if (/^N\d+\s+\*(.*)/) { push @results, "!$1"; } else { push @results, /[XYZ]([-+]*[\d\.]+)/g; } } print join ' ',@results;
The first regex handles comment lines, the second one greps all occurances of either an X,Y or Z followed optionally by a negative or positive sign followed by a combination of digits and dot.

If there is only one comment line on the top of each file, you could do this faster, but for a couple of thousand lines it should not matter.

update: the code was wrong, I forgot the * after the sign match.

---- amphiplex

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://182499]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.