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

Re: Open to suggestions on a search and replace..

by I0 (Priest)
on Apr 12, 2002 at 05:49 UTC ( #158493=note: print w/replies, xml ) Need Help??


in reply to Open to suggestions on a search and replace..

$line =~ s/^(R.*\$SUB=)<\*\d+>/$1/;

Replies are listed 'Best First'.
Re: Re: Open to suggestions on a search and replace..
by tachyon (Chancellor) on Apr 12, 2002 at 11:05 UTC

    You can use a positive lookahead assertion to avoid having to reinsert $1.

    $line =~ s/^(?=R.*\$SUB=)<\*\d+>//;

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      You can use a positive lookahead assertion to avoid having to reinsert $1. $line =~ s/^(?=R.*\$SUB=)<\*\d+>//;

      aehhm, this won't work. The lookahead doesn't move the position in your regex, so you are effectively looking for /^<\*\d+>/ which isn't there. Instead you would need a look behind assertion but they are only available for constant length.

      As I understand the file format there are no other digits in angle brackets starting with a star. So why not simply write: s/<\*\d+>//;

      Update: As of Rhodium's clarification of the specs, I would now fully recommend IO's solution.

      -- Hofmator

        Hey Hof,
        As I understand the file format there are no other digits in angle brackets starting with a star.
        That is something I don't want to assume..
        Rhodium

        The <it>seeker</it> of perl wisdom.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://158493]
help
Chatterbox?
[thezip]: My doggies love it when it snows
[perldigious]: As long as you are a good "boy scout" stevieb, more power to you... but I like my Jeep, and don't like the idea of rolling it or crashing it in to anything. :-)
[thezip]: Me, not as much.
[perldigious]: Mine too thezip, especially my German Shepherd. He looks like he is about to die of heat exhaustion all summer, so he goes nuts when winter comes and he can play in the snow.
[stevieb]: my main off-road vehicle nowadays is a strengthened mercedes ML320. I'm very hard on it, but I've never had any real issues at all (I love how small and light it is, and it has a very, very good centre of gravity for how I roll)
[perldigious]: "for how I roll"... ahhh, I see what you did there stevieb.

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (13)
As of 2016-12-06 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.