Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Creating 1 file w/ the contents of 7 other files mixed randomly.

Reply
Thread Tools

Creating 1 file w/ the contents of 7 other files mixed randomly.

 
 
Paul Lalli
Guest
Posts: n/a
 
      04-18-2006
robic0 wrote:
> In a loop, read all the lines into an array.


Why would you ever do that? Why not simply read the file into an array
directly, by using the readline operator in list context? If you've
already resigned yourself to storing the entire file(s) in memory,
seems pointless to spend cycles looping through the file...

Paul Lalli

 
Reply With Quote
 
 
 
 
robic0
Guest
Posts: n/a
 
      04-18-2006
On 18 Apr 2006 20:54:35 GMT, (Anno Siegel) wrote:

>Zachary <> wrote in comp.lang.perl.misc:
>> Why did you even reply?

>
>To give you a chance to make a posting that shows some code we can help
>you with.
>
>> I work at UPS and I'm attemting to change
>> positions. The new position requires that I learn a ton of zip codes
>> so that I'll know where to send the packages in the buiding so I
>> figured I would kill 2 birds with one stone ( do some programming and
>> learn the zips ). I'm working on an application that I can use to test
>> myself. I'm also currently working through the "Learning Perl" and
>> "Programming Perl" books. It's just a hobby. I'm not a student trying
>> to cheat I just don't know how to accomplish the task above.

>
>That is all mildly interesting, but does nothing to validate your
>question. We help people correct their Perl programs. You are in
>a stage of problem solving that isn't (yet) language-specific. That you
>intend to implement a solution in Perl doesn't make it a Perl problem.
>
>> So far
>> I'm just randomly picking a filehandle, plucking a line off the top,
>> and comparing with my answer until I reach EOF on each filehandle. The
>> problem with that is nothing varies.

>
>Read all the files in a big array. Select a random line from the
>array each time through. Seems like that's all there's to it.
>
>> Sorry if posted to the wrong group but you should just pass it on by if
>> you don't know the answer.

>
>It's not a question of knowing. Many of us earn their money by writing
>Perl programs to specification. It would be bad for the market if we
>did it here for free.
>
>> I'm sure someone will help eventually or I
>> might even figure it out on my own. If you want to be a teacher, make
>> that your profession. If you just want to be an *sshole then keep up
>> the good work.

>
>You seem to be of the insult-them-until-they-help-me school of belief.
>They don't last long...
>
>Anno


The OP made a half-hearted effort, couldn't quite cover his *I don't really
know what I'm trying to do*. When he's serious, that kind of aggresion will
turn to accertiveness and surely help him. Your response will definetly push
him in the right direction technically. Just remember Anno, your producing
another Charles Manson programming god...

 
Reply With Quote
 
 
 
 
robic0
Guest
Posts: n/a
 
      04-18-2006
On 18 Apr 2006 14:44:38 -0700, "Paul Lalli" <> wrote:

>robic0 wrote:
>> In a loop, read all the lines into an array.

>
>Why would you ever do that? Why not simply read the file into an array
>directly, by using the readline operator in list context? If you've
>already resigned yourself to storing the entire file(s) in memory,
>seems pointless to spend cycles looping through the file...
>
>Paul Lalli


Yeh, thats what I meant. I thought this was an original post, didn't know it was
a thread. Didn't think he was technical enough to understand, or anyone else would respond.
My bad......
 
Reply With Quote
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      04-18-2006
Zachary wrote:
> [a question]


This question was multi-posted to perl.beginners (and maybe other
groups). That shows remarkable lack of nettiquite (or deliberate
rudeness on the part of the OP).

--
http://DavidFilmer.com

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      04-18-2006
"Zachary" <> wrote in news:1145392234.672076.58990
@i39g2000cwa.googlegroups.com:

> If you just want to be an *sshole then keep up
> the good work.


Following your own advice? Bye.

Sinan
--
A. Sinan Unur <>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc...uidelines.html

 
Reply With Quote
 
Harry
Guest
Posts: n/a
 
      04-18-2006
Zachary wrote:
> Say I've got 7 files ( file1.txt - file7.txt) and I want to combine the
> lines from all 7 files into one file (file8.txt) but I want the line
> order to be randomly mixed. In other words, I want file8.txt to
> contain all the lines from file1.txt through file7.txt but in random
> order so that each pass produces a different file8.txt. Might someone
> help me accomplish this? Keep in mind that files 1-7 may not contain
> the same number of lines. One may have a hundred lines wile the other
> may only have ten.


Don't re-invent the wheel

Google "randomize text file" will point you to here, which
co-incidently, is a Perl script.

Random Text Version 1.0
http://www.rahoorkhuit.net/programmi...xt/index.shtml

 
Reply With Quote
 
robic0
Guest
Posts: n/a
 
      04-18-2006
On 18 Apr 2006 15:35:40 -0700, "Harry" <> wrote:

>Zachary wrote:
>> Say I've got 7 files ( file1.txt - file7.txt) and I want to combine the
>> lines from all 7 files into one file (file8.txt) but I want the line
>> order to be randomly mixed. In other words, I want file8.txt to
>> contain all the lines from file1.txt through file7.txt but in random
>> order so that each pass produces a different file8.txt. Might someone
>> help me accomplish this? Keep in mind that files 1-7 may not contain
>> the same number of lines. One may have a hundred lines wile the other
>> may only have ten.

