Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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?
[marto]: erix unlikely, we've had posts within the last few minutes ;)
[ambrus]: nysus: make sure you enter at least two lines for the title and then preview, and read warnings the preview form prints
[davies]: There is an option (I have it set) to force preview before submission. Perhaps your option has been set (accidentally?) and you are not expecting it.
[ambrus]: sorry, I mean at least two words for the title and then preview
[ambrus]: davies: that option is the default. and it's not really "force", it just hides the button.
[marto]: yes, not reading the errors displayed has been a cause of this type of report in the past
[nysus]: Ambrus, ah. I think that was the problem. I'll try. Thanks!
[davies]: Ambrus: you've missed it by a couple of weeks, but consider next year's London Perl Workshop.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (12)
As of 2017-12-15 11:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (431 votes). Check out past polls.

    Notices?