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

A

A. Sinan Unur

(e-mail address removed) wrote in @u72g2000cwu.googlegroups.com:
Fair point, but at the same time a child who touches a steaming iron
won't touch it again.

How many injuries are you willing to let your child suffer to help him
learn from experience?

Are you willing to let your child run red lights or cross the street
without looking in the hope that one day, he will learn from the
experience of a crash with a Mac truck?

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

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

Bart Lateur

Zachary said:
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.

Just load the lines from all files into an array, shuffle them, and
print them out...?

use List::Util 'shuffle';
local @ARGV = map "file$_.txt", 1 ..7;
my @lines = <>;
shuffle @lines;
open OUT, ">file8.txt";
print OUT @lines;
 
M

Michele Dondi

Why? Constructive criticism involves explanations, not dictats.

To improve readability and possibly to better structure your program,
lexically scoping your variables as close as possible to the point
they're being used.
Can you expand please?

opendir my $dh, '.' or die $!; # no need to close()
What difference would that have to the operation of the program? Surely
this is personal preference?

Indeed it is. I prefer @planets_of_solar_system all the time. Some
people have difficulties understanding the logical role of this array
in my code...
What difference would that have to the operation of the program? Sure
this too is personal preference?

Indeed it is. And there are varying personal preferences wrt the
chosen indenting style as well. But the general consensus is that a
nice, mostly consistent indentation aids readability.

It is of course a personal preference to want to have readable code,
too. If you're posting for the benefit of a newbie this may (or
should?) be a relevant parameter...


Michele
 
B

Bart Lateur

Michele said:
opendir my $dh, '.' or die $!; # no need to close()

I disagree. In my experience (with normal handles), closedir() is
required. close() and closedir() are not the same thing! Yes it's silly,
but it has always been this way.
 
T

Tad McClellan

Michele Dondi said:
To improve readability and possibly to better structure your program,


Those are mere side effects.

The most important reason to restrict scope is that it reduces
the chances of inserting a hard-to-find bug.
 
M

Michele Dondi

I disagree. In my experience (with normal handles), closedir() is
required. close() and closedir() are not the same thing! Yes it's silly,
but it has always been this way.

My fault! You're perfectly right. To be fair I use lexical handles all
the time with files, i.e. open() & C., but very very seldom do
opendir()s myself as in my experience most of the times either
File::Find and relatives or glob(), depending on whether I want
recursion or not, suffice. Hence the typo. BTW: From previous
discussions I'm aware that people's opinion tend to vary...


PS: re your last claim, I seem to remember having read in Tanenbaum's
that in the first versions of UNIX there was only one call for opening
files and directories and one for closing. For technical reasons
dedicated calls for directories were introduced after an improvement
of the fs. Hopefully someone more knowledgeable than I am may
clarify...


Michele
 
M

Michele Dondi

Those are mere side effects.

The most important reason to restrict scope is that it reduces
the chances of inserting a hard-to-find bug.

Ack: readability *is* a side effect. "To better structure your
program" was intended to be strictly related with the most important
reason to restrict scope, as you describe it.


Michele
 
U

Uri Guttman

MD> PS: re your last claim, I seem to remember having read in Tanenbaum's
MD> that in the first versions of UNIX there was only one call for opening
MD> files and directories and one for closing. For technical reasons
MD> dedicated calls for directories were introduced after an improvement
MD> of the fs. Hopefully someone more knowledgeable than I am may
MD> clarify...

you can always open a dir with just open and read the contents. but
there have been several changes over the decades to basic dir file
formats (and i am not even going near the modern FS variants like
rieserfs). the earliest dir format was 16 bytes which was a 2 byte inode
number and a 14 char file name. this was easy to read as is and access
via a simple structure. when the BSD fs came in, it allowed a max of 512 char
names, 32 bit inode number and variable length file names (saves space
when you don't use all 512 chars :). so it was obvious that either a
library or new system call was needed to just handle reading and
scanning dirs and opendir and friends were born.

that is a general overview and some of that could be wrong as it was a
long time ago :).

uri
 
U

Uri Guttman

"r" == robic0 <robic0> writes:

MD> PS: re your last claim, I seem to remember having read in Tanenbaum's
MD> that in the first versions of UNIX there was only one call for opening
MD> files and directories and one for closing. For technical reasons
MD> dedicated calls for directories were introduced after an improvement
MD> of the fs. Hopefully someone more knowledgeable than I am may
MD> clarify...
r> This last line is a clear indication that the respondent is fuckin
r> psychotic! Over just over a simple 20 years ago the IBM pc was
r> invented and produced with its big 8085 8-bit, altair machine.

and what does this have to do with how unix directories are formated or
read?

r> Don't listen to a goddamned word this skunk Uri says, not one
r> goddamed thing !!!!

you are obeying your own orders very well.

and if you are what you say and you are so pained as you expressed here,
why do you still act like an asshole? you and all of us know you are
faking this so why continue the charade? you can actually learn from
others if you cared to do so. but you want to stay in your locked up
world and think we are all your personal enemies. too bad for you. i
tried to help and you immediately went back into you bottomless and
unsupported rage and rant against all the others here. do i have to keep
trying to shame you here? can't you fight the urge to flame and actually
join a community instead of being the outsider? see if you have the
courage to do that instead of being the coward hiding behind the flaming
persona.

uri
 
B

Ben Morrow

