Re: [PBML] file handler
- Thank you! I'm very new to Perl and whether %hash = `ls -ltr` is useless or
not, I just came up with an example to use backtick. I just realized that
print FILE " "; will send the output to FILE(or whatever FH I use) rather
than to STDOUT. That was my question.
On Wed, Jan 26, 2011 at 4:41 PM, Randal L. Schwartz
> >>>>> "Hema" == Hema K <khema1808@...> writes:[Non-text portions of this message have been removed]
> Hema> open(FILE, "+>output.txt");
> You should verify that this succeeds:
> open FILE, ">output.txt" or die "Cannot create output.txt: $!";
> Hema> %hash = `ls -ltr`;
> This will assign alternate lines as keys and values in the hash. Pretty
> useless. Not only that, but the newlines are preserved.
> Hema> @array = %hash;
> This randomly extracts key/value pairs from the hash, turning them into
> an array.
> Hema> print "@array \n";
> This inserts spaces between the elements, causing all but the first line
> to be indented, since you've preserved the newlines above. And this
> also goes to STDOUT, not to FILE.
> Hema> close FILE;
> This is the only line that might be correct, although in most programs I
> write, I never close the filehandle.
> Your code is a mishmash. I suggest instead of generating "blender perl"
> where you throw a bunch of random things into a file without
> understanding what they do, that you instead proceed in an orderly
> manner through any of the many tutorials recommend by sites like
> http://learn.perl.org In the long run, you'll waste less of your time,
> and less of ours.
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
> <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> See http://methodsandmessages.posterous.com/ for Smalltalk discussion