CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
develop the SED command in perl

 



daragorn_1
New User

Sep 15, 2013, 2:01 PM

Post #1 of 5 (582 views)
develop the SED command in perl Can't Post

Hello everyone

i have a task and it is to develop the SED command but in perl

Global replacement, match, slash delimiter etc

can you help me with that?

Regards,

Ken


Laurent_R
Veteran / Moderator

Sep 16, 2013, 10:40 AM

Post #2 of 5 (574 views)
Re: [daragorn_1] develop the SED command in perl [In reply to] Can't Post

The s2p utility already does this. No need to develop it again (unless it is a homework assignment).


daragorn_1
New User

Sep 16, 2013, 12:57 PM

Post #3 of 5 (570 views)
Re: [Laurent_R] develop the SED command in perl [In reply to] Can't Post

yes it is some kind of homework. can somone help me with it?

Regards,

Dotan


BillKSmith
Veteran

Sep 16, 2013, 3:30 PM

Post #4 of 5 (565 views)
Re: [daragorn_1] develop the SED command in perl [In reply to] Can't Post

The first thing you should do is write and debug a suite of test cases that will define the scope of your project. The project will be complete when your simulator passes all the tests. Start with the sed manpage. Write at least one test for every feature that you are required to implement. Without this step, you will probably never finish the project and will not know it if you do. Fully executable tests are desirable and will save you time in the long run, but are not necessary. Your first real task is to parse the command line. Choose a module. You do not want to do this yourself. The last thing to do is implement the sed commands. Add them one at a time. Test them with the test you already made. Repeat all the test frequently to make sure that you have not broken something that had been working.
Good Luck,
Bill


Laurent_R
Veteran / Moderator

Sep 16, 2013, 3:53 PM

Post #5 of 5 (564 views)
Re: [daragorn_1] develop the SED command in perl [In reply to] Can't Post


In Reply To
yes it is some kind of homework. can somone help me with it?


Sure, we can help, but we're not gonna do your assignment in your place. Wink

Please show what you have done and where you're having difficulties, we will help you.

If you haven't got anything so far, this is a starter:


Code
sed 's/MA/Massachussetts/' file.txt


will print to the screen a version of file.txt where occurrences of MA have been replaced by the full state name.

Same thing in Perl:


Code
perl -pe 's/MA/Massachussetts/' file.txt


As you can see, it is very similar, but of course, it will not always be that easy. Actually, a Perl one-liner will not be sufficient, you will have to write an actual Perl program. But the Perl s/// substitution operator will definitely have to be used heavily in your progtram.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives