Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Perl Arrays & regex

Reply
Thread Tools

Perl Arrays & regex

 
 
Kevin Barry
Guest
Posts: n/a
 
      10-12-2003
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


 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      10-12-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help in perl arrays (New to perl but know TCL well) Anil A Kumar Perl Misc 2 08-03-2011 12:40 PM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
Java regex imposture re: Perl regex compatibility a_c_Attlee@yahoo.com Java 2 05-06-2005 12:16 AM
perl regex to java regex Rick Venter Java 5 11-06-2003 10:55 AM



Advertisments