Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Perl Arrays & regex (http://www.velocityreviews.com/forums/t883057-perl-arrays-and-regex.html)

Kevin Barry 10-12-2003 06:07 PM

Perl Arrays & regex
 
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



John W. Krahn 10-12-2003 07:12 PM

Re: Perl Arrays & regex
 
Kevin Barry wrote:
>
> 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
--
use Perl;
program
fulfillment


All times are GMT. The time now is 03:40 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.