Perl Arrays & regex

K

Kevin Barry

I'm writing a program to parse words of three or more characters from a file
into an array. But when I load the words into the array and look to print
individual words it seems to have overwritten earlier lines with the last
line in the file. What am I missing here?

#!/usr/bin/perl

#matchtest3.pl

use warnings;
use strict;

my @tempwords;

open FD, "< dslinfo1.txt" or die $!;

while (<FD>){

@tempwords = /\b\w{3,}\b/g;

print @tempwords, "\n";

print $tempwords[2];
}

There's nothing special about the *.txt file just a notepad file with 3
lines of txt.

Kevin
 
J

John W. Krahn

Kevin said:
I'm writing a program to parse words of three or more characters from a file
into an array. But when I load the words into the array and look to print
individual words it seems to have overwritten earlier lines with the last
line in the file. What am I missing here?

perldoc -f push

#!/usr/bin/perl

#matchtest3.pl

use warnings;
use strict;

my @tempwords;

open FD, "< dslinfo1.txt" or die $!;

while (<FD>){

@tempwords = /\b\w{3,}\b/g;

push @tempwords, /\b\w{3,}\b/g;

print @tempwords, "\n";

print $tempwords[2];
}


John
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top