>
>Don't re-invent the wheel
>
>Google "randomize text file" will point you to here, which
>co-incidently, is a Perl script.
>
>Random Text Version 1.0
>http://www.rahoorkhuit.net/programmi...xt/index.shtml


Post it, explain it, don't talk about 'wheels'.
Either the files can be read, or seek positions into a array in memory or not. Rand has
nothing at all to do with it. Randomize 7 120gig files for me........
 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      04-18-2006
Harry wrote:
> Zachary wrote:
>>Say I've got 7 files ( file1.txt - file7.txt) and I want to combine the
>>lines from all 7 files into one file (file8.txt) but I want the line
>>order to be randomly mixed. In other words, I want file8.txt to
>>contain all the lines from file1.txt through file7.txt but in random
>>order so that each pass produces a different file8.txt. Might someone
>>help me accomplish this? Keep in mind that files 1-7 may not contain
>>the same number of lines. One may have a hundred lines wile the other
>>may only have ten.

>
> Don't re-invent the wheel
>
> Google "randomize text file" will point you to here, which
> co-incidently, is a Perl script.
>
> Random Text Version 1.0
> http://www.rahoorkhuit.net/programmi...xt/index.shtml


Wow, you must be a brave little coder, posting a Perl4 Matt Wright script
here. And one that only prints a single line from a file instead of
randomising the entire file.


John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
robic0
Guest
Posts: n/a
 
      04-18-2006
On Tue, 18 Apr 2006 22:53:01 GMT, "John W. Krahn" <> wrote:

>Harry wrote:
>> Zachary wrote:
>>>Say I've got 7 files ( file1.txt - file7.txt) and I want to combine the
>>>lines from all 7 files into one file (file8.txt) but I want the line
>>>order to be randomly mixed. In other words, I want file8.txt to
>>>contain all the lines from file1.txt through file7.txt but in random
>>>order so that each pass produces a different file8.txt. Might someone
>>>help me accomplish this? Keep in mind that files 1-7 may not contain
>>>the same number of lines. One may have a hundred lines wile the other
>>>may only have ten.

>>
>> Don't re-invent the wheel
>>
>> Google "randomize text file" will point you to here, which
>> co-incidently, is a Perl script.
>>
>> Random Text Version 1.0
>> http://www.rahoorkhuit.net/programmi...xt/index.shtml

>
>Wow, you must be a brave little coder, posting a Perl4 Matt Wright script
>here. And one that only prints a single line from a file instead of
>randomising the entire file.
>
>
>John


You know, actually you could cat all the files into one (no matter how big).
Given the number of lines in the file, using Tie::File or something, you
could get a randome number between 0..last line, then print it out.
I guess..
 
Reply With Quote
 
robic0
Guest
Posts: n/a
 
      04-18-2006
On Tue, 18 Apr 2006 16:01:10 -0700, robic0 wrote:

>On Tue, 18 Apr 2006 22:53:01 GMT, "John W. Krahn" <> wrote:
>
>>Harry wrote:
>>> Zachary wrote:
>>>>Say I've got 7 files ( file1.txt - file7.txt) and I want to combine the
>>>>lines from all 7 files into one file (file8.txt) but I want the line
>>>>order to be randomly mixed. In other words, I want file8.txt to
>>>>contain all the lines from file1.txt through file7.txt but in random
>>>>order so that each pass produces a different file8.txt. Might someone
>>>>help me accomplish this? Keep in mind that files 1-7 may not contain
>>>>the same number of lines. One may have a hundred lines wile the other
>>>>may only have ten.
>>>
>>> Don't re-invent the wheel
>>>
>>> Google "randomize text file" will point you to here, which
>>> co-incidently, is a Perl script.
>>>
>>> Random Text Version 1.0
>>> http://www.rahoorkhuit.net/programmi...xt/index.shtml

>>
>>Wow, you must be a brave little coder, posting a Perl4 Matt Wright script
>>here. And one that only prints a single line from a file instead of
>>randomising the entire file.
>>
>>
>>John

>
>You know, actually you could cat all the files into one (no matter how big).
>Given the number of lines in the file, using Tie::File or something, you
>could get a randome number between 0..last line, then print it out.
>I guess..


But hey, the file cat wouldn't seem to be the point (as the subject suggests).
Though for efficiency, why cat files? A random file(/lines) ([filex,lines]) index
is obtained, then the line index is randomized. Does randomize know file numbers?
How many files you need for a good statistical spread? The more the better.
Then Tie::File, rinse, repeat...
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding contents on yaml file without overwriting actual contents Kamarulnizam Rahim Ruby 4 01-28-2011 09:10 AM
if innerHTML used twice then it replaces the contents i want it to display all the contents virendra.amritkar@gmail.com Javascript 0 06-29-2007 08:13 AM
particular costraints in mixed contents JU XML 2 07-03-2006 01:25 AM
Creating a File object out of the contents of jar/zip file kotauk@gmail.com Java 5 04-06-2006 08:36 PM
Can I restrict both attribute contents and element contents in schema Don Adams XML 1 03-05-2004 12:48 PM



Advertisments