Quoth Uri Guttman said:
MD> PS: re your last claim, I seem to remember having read in Tanenbaum's
MD> that in the first versions of UNIX there was only one call for opening
MD> files and directories and one for closing. For technical reasons
MD> dedicated calls for directories were introduced after an improvement
MD> of the fs. Hopefully someone more knowledgeable than I am may
MD> clarify...

you can always open a dir with just open and read the contents.

At least on Linux, you can open a directory with open(2) (which is what
opendir(3) uses), but cannot read it with read(2) (read fails with
EISDIR). To read the entries the call getdents(2) (from SVr4,
apparently) must be used. Closing is with close(2).

opendir(3), closedir(3) are equivalent to fopen(3), fclose(3), and must
be matched for the same reason (but you knew that already :) ).

Ben
 
R

robic0

MD> PS: re your last claim, I seem to remember having read in Tanenbaum's
MD> that in the first versions of UNIX there was only one call for opening
MD> files and directories and one for closing. For technical reasons
MD> dedicated calls for directories were introduced after an improvement
MD> of the fs. Hopefully someone more knowledgeable than I am may
MD> clarify...

r> This last line is a clear indication that the respondent is fuckin
r> psychotic! Over just over a simple 20 years ago the IBM pc was
r> invented and produced with its big 8085 8-bit, altair machine.

and what does this have to do with how unix directories are formated or
read?

r> Don't listen to a goddamned word this skunk Uri says, not one
r> goddamed thing !!!!

you are obeying your own orders very well.

and if you are what you say and you are so pained as you expressed here,
why do you still act like an asshole? you and all of us know you are
faking this so why continue the charade? you can actually learn from
others if you cared to do so. but you want to stay in your locked up
world and think we are all your personal enemies. too bad for you. i
tried to help and you immediately went back into you bottomless and
unsupported rage and rant against all the others here. do i have to keep
trying to shame you here? can't you fight the urge to flame and actually
join a community instead of being the outsider? see if you have the
courage to do that instead of being the coward hiding behind the flaming
persona.

uri

Forgot where I left off but think I was here before and wanted to reply
again. Maybe with some more insight.

I may look a little rough but I can assure you that I've been at this for
25 years and my edges are laced with bitter poison with the typical persona's
and attitude's I find here. You lose out on knowledge not me. I can't change
you. I hope I can though, you and the others here really don't know shit
here. I'm only here because I have free time. To alter your reasoning is not
why I'm here. 'Flaming' is a word not relegated to news groups. If your not
tough enough to take reply's hard-core style, then you should'nt dish out
personal insults. What goes around, comes around. You make your bed you
sleep in, if you want to shit there thats up to you.

Just remember, Perl isin't some unique special thing. There is nothing
new and the rules of the machine win. I'm not here to learn anything from
you. Nothing you know I don't, lots I know you don't. And hey keep up the
bullshit as long as you want. I'm gonna hit you on every front that you hit
me!
 
M

Matt Garrish

I may look a little rough but I can assure you that I've been at this for
25 years and my edges are laced with bitter poison with the typical
persona's
and attitude's I find here. You lose out on knowledge not me. I can't
change
you. I hope I can though, you and the others here really don't know shit
here. I'm only here because I have free time.

The pretense of being older than you are wore thin a long time ago. It's
fairly easy to judge a person's age by the language they use, and you use
the vocabulary of someone who is no older than 25. And as Uri said, you
aren't fooling anyone with your generalities about programming that are
usually wrong and look like they're the result of a quick Google search.
Since you think Usenet is about being king of the hill, know that your
postings put you firmly at the bottom, and the more you try the worse you
look (try a Google of your next of kin Purl Gurl for a picture of how people
view you).

At the very least stop hiding behind the anonymity of your email handle. No
one respects a coward.

Matt
 
D

DJ Stunks

Matt said:
Google ... your next of kin Purl Gurl

Holy smokes that's funny.

robic, is that your sister dude? if so, does she have a boyfriend??
hahaha

too funny, thanks Matt

-jp
 
R

robic0

The pretense of being older than you are wore thin a long time ago. It's
fairly easy to judge a person's age by the language they use, and you use
the vocabulary of someone who is no older than 25. And as Uri said, you
aren't fooling anyone with your generalities about programming that are
usually wrong and look like they're the result of a quick Google search.
Since you think Usenet is about being king of the hill, know that your
postings put you firmly at the bottom, and the more you try the worse you
look (try a Google of your next of kin Purl Gurl for a picture of how people
view you).
Its good to know how people view you. When your dead and dust I'm sure all the
people views will rise you from the dead. Scarecly a single relative will even
think about you for a second after your dead! I'm talking about you dude!
Thats how you can tell how old someone is.....
At the very least stop hiding behind the anonymity of your email handle. No
What you wan't my name and address?
 
R

robic0

Holy smokes that's funny.

robic, is that your sister dude? if so, does she have a boyfriend??
hahaha

too funny, thanks Matt

-jp

Hey dude, haha, why don't you bend down and suck you 1 inch ****.
Let me know how it comes out. Hahahahaaaaaa
 
M

Matt Garrish

What you wan't my name and address?

If you're so proud of your skill as a programmer, why do you hide behind a
fake name? You don't see anyone else here doing it. Does the anonymity make
you feel more important? Or do you know what a little a-hole you are and are
afraid some potential employer's going to google your name to see what comes
up? I want to see you grow up and take responsibility for what you write.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top