Perl Arrays & regex

Discussion in 'Perl Misc' started by Kevin Barry, Oct 12, 2003.

  1. Kevin Barry

    Kevin Barry Guest

    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
     
    Kevin Barry, Oct 12, 2003
    #1
    1. Advertising

  2. 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
     
    John W. Krahn, Oct 12, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,635
    Ant...
    Nov 6, 2003
  2. Replies:
    2
    Views:
    601
  3. Replies:
    3
    Views:
    772
    Reedick, Andrew
    Jul 1, 2008
  4. Philipp
    Replies:
    21
    Views:
    1,134
    Philipp
    Jan 20, 2009
  5. Anil A Kumar
    Replies:
    2
    Views:
    128
    J├╝rgen Exner
    Aug 3, 2011
Loading...

Share This Page