pattern matching

Discussion in 'Perl Misc' started by pavan734@gmail.com, Apr 20, 2006.

  1. Guest

    hi Iam pavan . I need to run a perl script that runs on a file and does
    the following.

    The file may look like like this
    pavan.h:

    pavan_here hi how r u
    pavan_there Iam fine
    pavan_now typing

    Search for words containing pavan(say)
    In the above example it much search for pavan_here, pavan_there ,
    pavan_now and modify those words such that
    1.underscores must be eliminated
    2. Next letter to underscore(i.e anyletter after underscore) must
    become capital.


    I mean to say when I run the script the file must modify to

    pavanHere hi how r u
    pavanThere Iam fine
    pavanNow typing

    Hope you understood the problem
     
    , Apr 20, 2006
    #1
    1. Advertising

  2. wrote:
    > hi Iam pavan . I need to run a perl script


    If your system is set up properly then you can run a perl script simply by
    typing it's name on the command line.
    If that is not your problem then we will need much more details about your
    system and how exactly you are trying to run the script.

    > that runs on a file and
    > does the following.
    >
    > The file may look like like this
    > pavan.h:
    >
    > pavan_here hi how r u
    > pavan_there Iam fine
    > pavan_now typing
    >
    > Search for words containing pavan(say)
    > In the above example it much search for pavan_here, pavan_there ,
    > pavan_now and modify those words


    To modify text people often use the 's' (aka substitute) function

    > such that
    > 1.underscores must be eliminated


    This could also be done by the 'tr' function

    > 2. Next letter to underscore(i.e anyletter after underscore) must
    > become capital.


    The easiest way is probably to use the 'ucfirst' function.

    > I mean to say when I run the script the file must modify to
    >
    > pavanHere hi how r u
    > pavanThere Iam fine
    > pavanNow typing
    >
    > Hope you understood the problem


    I understand your goal (at least I think), that was a good description.
    But you didn't explain what your problem is nor did you give us enough
    information to fix it. Where are you stuck? Which part of your program is
    not working as expected? Where is your program to begin with?

    jue
     
    Jürgen Exner, Apr 20, 2006
    #2
    1. Advertising

  3. Guest

    Sorry, I have not written any script at all. I know how to run a
    script. But I want a code to do that. Also tell me whether is it
    possible in vim "search and replace" command.
     
    , Apr 20, 2006
    #3
  4. wrote in news:1145542973.014914.65260
    @z34g2000cwc.googlegroups.com:

    > Sorry, I have not written any script at all.


    Please read the posting guidelines for this group, and then write a
    script that attempts to accomplish what you want.

    Then, come back here and ask about issues you can't solve.

    > I know how to run a script. But I want a code to do that.


    I think the going consulting rate here is about $100. Unfortunately,
    most of us have really busy schedules, which means we can't take on new
    clients all the time.

    This is not a "write my code for me" service.

    > Also tell me whether is it
    > possible in vim "search and replace" command.


    comp.editors

    Sinan
    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Apr 20, 2006
    #4
  5. Guest

    This is a generic question ...... A single vim command can do it. But I
    dont know much abt vim.
     
    , Apr 20, 2006
    #5
  6. wrote in news:1145544839.833962.38220
    @g10g2000cwb.googlegroups.com:

    > This is a generic question ...... A single vim command can do it. But I
    > dont know much abt vim.


    Then learn. On your own or with the help of the friendly people over in
    comp.editors.

    I won't be seeing your posts again.

    Sinan

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Apr 20, 2006
    #6
  7. wrote:
    [What are you replying to? Please quote appropriatly -as has been customary
    in Usenet for 2 decades- such that people have a chance to know what your
    are talking about.]

    > Sorry, I have not written any script at all.


    No problem. Now is as good a time to start as any. I recommend "Learning
    Perl", availaible in your favourite book store.

    > I know how to run a
    > script.


    Good.

    > But I want a code to do that.


    Trying to understand: you want to run your script from your code? Please see
    "perldoc -f system".

    > Also tell me whether is it
    > possible in vim "search and replace" command.


    Maybe you should ask in a NG that deals with vim about if it is possible to
    run a script in the vim "search and replace" command.

    jue
     
    Jürgen Exner, Apr 20, 2006
    #7
  8. Xicheng Jia Guest

    wrote:
    > This is a generic question ...... A single vim command can do it. But I
    > dont know much abt vim.


    see your posts at comp.unix.shell

    Xicheng
     
    Xicheng Jia, Apr 20, 2006
    #8
  9. wrote:
    > This is a generic question ...... A single vim command can do it. But
    > I dont know much abt vim.


    What is a generic question? I don't see any in your post.

    jue
     
    Jürgen Exner, Apr 20, 2006
    #9
  10. robic0 Guest

    On Thu, 20 Apr 2006 14:45:42 GMT, "A. Sinan Unur" <> wrote:

    > wrote in news:1145542973.014914.65260
    >@z34g2000cwc.googlegroups.com:
    >
    >> Sorry, I have not written any script at all.

    >
    >Please read the posting guidelines for this group, and then write a
    >script that attempts to accomplish what you want.
    >
    >Then, come back here and ask about issues you can't solve.
    >
    >> I know how to run a script. But I want a code to do that.

    >
    >I think the going consulting rate here is about $100. Unfortunately,
    >most of us have really busy schedules, which means we can't take on new
    >clients all the time.


    HUH? 100? Per hour? Where can I get that kind of work?
     
    robic0, Apr 20, 2006
    #10
  11. <> wrote:

    > Search for words containing pavan(say)


    > modify those words such that
    > 1.underscores must be eliminated
    > 2. Next letter to underscore(i.e anyletter after underscore) must
    > become capital.



    ---------------------
    #!/usr/bin/perl
    use warnings;
    use strict;

    while ( <DATA> ) {
    s/pavan_(\w)/paven\U$1/g;
    print;
    }

    __DATA__
    pavan_here hi how r u
    pavan_there Iam fine
    pavan_now typing
    ---------------------


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Apr 20, 2006
    #11
  12. Guest

    Thanks a lot. This code is working for me.
     
    , Apr 21, 2006
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DelphiDude
    Replies:
    3
    Views:
    1,191
  2. danpres2k
    Replies:
    3
    Views:
    7,519
    danpres2k
    Aug 25, 2003
  3. CV
    Replies:
    2
    Views:
    609
    Charles DeRykus
    Aug 31, 2004
  4. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    263
    Marc Bissonnette
    Jan 13, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    268
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page