There seems to be a new trend in the world of C++ programming with regards to online games. The trend in question is taking an existing game and running it in a browser online. There’s a lot of open source games that programmers and players will now be able to tap into. The newest generation of browsers able to do fast JavaScript, Google’s Chrome for example uses the V8 engine so those games can run pretty quick, this enables users to enjoy a quick and clear gaming experience.
Many games seem to be following this pattern. These Games were originally written in C or C++. With Java these games can easily be converted to be played online.
Remember, we aren’t talking about light weight game like online roulette that runs well in all environments. We are referring to games like Quake III, M.U.L.E and FreeCiv some of game history’s favorites.
Some of these games are JavaScript front end, C server backend so you can even play it on an iPhone 3GS.
In this program we are going to use the split function in perl to count the occurrences of a particular string in a given text.
#!/usr/bin/perl
#A perl program to count the occrrences of a particular string in a given text
print("Enter some text\n");
$text=" ".<stdin>." ";
print("Enter the string whose occurrences you want to count:");
$string=<stdin>;
chop($string);
@array= split(/$string/,$text);
$count=@array;
print("\nThe number of occurrences of the string \"$string\" is ". ($count-1)."\n");
Analysis
In line 5, if we don’t add the blank space before and after the text, we will not be able to count the occurrence of the string at the beginning and end.
In line 7 we are chopping the string to get rid of the new line character at the end, if we don’t do this we wont get the count we are expecting.
In line 8 we are using the split function. Split is a library function, it splits the string when ever it see the sub string between //.
for example @array=split(/the/, “this is a test string to, this string to split when ever there is an occurrence of the word this”);
now the array will have the following elements
$array[0]=” is a test string to, ”
$array[1]=”string to split when ever there is an occurrence of the word “
What Is Perl?
Perl is an acronym, short for Practical Extraction and Report Language. It was designed by Larry Wall as a tool for writing programs in the UNIX environment and is continually being updated and maintained by him. For its many fans,
Perl provides the best of several worlds. For instance: Perl has the power and [...]
Full Story »