in reply to Re: Easy find and replace loop. HELP!
in thread Find and replace by five character string

Good questions, I should have clarified.

the lines are very long and there are a lot of them (these files are very large). I believe the lines are 15,000 characters long and there might be 2,000 of them. there is data on both sides and there can be more than one "0000J" and "0000K" on the same line. The letters go from J to U -12. As for 000-11 or 00-11. they will all always be five characters long. so it is 00-11. I don't know if they are all capitalized, and would like to be prepared if they were not (though I think I know how to make this change in perl). there is certainly no other use for those letters so one need not worry about changing a lowercase that means something else.

thanks again,

walter

  • Comment on Re^2: Easy find and replace loop. HELP!

Replies are listed 'Best First'.
Re^3: Easy find and replace loop. HELP!
by Transient (Hermit) on Aug 10, 2005 at 18:57 UTC
    Here's one way to do your search and replace. I suggest you look into each element of why this works. Opening the file and looping through the lines should be simple enough (there are many tutorials on that). Note that this one will treat upper and lower case characters the same

    Try this example:
    #!/usr/bin/perl use strict; use warnings; my $string = "ABC0000K0000T12345"; $string =~ s/0000([J-U])/my $x=ord(uc($1))-ord('I');('0'x(4-length($x) +)).'-'.$x/ige; print $string, "\n";


    Update (added links)

    s///
    ord
    length

    tutorial on open