Professional Web Applications Themes

Appending at various locations. - PERL Miscellaneous

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 ...

  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. #2

    Default Re: Appending at various locations.


    "MJS" <tabletdesktop> wrote in message
    news:f0171209.0309071012.606a61bdposting.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

  3. #3

    Default Re: Appending at various locations.

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

    [email]tabletdesktop[/email] (MJS) wrote in
    news:f0171209.0309071012.606a61bdposting.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/AwUBP1xZ0GPeouIeTNHoEQJZvgCg8Y60jVSZeUxbTGt3NxD 4RX18AoKGl
    gKqzdoSxqxYrn85FjrjCRVPU
    =y0Ca
    -----END PGP SIGNATURE-----
    Eric J. Roode Guest

  4. #4

    Default Re: Appending at various locations.

    Eric J. Roode <REMOVEsdnCAPScomcast.net> wrote:
    > [email]tabletdesktop[/email] (MJS) wrote in
    > news:f0171209.0309071012.606a61bdposting.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]tadmcaugustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

Similar Threads

  1. Appending FLV files together on the fly
    By bill0bill in forum Macromedia Flash Flashcom
    Replies: 1
    Last Post: May 3rd, 10:09 AM
  2. Appending to a string?
    By JakeFlynn in forum Macromedia ColdFusion
    Replies: 6
    Last Post: June 2nd, 01:24 PM
  3. Appending text file
    By Brandon Taylor in forum Dreamweaver AppDev
    Replies: 0
    Last Post: March 19th, 03:57 AM
  4. Appending at various locations
    By MJS in forum PERL Beginners
    Replies: 0
    Last Post: September 7th, 05:15 AM
  5. appending multiple PDFs together.
    By Stephanie S in forum ASP
    Replies: 1
    Last Post: July 25th, 04:21 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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