perl
1
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?
2
Name:
Anonymous
2007-10-04 23:53
iirc, it involves the !@#*&$%^&@$!#%%^*$^%#^@$% operator.
3
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!
4
Name:
Anonymous
2007-10-05 0:17
HAY GUIZE,
<insert joke about like noise, pound symbol keys and say it's valid perl>
5
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);
6
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;
7
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);
}
8
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
9
Name:
Anonymous
2007-10-05 7:03
split /\s/,`cat $filename`;
10
Name:
Anonymous
2007-10-05 7:04
split /\s+/,`cat $filename`
11
Name:
Anonymous
2007-10-05 7:12
this thread is now about solving the OPs problem in a language of their choice. GO
12
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
13
Name:
Anonymous
2007-10-05 10:38
14
Name:
Anonymous
2007-10-05 10:39
Also, fixing my
>>8 :
Python:
myarray = file('lol').read().split()
15
Name:
Anonymous
2007-10-05 10:40
[CODE] `cat $filename`[CODE] is bad. It copies the whole file to memory.
16
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?
17
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.
18
Name:
Anonymous
2007-10-05 10:46
Also, WTF was I thinking. I wrote "most reply call last" instead of "most recent call last".
19
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>())
20
Name:
Anonymous
2007-10-05 11:05
;
21
Name:
Anonymous
2007-10-05 11:10
>>17
OH SHIT, I DAONT WANT WATO TUSE MY MEMOEY!!!!!!
22
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.
23
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.
24
Name:
Anonymous
2007-10-05 12:53
>>22
PROTIP: The joke is that
>>5 is perl code.
25
Name:
Anonymous
2007-10-05 13:21
>>24
Your highly illogical use of
[spoiler] tags confuses and enrages me, Sir.
26
Name:
Anonymous
2007-10-05 13:22
>>25
Your smugness fuqing angers an expert programmer.
27
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.
28
Name:
Anonymous
2007-10-05 20:14
>>19
Shutup suave yoshi C++;
29
Name:
Anonymous
2007-10-05 21:26
$/=" ";
$\=" ";
done