UrbanHick has asked for the wisdom of the Perl Monks concerning the following question:

Hello all!

Its another Sunday morning and that means I am trying to get my head around Perl again.

I am looking for an easy way to parse words out of a file that looks like this:

aboveboard aboveground abovementioned abrade Abraham Abram Abramson abrasion abrasive abreact abreast abridge abridgment abroad abrogate abrupt abscess abscissa abscissae absence absent absentee absenteeism absentia absentminded absinthe absolute absolutio +n absolve absorb absorbent absorption absorptive abstain abstention abstinent abstract abstracter abstractor abstruse absurd abuilding abundant abusable abuse abusive abut abutted abutting abysmal abyss Abyssinia AC academe academia academic academician academy Acadia acanthus Acapulco accede accelerate accelerometer accent accentual accentuate accept acceptant acceptor access accessible accession accessory accident accidental accipiter acclaim acclamation acclimate accolade accommodate accompaniment accom +panist

I want to use something like:

my @array = split/\s+/, $scaler;

I have failed to find away to parse this is the pass the individual words on to a while (<>) argument..

My thanks and gratitude in advance to any who can set me straight. -hick

Replies are listed 'Best First'.
Re: Parsing individual words from a file
by McDarren (Abbot) on Oct 08, 2006 at 13:28 UTC
    split by default, splits on whitespace - so you could simply do something like this:
    my @words; while (<DATA>) { chomp; push @words, split; } __DATA__ aboveboard aboveground abovementioned abrade Abraham Abram Abramson abrasion abrasive abreact abreast abridge abridgment abroad abrogate abrupt abscess abscissa abscissae absence absent etc....

    Cheers,
    Darren :)

      Thank you! I swear guys like you make this one of the best communities on the internet!
Re: Parsing individual words from a file
by merlyn (Sage) on Oct 08, 2006 at 16:37 UTC
      my @w = map /\S+/, <DATA>; use Data::Dumper;print Dumper \@w; __DATA__ aboveboard aboveground abovementioned abrade Abraham Abram Abramson abrasion abrasive abreact abreast abridge abridgment abroad

      Produces:

      $VAR1 = [ 1, 1 ];

      Test your code the next time ;^). You really meant /\S+/g:

      my @w = map /\S+/g, <DATA>; use Data::Dumper;print Dumper \@w; __DATA__ aboveboard aboveground abovementioned abrade Abraham Abram Abramson abrasion abrasive abreact abreast abridge abridgment abroad
      $VAR1 = [ 'aboveboard', 'aboveground', 'abovementioned', [...]

      --
      David Serrano