Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: OptiPerls Pattern Replace (Regexpses for one Line)

by Ben Win Lue (Friar)
on Mar 02, 2005 at 10:06 UTC ( #435749=note: print w/ replies, xml ) Need Help??


in reply to Re: OptiPerls Pattern Replace (Regexpses for one Line)
in thread OptiPerls Pattern Replace (Regexpses for one Line)

Thanks for your fast answer. My Problem is not using the RegExp IN the code but ON the code. (Editing / Generating code in the editor). I know the $ meta-character. But somehow i cound not make it work correctly.

Here is an example, I had something like:
 my $foobar = substr($line,20,30);  # this is :;- a comment
which I changed to

#***** # this is :;- a comment #***** sub foobar($){ return substr($_[0],20,30); }
for a couple of hundreds of variables.
for matching the comment at the end of the line, I did something like:
 (#[a-zA-Z0-9 -_;:()]+) I think there must be a more elegant way to do this.


Comment on Re^2: OptiPerls Pattern Replace (Regexpses for one Line)
Select or Download Code
Re^3: OptiPerls Pattern Replace (Regexpses for one Line)
by tphyahoo (Vicar) on Mar 02, 2005 at 10:12 UTC
    This help?
    use warnings; use strict; while (<DATA>) { #everything before the # /^[^#]*/; print 'everything before the #: ' . "$&\n"; #everything from the # to the end of the line /#.*/; print '/#.*/: ' . "$&\n"; print "\n"; } #outputs: #everything before the #: blah #/#.*/: #this is a comment # #everything before the #: foo blah #/#.*/: #this is a comment # #everything before the #: foo bar blah blah blah #/#.*/: #this is a comment # #everything before the #: # #/#.*/: # __DATA__ blah #this is a comment foo blah #this is a comment foo bar blah blah blah #this is a comment

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2014-10-01 00:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (386 votes), past polls