Perl in c++

I was just wondering if I could implement Perl code in c++? The reason I'm asking is that I prefer Perl's filehandling over c++ filehandling because c++ filehandling looks scary and gives me nightmares.
writing a perl interpretter is 10000x more complicated than basic file i/o.

C++ file handling is simple. What are you trying to do? We can show you how to do it.
c++ file handling

1
2
3
4
5
6
string pathToFile = "path\filename.ext";
fstream file;
file.open(pathToFile.c_str(),ios::in|ios::binary);
string stringFromFile = "";
file >> stringFromFile;
cout << "the first delimited text from the file = " << stringFromFile;
nothing in particular I just occasionally need to handle files. Another thing I have trouble with is strings. any good tuts for those 2 things?

*edit would it be possible to make a declaration for a file handle in <iostream> somehow?(I would only be using it on my comp if that matters) or mabee I could write an object with an interface easier for me to understand surrounding file input and output so I only have to wade through those horrors once and never again.
Last edited on
scratch that^
I read the tut on this site on file handling and it all makes sense now. How would I go about making a very large file?(several Gigs) would a 400 dimensional array with each spot assigned a random number and written to the file work? yes I am making a virus no I will not use it. I like challenging myself by making viruses for my pc.
would a 400 dimensional array with each spot assigned a random number and written to the file work?

What? 400 dimensional? Ehhh, you gotta realize, modern machines are quite powerful, but normally even those can't load several gigs of data at once into working memory. Also you should realize that certain systems don't even allow such large files, e.g. older windows versions that use FAT32 instead of NTFS only allow file sizes up to 4GB. Other than that, if you are on a system that allows such large files, the pos_type of your filesstreams should be a 64 bit integer, which means that you don't even have to worry about file size restrictions so much - your hard drive is very likely not large enough to contain a file that isn't within that limit. So basically, the buffer size is all you have to worry about, but as you probably flush your buffer every so often (and your buffers get flushed automatically when they're full anyways), that's not really a problem either.


PS: Is that really a virus you are trying to write? Sounds more like you are trying to build an archive bomb to me.
bboy212 wrote:
yes I am making a virus no I will not use it. I like challenging myself by making viruses for my pc.


I'm going to go ahead and call bull crap on that one.

If you're going to make a "virus" do something cooler than that, geez.
I simply put that so that rather than accuse me of making a virus you could give me good advice. but ok what counts as cooler that that? I already made one that does a crapload of math and other stuff in a infinite loop that at the start it opens up another one of itself and so on. comp gets pretty slow after a while.
bboy212 wrote:
rather than accuse me of making a virus
bboy212 wrote:
yes I am making a virus


You gotta work on your consistency, keeping stuff consistent is an important skill for programmers.

Oh btw, if you have to ask: Anything that does something remotely useful is cooler than a virus. For example, there is a relatively simple way to implement the following game using binary trees:


The "player" thinks of an animal. The computer asks questions to determine what animal the player is thinking of.

Ex:

Comp: Is it a mouse?
User: No.
Comp: I give up. What is it?
User: A lion.
Comp: What is a yes/no question with which you can differentiate a lion from a mouse?
User: Is it small and gray?
Comp: What is the answer for the lion?
User: No.
Comp: Alright, another round?
User: Yes.
Comp: Is it small and grey?
User: No.
Comp: Is it a Lion?
User: No.
Comp: I give up, what is it?
User: An eagle.
Comp: What is a yes/no question with which you can differentiate a lion from an eagle?
User: Does it have wings?
Comp: What is the answer for an eagle?
User: Yes.
Comp: Alright, another round?
User: Yes.
Comp: Does it have wings?
User: No.
Comp: Is it small and gray?

.. and so on.
Last edited on
bboy212 wrote:
I simply put that so that rather than accuse me of making a virus you could give me good advice.
Lol, what?

Here's some good advise: Learn something useful, or fun. Don't waste your time on a virus. Just remember it doesn't profit you anything to hurt anyone else's computer, you may get a laugh out of it, but you won't make a lick of money off it, and it'll only make their life harder.

If I were you I would look into networking, or audio programming, or graphics programming. If you really want to do something cool you could make a collaborative text editor, or a strategic life AI, or a neural network, or something awesome

And if you're still stuck on virus crap then, well you can make some really advanced stuff that could actually help people, maybe a benign worm or something. I just don't understand the destruction.
Last edited on

I was just wondering if I could implement Perl code in c++? The reason I'm asking is that I prefer Perl's filehandling over c++ filehandling because c++ filehandling looks scary and gives me nightmares.


If you don't like the C++ way, why not use Perl then?
Perl was created specifically for I/O and text processing, so no surprise it is more convenient at this.
@ OP: Let me start off by saying congrats on your fork bomb, that's the term for the malware you described in your earlier post. Although from how you describe it you don't yet understand what parts of an application are the most taxing on an operating system, you were at least able to reach your goal of impeding the PC.

Second, don't mix and match languages. The only language that even comes close to cleanly mixing with C++ (other then C) is Assembly and by it's nature that is NOT a clean language to begin with. Python shows some interoperability but I personally think you're better off sticking with one or the other.

I'm concerned that you are over thinking when it comes to planning programs. I know, I know "it's supposed to be complicated so that I can learn" but that's exactly my point, you should never settle for complicated. For example you said you were going to fill the 400 dimension array with random data, why? Try typing this into your IDE:
1
2
3
int a;

std::cout << a;

What do you see? I'm going to take a shot in the dark and say you get data. This wouldn't be sufficent if you were trying to randomly generate numbers to compare against like in a game, but you don't need that do you? When planning to write an application you should outline your goals first, you also have to know what your tools do and then how to use them to accomplish your goals.
Last edited on
Mabee I should clarify i do do things other that write viruses its just a little thing I do is see what I can do to my own computer. As for some of the ideas you have given me they are all great. I really liked the one that asks the user questions about what kind of animal it is. One of the other ideas was an AI. My ultimate goal in programming is to somehow make a swarm AI with a central queen mind that simulates ants gathering food and building a colony.
@Computergeek01,
Assembly is a clean language. Look at 6502 assembly and tell me it's not beautiful. There are less than 30 instructions...

@bboy212,
That's not a virus, viruses are self-replicating. That would be an interesting project, though. You could maybe try to make the computer equivalent of a bacteriophage - a virus that infects bacteria. You could try to write a virus that infects other viruses to tell the user that the program is a virus when they run it (by scanning the computer for infected files).
@chrisname, technically it is a virus, by definition anyways. What you are referring to is a worm. Not that it matters.

On another note, you could learn SFML for your little swarm idea, you could design it pretty easily in an environment like that.

Assembly is a clean language. Look at 6502 assembly and tell me it's not beautiful. There are less than 30 instructions...

It's less the number of instructions than the fact that it's machine oriented rather than problem oriented that's bothersome.


On another note, you could learn SFML for your little swarm idea, you could design it pretty easily in an environment like that.


The important part about a swarm is the AI, not the graphical representation. SFML doesn't really help that much there.
But the cool part is seeing it =)
A virus has to be self-replicating, a worm doesn't.
Oops you're right =) my bad.
Topic archived. No new replies allowed.