Appending at various locations.

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Appending at various locations.

    I have to ask the user to input any two digits e.g input= 3,5 (their
    value can be upto 300-whole numbers only). These two numbers have to
    be associated with multiple strings. As an example, 3 is associated
    to "hello" and 5 is associated to "cool". After the input, an existing
    file at various locations should be edited automatically. These
    locations can be determined by certain strings e.g "howr u" and "is
    it hot" etc? Once these strings are searched and found, then text like
    hello_1, hello_2, hello_3 and cool_1, cool_2,cool_3,cool_4, etc
    should be added to this file. The
    number of times hello_1, hello_2 etc and cool_1, cool_2 etc. should
    be added depends on the users input.
    e.g

    a file contains some text.
    some text..... i m from the city..... "how r u" ..... how is the weather there
    "is it hot".......thats good.

    when the user inputs 3, 5. The file should then be edited to

    some text ..... i m from the city ...."how r u" hello_1,hello_2,hello_3 .....
    how is the weather there "is it hot" cool_1,cool_2, cool_3, cool_4,
    cool_5........thats good.

    ============================================

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

    print "enter counts for 'hello' and 'cool' with a space in
    between: ";
    my $nums = <STDIN>;

    # key=word, value=count for that word
    my %word_count;
    @word_count{ 'hello', 'cool' } = split /\s+/, $nums; # a "hash
    slice"

    # key=search phrase, value=the word to tack on when found
    my %words = ( '"how r u"' => 'hello', '"is it hot"' => 'cool' );

    # key=search phrase, value=string with the right # of words/commas
    my %patterns;

    foreach my $pat ( keys %words ) {
    $patterns{$pat} = join ',', map { "$words{$pat}_$_" }
    1 .. $word_count{$words{$pat}};
    }

    open(FILEREAD, "data") or die "Can't open data: $!\n";

    my $pattern = join '|', keys %patterns;

    open(F,">>data") or die "Can't open data: $!\n";
    while (<FILEREAD>) {
    s/($pattern)/$1 $patterns{$1}/g;
    print F $_;
    };
    close(F);

    close(FILEREAD);
    ======================================
    MJS Guest

  2. Similar Questions and Discussions

    1. Appending FLV files together on the fly
      I have a website that accepts video uploads. I then of a content management tool that always me to browse and uploaded videos and approve or deny...
    2. Web Locations
      Hi everyone! I work in an environment that restricts web access via a filter. Due to this, I need to know from where does shockwave/flash obtain...
    3. Appending to a string?
      How the heck do you append to a string doing something like this... if it is defined append a "|" and then the var to the end of a string <cfif...
    4. Specifying Grid Locations
      Hi, I have this problem which I need the solution to ASAP. I have started developing a program which requires snapping of sprites to nearest...
    5. Appending at various locations
      I have to ask the user to input any two digits e.g input= 3,5 (their value can be upto 300-whole numbers only). These two numbers have to be...
  3. #2

    Default Re: Appending at various locations.


    "MJS" <tabletdesktop@yahoo.com> wrote in message
    news:f0171209.0309071012.606a61bd@posting.google.c om...
    > I have to ask the user to input any two digits e.g input= 3,5 (their
    > value can be upto 300-whole numbers only). These two numbers have to
    > be associated with multiple strings. As an example, 3 is associated
    > to "hello" and 5 is associated to "cool". After the input, an existing
    > file at various locations should be edited automatically. These
    > locations can be determined by certain strings e.g "howr u" and "is
    > it hot" etc? Once these strings are searched and found, then text like
    > hello_1, hello_2, hello_3 and cool_1, cool_2,cool_3,cool_4, etc
    > should be added to this file. The
    > number of times hello_1, hello_2 etc and cool_1, cool_2 etc. should
    > be added depends on the users input.
    > e.g
    >
    > a file contains some text.
    > some text..... i m from the city..... "how r u" ..... how is the weather
    there
    > "is it hot".......thats good.
    >
    > when the user inputs 3, 5. The file should then be edited to
    >
    > some text ..... i m from the city ...."how r u" hello_1,hello_2,hello_3
    ......
    > how is the weather there "is it hot" cool_1,cool_2, cool_3, cool_4,
    > cool_5........thats good.
    >
    [script snipped]

    .... And your question is?


    James E Keenan Guest

  4. #3

    Default Re: Appending at various locations.

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    [email]tabletdesktop@yahoo.com[/email] (MJS) wrote in
    news:f0171209.0309071012.606a61bd@posting.google.c om:
    > I have to ask the user to input any two digits e.g input= 3,5 (their
    > value can be upto 300-whole numbers only). These two numbers have to
    > be associated with multiple strings. As an example, 3 is associated
    ....

    Didn't you post this about a month ago?

    - --
    Eric
    $_ = reverse sort $ /. r , qw p ekca lre uJ reh
    ts p , map $ _. $ " , qw e p h tona e and print

    -----BEGIN PGP SIGNATURE-----
    Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

    iQA/AwUBP1xZ0GPeouIeTNHoEQJZvgCg8Y60jVSZeUxbTGt3NxDgAy 4RX18AoKGl
    gKqzdoSxqxYrn85FjrjCRVPU
    =y0Ca
    -----END PGP SIGNATURE-----
    Eric J. Roode Guest

  5. #4

    Default Re: Appending at various locations.

    Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:
    > [email]tabletdesktop@yahoo.com[/email] (MJS) wrote in
    > news:f0171209.0309071012.606a61bd@posting.google.c om:
    >
    >> I have to ask the user to input any two digits e.g input= 3,5 (their
    >> value can be upto 300-whole numbers only). These two numbers have to
    >> be associated with multiple strings. As an example, 3 is associated
    > ...
    >
    > Didn't you post this about a month ago?

    He posted the question 2 weeks ago.

    I posted (most of) the code 2 weeks ago in response.

    It appears that he needs to modify what he was given, but he
    neglected to mention what problem it is that he needs solved...


    It looks to me like he wants us to write his program for him rather
    than help him learn how to write his program.


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139