Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

using a string or file in qw

by Anonymous Monk
on Jan 22, 2009 at 18:41 UTC ( #738256=perlquestion: print w/replies, xml ) Need Help??

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

Dear Perlers I have a question about using a variable or a file in perl. my siplified code is as below, I have a string and want to remove the stopwords but it does not works since qw works in different way ...any clue?
#!/usr/bin/perl use strict; use Lingua::StopWords qw( getStopWords ); my $stopwords = getStopWords('en'); my $text='I want to remove stop words'; #my @words = qw ($text); print join ' ', grep { !$stopwords->{$_} } $words;
or even if there is any option for this, I would appreciate to know. thanks in advance.

Replies are listed 'Best First'.
Re: using a string or file in qw
by ikegami (Patriarch) on Jan 22, 2009 at 19:10 UTC
Re: using a string or file in qw
by jasonk (Parson) on Jan 22, 2009 at 18:47 UTC
    my @words = split( ' ', $words ); print join ' ', grep { ! $stopwords->{ $_ } } @words;

    Then I suggest you read a good book, such as "Learning Perl"


    www.jasonkohles.com
    We're not surrounded, we're in a target-rich environment!
      ... or even:
      . . print join ' ', grep ! $stopwords->{ $_ }, split( ' ', $words ); . .
      - assuming @words isn't required later...

      A user level that continues to overstate my experience :-))
Re: using a string or file in qw
by holli (Abbot) on Jan 22, 2009 at 18:46 UTC
    What's wrong with my @words = ($text);?

    Sorry, misread.


    holli

    When you're up to your ass in alligators, it's difficult to remember that your original purpose was to drain the swamp.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://738256]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2022-05-17 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (65 votes). Check out past polls.

    Notices?