Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

simple pattern matching.

by eoin (Monk)
on Apr 19, 2003 at 19:43 UTC ( #251695=perlquestion: print w/replies, xml ) Need Help??

eoin has asked for the wisdom of the Perl Monks concerning the following question:

Hey all,
thanks for all the help before, especially to tall_man.
Heres my latest faidbh.
I have a data file writen like so:
fnlPfnrff3xvf31vfWrdaMIXMhAHtCALVrMcZ7 Od6cWuetY86lY8aMSnNCEHsxAHMxAFIpAFIpCEopAFIYAFI5CHtSEJxKCOfOjOfOnN6USm +Mx ADkQADkpAEoxCFI5GKVrENacOdaMMeetSt6tSsaMKbVzGEopCGNCEMZ7Kb2cjEoIAIw5AE +oY ALWte7WchMa9hNa9jLWcY8aEGIxaAHNCAHtSAGNCAKVaAMa1e7V7OYxKGJRSCKV7SqVrOb +WU UrWESqV7OSkIALW1hMa9lK2te7W1lL29pbWtlMate7WEGMacY6V7KffGa0pCMXNaQrWclO +/n xvfWpcbGpdbOpdbGrd7evdbOlNa1pb17Oe+tY5yUe7WEWsaMY8aMWoxrUpRrGPfOe6WEOZ +Rz GL17Md6tWnNKENa9rWMxEKWEKZRKEL1zIZxCAL1jKYxKCPfOc/fehKVzGKVrAJxaALVzCK +V7 GJRrEP///////////////////////////ywAAAAA5QGqAAAI/wABCBQYQGCAgQEGDgwAIE +AA AQACDBw4UGCAAAIEBggQAICAAAMHBggwcCCAAAIDAAggAEAAgQEECgAgYKAAAQIABBAgME +AA gQICCAAQIMDAgQMHDhQYQMAAAQIDCAwwcKDAAAMDDBwocEAAAQACDBw4EECAAAEECAQYQO +BA gAAEDgwQYOBAAAEEBgAQQECAgQEECgAQYKAAAQEABBAgUECAAAAEBBAAIMDAgQMHDhwYQI +AA AQMBBBg4MIDAAAMDDBwoMEAAAQACDBw4EEAAAAEECAQYQOBAgAAEDgwAIMDAgQEGBgAgIM +DA AAIFABgwUIAAAQACCBAoIEAAAAICCP8IACDAwIEDBw4UGEBAAAECAwgMMHCgwAADAwwcKD +BA AAECAwwcOBBAgAACBAIMIHAgQAACBwYIMHAggAACAwAIIABAAIEBBAoAECCAQAECAgAIIE +Cg gAABAAgIIABAgAABBgoMMHDgwIEDAwAQEGDgwIEDAwQIEABAAAEBBg4UGGDgwIEBAAQYOD +DA QIECAgQIMFBAgAAAAggIEEBgAAEAAgwcKDDAwIEDBwIAGECgQAEAAAAAEACAAIAABA4kWB +BA AAEBDAoMQFBAAIEBBAQIYBBAAIMDAwAIQDAAgAAFBQQIEGCggAABAAQIEECAwAABAAQIYB +BA AIMGAQQIECD/AAABAQoGMGhwYAAAAgIYNBggQACBAQQECGAQQIAABgUGABDAYICCAgIECD +Aw QIAAAAIECCBAYIAAAAIACGDQoEGBAQIECAAgQICCAgwaHBgAAAGDBgUGECAwgIAAAQwCCG +Bw YAAAAQwGIBggQAAAAQYKACAAQIAAAQQIDBAAQAAAAQQACAAgQIAAAAIMABAAQACDBAMECG +BQ YACBAQYEGBAAwIAAAQIUDBAgQAAAAQYGCBAggMAAAQIMDDBwAIAABgkECBBAQAABAQIACC +Ag gACCAQIEABBAIMAAAAAACAAAQAAAAAAAEAAAgAABAQIACBAAQIABAwAECBAAIACB
You get the idea.. A whole load of data seperated by "/" foward slashes. What I need is something to find the fist set of "//" doubles and insert text between them.
Its been a while since I've done anything like this and I can't find a solution in any of my old scripts. Seeing as I've only been at it for less than a year I don't have many old scripts that I've kept.
I appriciate any help you can give.
Thanks in advance

All the Best, Eoin...

If everything seems to be going well, you obviously don't know what the hell is going on.

Replies are listed 'Best First'.
Re: simple pattern matching.
by Abigail-II (Bishop) on Apr 19, 2003 at 19:55 UTC
    Assuming you have the text in $_:
    s!//!/New text/!;

    Abigail

Re: simple pattern matching.
by Coruscate (Sexton) on Apr 19, 2003 at 19:57 UTC

    Simply whip out your regular expressions and come up with something like the snippet below. Really... this was quite simple :)

    my $foo = qq{ fnlPfnrff3xvf31vfWrdaMIXMhAHtCALVrMcZ7 Od6cWuetY86lY8aMSnNCEHsxAHMxAFIpAFIpCEopAFIYAFI5CHtSEJxKCOfOjOfOnN6USm +Mx ADkQADkpAEoxCFI5GKVrENacOdaMMeetSt6tSsaMKbVzGEopCGNCEMZ7Kb2cjEoIAIw5AE +oY ALWte7WchMa9hNa9jLWcY8aEGIxaAHNCAHtSAGNCAKVaAMa1e7V7OYxKGJRSCKV7SqVrOb +WU UrWESqV7OSkIALW1hMa9lK2te7W1lL29pbWtlMate7WEGMacY6V7KffGa0pCMXNaQrWclO +/n xvfWpcbGpdbOpdbGrd7evdbOlNa1pb17Oe+tY5yUe7WEWsaMY8aMWoxrUpRrGPfOe6WEOZ +Rz GL17Md6tWnNKENa9rWMxEKWEKZRKEL1zIZxCAL1jKYxKCPfOc/fehKVzGKVrAJxaALVzCK +V7 GJRrEP///////////////////////////ywAAAAA5QGqAAAI/wABCBQYQGCAgQEGDgwAIE +AA AQACDBw4UGCAAAIEBggQAICAAAMHBggwcCCAAAIDAAggAEAAgQEECgAgYKAAAQIABBAgME +AA gQICCAAQIMDAgQMHDhQYQMAAAQIDCAwwcKDAAAMDDBwocEAAAQACDBw4EECAAAEECAQYQO +BA gAAEDgwQYOBAAAEEBgAQQECAgQEECgAQYKAAAQEABBAgUECAAAAEBBAAIMDAgQMHDhwYQI +AA AQMBBBg4MIDAAAMDDBwoMEAAAQACDBw4EEAAAAEECAQYQOBAgAAEDgwAIMDAgQEGBgAgIM +DA AAIFABgwUIAAAQACCBAoIEAAAAICCP8IACDAwIEDBw4UGEBAAAECAwgMMHCgwAADAwwcKD +BA AAECAwwcOBBAgAACBAIMIHAgQAACBwYIMHAggAACAwAIIABAAIEBBAoAECCAQAECAgAIIE +Cg gAABAAgIIABAgAABBgoMMHDgwIEDAwAQEGDgwIEDAwQIEABAAAEBBg4UGGDgwIEBAAQYOD +DA QIECAgQIMFBAgAAAAggIEEBgAAEAAgwcKDDAwIEDBwIAGECgQAEAAAAAEACAAIAABA4kWB +BA AAEBDAoMQFBAAIEBBAQIYBBAAIMDAwAIQDAAgAAFBQQIEGCggAABAAQIEECAwAABAAQIYB +BA AIMGAQQIECD/AAABAQoGMGhwYAAAAgIYNBggQACBAQQECGAQQIAABgUGABDAYICCAgIECD +Aw QIAAAAIECCBAYIAAAAIACGDQoEGBAQIECAAgQICCAgwaHBgAAAGDBgUGECAwgIAAAQwCCG +Bw YAAAAQwGIBggQAAAAQYKACAAQIAAAQQIDBAAQAAAAQQACAAgQIAAAAIMABAAQACDBAMECG +BQ YACBAQYEGBAAwIAAAQIUDBAgQAAAAQYGCBAggMAAAQIMDDBwAIAABgkECBBAQAABAQIACC +Ag gACCAQIEABBAIMAAAAAACAAAQAAAAAAAEAAAgAABAQIACBAAQIABAwAECBAAIACB }; $foo =~ s#/{4}#//I got inserted!//#; print $foo, "\n";


    If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.

      That worked brilliant..... BUT
      Is it possible to recover the text that you insert into the data??
      Thanks
      All the Best, Eoin...

      If everything seems to be going well, you obviously don't know what the hell is going on.

        Assuming the data is in $_,
        my ($text) = m!/([^/]+)/!;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2019-08-19 23:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If you were the first to set foot on the Moon, what would be your epigram?






    Results (141 votes). Check out past polls.

    Notices?