Ask a Question related to PERL Miscellaneous, Design and Development.
-
MJS #1
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
-
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... -
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... -
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... -
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... -
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... -
James E Keenan #2
Re: Appending at various locations.
"MJS" <tabletdesktop@yahoo.com> wrote in message
news:f0171209.0309071012.606a61bd@posting.google.c om...there> 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......> "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[script snipped]> how is the weather there "is it hot" cool_1,cool_2, cool_3, cool_4,
> cool_5........thats good.
>
.... And your question is?
James E Keenan Guest
-
Eric J. Roode #3
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
-
Tad McClellan #4
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



Reply With Quote

