Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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"
    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.


    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?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2022-05-23 08:39 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (81 votes). Check out past polls.