-
[ Voor 108% gewijzigd door Verwijderd op 05-06-2016 10:17 ]
1
| push(@totaal_array, @split_van_regel); |
1
2
3
4
5
6
7
8
9
10
| open(FILE, "bestandje.txt");
@data=<FILE>;
close(FILE);
foreach $regel (@data)
{
chop($regel);
@split_van_regel = split(/,/, $regel);
push(@totaal_array, @split_van_regel);
} |
[ Voor 59% gewijzigd door Annie op 10-01-2006 20:49 ]
Today's subliminal thought is:
'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.
-NMe- schreef op dinsdag 10 januari 2006 @ 20:38:
.Peter bedoelt (in lekentaal) dat je gewoon enters kan vervangen door komma's. Normaal bestaat een "enter" uit een combinatie van twee karakters: een carriage return en een line feed. Afhankelijk van je OS kan een regeleinde gemarkeerd worden door CRLF, LFCR en LF (alleen een CR zal ook wel mogelijk zijn, maar ben ik nog niet tegengekomen).
[ Voor 62% gewijzigd door NMe op 10-01-2006 21:07 ]
\n, niet /n.Verwijderd schreef op dinsdag 10 januari 2006 @ 20:50:
Bedankt mensen. De push werkt al inderdaad.
De replace van de /n is ook interessant en ga ik ook nog proberen.
Leuk taaltje is het wel.
Hmm, ik dacht al dat er iets niet klopte toen ik die post maakte.Wolfboy schreef op dinsdag 10 januari 2006 @ 20:59:
offtopic:
Windows gebruikt standaard CRLF
Linux gebruikt LF
Mac gebruikt CR
LFCR hoort niet te bestaan
correct me if i'm wrong
'E's fighting in there!' he stuttered, grabbing the captain's arm.
'All by himself?' said the captain.
'No, with everyone!' shouted Nobby, hopping from one foot to the other.
1
2
3
4
5
6
7
8
9
10
11
12
13
| use strict;
use warnings;
open THEFILE, "<myfile" or die "Could not open file: $!";
my @content = <THEFILE>;
close THEFILE;
my @letters = ();
foreach my $line (@content) {
my @currentletters = split /,/, $line;
push @letters, split /,/, $line;
} |
Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea
1
2
3
4
5
6
7
8
9
10
| open THEFILE, "<myfile" or die "Could not open file: $!"; my @content = <THEFILE>; close THEFILE; my @letters = (); foreach my $line (@content) { $line =~ s/\n//; push @letters, split(/,/, $line); } |
1
2
3
4
5
6
7
| open THEFILE, "<myfile" or die "Could not open file: $!"; my @content = <THEFILE>; close THEFILE; my $contents = "@content"; $contents =~ s/\n/,/g; my @letters = split(/,/,$contents); |
Verwijderd
Ai. Daar heb je gelijk in. Niet op geletBOOTZ schreef op woensdag 11 januari 2006 @ 09:21:
MUBA, let je wel op dat er in de file een newline aan het eind van elke regel staat? Die moet je er even uitvissen, anders krijg je een aantal waardes met newlines er in.
Reporter: Mister Gandhi, what do you think of western civilisation?
Gandhi: I think it would be a good idea
1
2
3
4
| my ( @array, $fh ); open $fh, '<', $file; chomp and @array = (@array, split/,/) while(<$fh>); close $fh; |
Annie schreef op dinsdag 10 januari 2006 @ 20:36:
Perl kennende zal dit wel weer veel korter en obscuurder kunnen
Today's subliminal thought is: