1.

Solve : PERL - Is there a better way to write output to file than my batch/perl method?

Answer»

I am curious as to if there is a better way to write an output to a file using PERL than the method that I am using below, which is a mixture of PERL and DOS(batch):

system "echo $a $b $c >>WriteList.txt";


Where variables $a, $b, and $c are passed directly into the Echo output of a DOS Shell batched type of environment which then uses the >> redirection and append to EOF to write the output of PERL's variable strings to text file.

*This does work, but to me it just seems sloppy to have to pass variables outside of PERL into a SYSTEM call which then runs as if you were in DOS. The same SYSTEM(" "); call can also be run in C++ and perform the same passing of variables out of C++ into DOS command lines, BUT C++ has its FILE OPEN, Write, and FILE CLOSE function so that you dont need to perform a SYSTEM Call. So that is why I am thinking that I am running this in an ugly frankensteined state, which just happens to work. And figured I'd check to see if someone with more PERL experience might point out how to perform this without a frankensteined method of mixed guts!

The other thing I have to figure out is why I can only write a maximum of 60,000 lines per hour with this program on both a Pentium 3 (600Mhz) and a Dual-Core Atom. Thinking that maybe the excessive Open/Close >> appending might be hammering the drive and wasting time. But the HD LED does not stay on constant, so I dont think that is the problem. Because if the HD was being flooded with file open/close's I WOULD expect to see a solid LED lit and lots of drive arm rattling..lol

Was thinking that maybe if I printed out 100 lines then wrote to file, it might be more HD friendly and might execute faster, but the CPU on the P3 is pegged at 100% and the Dual-Core Atom is hovering between 53-60% and both when timed were executing the program the same speed pretty much at a little less than 30,000 lines written in 30 minutes. With close to 450,000 lines to write, this is going to take a while, and it seems that even throwing faster processing power at it isnt going to help me for some reason the way that i have it currently executing.Yes, it would be better to read and write files inside of pearl.
http://perl.about.com/od/perltutorials/a/readwritefiles.htm
The above is a basic tutorial on pearl open, read and write. And don't forget to close when done.
Here is one on append.
http://www.pageresource.com/cgirec/ptut15.htmopen the file...
Code: [Select]open(APPENDFILE,">>WriteList.txt") || die("Error opening WriteList.txt");
print to the file
Code: [Select]print APPENDFILE "$a $b $c";
close the file:
Code: [Select]close(APPENDFILE);

If you are looping in some way as you output the data or otherwise are outputting more then once per script run you should open the file early on, perform all the writes on it, and then close it.


By the way, shelling out to any other application to perform a task is always going to be slower then performing that same task in the same environment. Setting up Process INFORMATION and starting a new task is a very expensive operation. Also, doing it that way is a rather ugly kludge.if you are using Perl, then use Perl. There is no need to use batch any more than calling the Perl interpreter to run your Perl script.
Always looks at the documentation for what you need. And I suggest you dive deeper into the language (if you want) because it can practically replace batch for what you are doing. Plus, there are humongous amount of libraries you can use to do other complex stuff, eg big integer maths, pdf generation, HTML parsing , etc...Quote from: Geek-9pm on December 29, 2010, 08:50:24 PM

Yes, it would be better to read and write files inside of pearl.
its Perl.Perl was originally named "Pearl," after the Parable of the Pearl from the Gospel .

But I guess you are to young to know that.
Quote from: Geek-9pm on December 29, 2010, 10:43:07 PM
Perl was originally named "Pearl," after the Parable of the Pearl from the Gospel .

But I guess you are to young to know that.

Wrong. Being "named" and being "OFFICIALLY used" are two different things. Before Perl, there's also a PEARL language (since 1977). after that, Larry changed the spelling to Perl. Get that in your head.Quote from: ghostdog74 on December 29, 2010, 11:03:30 PM
Wrong. Being "named" and being "officially used" are two different things. Before Perl, there's also a PEARL language (since 1977). after that, Larry changed the spelling to Perl. Get that in your head.
You are right.
He wanted 'Pearl' but changed it to 'Perl' before the official release.
Thanks everyone for the useful info...plus also about the Perl name history =) never knew PERL has been around since 1977. To just think I might have been able to play with PERL on my TRS-80 way way back..lolSorry for the confusion I started...
Quote
A pearl is a round shiny object produced by mollusks and used in jewelry.

Pearl may also REFER to:
# Pearl (given name)
# Bruce Pearl (born 1960), head basketball coach - University of Tennessee
# Daniel Pearl (1963–2002), American journalist who was kidnapped and murdered in Pakistan
Canada
* Pearl, Ontario

[edit] Hungary
* Gyöngyös, a town whose name means "Made of Pearls"

[edit] Iceland
* The Pearl (Perlan), a 1991 landmark building in Reykjavík, Iceland
# The Pearl, an 1867 legal case; see: List of United States Supreme Court cases, volume 72
# Polar Environment Atmospheric RESEARCH Laboratory, an Arctic Atmospheric laboratory at Eureka, Nunavut, Canada
# Pearl (color), a pale tint of off-white. It is a representation of the average color of a pearl
# Pearl (radio play), a 1978 radio play by award-winning English playwright John Arden
# Pearl (DART station)
....

Wall discovered the existing PEARL programming language before Perl's official release and changed the spelling of the name.

When referring to the language, the name is normally capitalized (Perl) as a proper noun.

Larry Wall began work on Perl in 1987, while working as a programmer at Unisys,[7] and released version 1.0 to the comp.sources.misc newsgroup on December 18, 1987.[8] The language expanded rapidly over the next few years.

Perl 2, released in 1988, featured a better regular expression engine. Perl 3, released in 1989, added support for binary data streams.

http://en.wikipedia.org/wiki/Perl

Perl can refer to:
* Perl, a programming language.

Place names
* Perl, Germany, a municipality in Saarland, Germany

Last names
* Hille Perl, a German musician who performs the viola da gamba and the lirone
* Martin Lewis Perl, an American physicist and Nobel Prize laureate

A Pearl by any other name would be a Rosa.Quote from: DaveLembke on January 01, 2011, 03:11:10 PM
Thanks everyone for the useful info...plus also about the Perl name history =) never knew PERL has been around since 1977. To just think I might have been able to play with PERL on my TRS-80 way way back..lol

There was no Perl in 1977...Pearl is very young, and has a problem...
http://www.funnyordie.com/videos/74/the-landlord-from-will-ferrell-and-adam-ghost-panther-mckayWell 1987 I guess vs 1977..lol...thx for posting correction


Discussion

No Comment Found