Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

perl

Name: Anonymous 2007-10-04 22:09

In perl, how would one read a text file into an array such that each word (as separated by whitespace) would become a different element?

Name: Anonymous 2007-10-04 23:53

iirc, it involves the !@#*&$%^&@$!#%%^*$^%#^@$% operator.

Name: Anonymous 2007-10-04 23:55

>>1
*&YHzcv,jh7o*$TO*&#! - iOFHO*&$GjnvL& &Y$&*O@ kjvh liuY $&O *I

That should do it. If not, you have two options... first, bang on the keyboard for ten minutes. Second, hook up a 300 baud modem to a noisy line and record the results.

That'll do it. EXPERT PROGRAMMER out!

Name: Anonymous 2007-10-05 0:17

HAY GUIZE,
<insert joke about like noise, pound symbol keys and say it's valid perl>

Name: Anonymous 2007-10-05 0:28

Lol perl. Try picking a less fail language so you can do something as simple as:

open(FILE, "file");
@foo = split(/ /, <FILE>);
close(FILE);

Name: Anonymous 2007-10-05 4:41

>>5, I pick PHP.

open my $fh, "file.txt"
    or die $!;
my @foo = split /\s+/, <$fh>;

close $file;

Name: Anonymous 2007-10-05 5:43

>>5
I pick C++

ifstream ifs("file.txt");
vector<string> words;
string file, word;
getline(ifs,line,(char)EOF);
istringstream is(line);
while (is) {
    is >> word;
    words.push_back(word);
}

Name: Anonymous 2007-10-05 5:47

I pick Python
myarray = file('lol').split()

I could also pick PHP
preg_split('/\s+/', file_get_contents('lol'))

Everybody else failed sorry sirs

Name: Anonymous 2007-10-05 7:03

split /\s/,`cat $filename`;

Name: Anonymous 2007-10-05 7:04

split /\s+/,`cat $filename`

Name: Anonymous 2007-10-05 7:12

this thread is now about solving the OPs problem in a language of their choice. GO

Name: Anonymous 2007-10-05 10:27

TIMTOWTDI
split " ", `cat $file`
Now this thread is for random perl noobbetry
@X = reverse split//,"perl";push @X, shift @X; print uc join "", @X

Name: Anonymous 2007-10-05 10:38

>>9-10
Inefficiency-get!

Name: Anonymous 2007-10-05 10:39

Also, fixing my >>8:
Python:
myarray = file('lol').read().split()

Name: Anonymous 2007-10-05 10:40

[CODE]`cat $filename`[CODE] is bad. It copies the whole file to memory.

Name: Anonymous 2007-10-05 10:45

>>15
Traceback (most reply call last):
  Thread "perl", line 1, in >>15
SyntaxError: reached end of post expecting "/CODE"


Also, the other methods also copy the whole file to memory. So?

Name: Anonymous 2007-10-05 10:46

>>15
file('lol').read() is bad. It copies the whole file to memory.
file_get_contents('lol') is bad. It copies the whole file to memory.

Name: Anonymous 2007-10-05 10:46

Also, WTF was I thinking. I wrote "most reply call last" instead of "most recent call last".

Name: Anonymous 2007-10-05 11:04

>>7
I also pick C++

std::ifstream in("file.txt");
std::vector words((std::istream_iterator<string>(in)), std::istream_iterator<string>())

Name: Anonymous 2007-10-05 11:05

;

Name: Anonymous 2007-10-05 11:10

>>17
OH SHIT, I DAONT WANT WATO TUSE MY MEMOEY!!!!!!

Name: Anonymous 2007-10-05 11:11

>>5
Fuck you.
Let me just say that again: Fuck you.

Perl is the best scripting language in a *nix enviroment, though mostly because bash script be s...l..o..w.

Name: Anonymous 2007-10-05 11:31

>>5
Fuck you.
Let me just say that again: Fuck you.

PHP is the best scripting language in a amiga enviroment, though mostly because ruby script be s...l..o..w.

Name: Anonymous 2007-10-05 12:53

>>22
PROTIP: The joke is that >>5 is perl code.

Name: Anonymous 2007-10-05 13:21

>>24
Your highly illogical use of [spoiler] tags confuses and enrages me, Sir.

Name: Anonymous 2007-10-05 13:22

>>25
Your smugness fuqing angers an expert programmer.

Name: Anonymous 2007-10-05 15:08

>>26
Your inadequate use of popycosta gives me a massive erection, Sir. Please allow me to rape your face.

Name: Anonymous 2007-10-05 20:14

>>19
Shutup suave yoshi C++;

Name: Anonymous 2007-10-05 21:26

$/=" ";
$\=" ";
done

Don't change these.
Name: Email:
Entire Thread Thread List