Re: how to select which words have Y and W
by LanX (Saint) on Dec 26, 2013 at 10:30 UTC
|
Try this
@selection = grep { /REGEX/ } @array
and plz give us feedback with code you tried.
see also grep and perlre
Cheers Rolf
( addicted to the Perl Programming Language)
| [reply] [Watch: Dir/Any] [d/l] |
|
i tried like this but it doesn't show any result
my@colors=('red', 'cyan', 'yellow', 'blue' );
my @yw_colors = grep {/yw/} @colors;
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
A reply falls below the community's threshold of quality. You may see it by logging in.
|
Re: how to select which words have Y and W
by Laurent_R (Canon) on Dec 26, 2013 at 12:19 UTC
|
For your initial question, if you want words having both y and w, a character class or alternation is not sufficient. Try two regexes:
$ perl -e 'print join " ", grep { /y/ and /w/} ('red', 'cyan', 'yello
+w', 'blue' )'
yellow
| [reply] [Watch: Dir/Any] [d/l] |
Re: how to select which words have Y and W
by karlgoethebier (Abbot) on Dec 26, 2013 at 12:42 UTC
|
"what is the functionality of [] and |?"
"I didn't find character class :("
"let me know"
rammohan, you got a lot of feedback and good advice. Very cool.
But can you imagine how all this guys figured out this stuff?
Let me us know...
My best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
|
Unbelievable. Unfortunately i'm not from India and i really want no Perl training. But perhaps some bros think that i should have one. Please donate (beer accepted). Regards, Karl
Update:...and why the hell are this gurus interested in my sex and age?
«The Crux of the Biscuit is the Apostrophe»
| [reply] [Watch: Dir/Any] |
Re: how to select which words have Y and W
by Lennotoecom (Pilgrim) on Dec 26, 2013 at 19:34 UTC
|
@a = qw/red cyan yellow blue why do you want this at all/;
/y/ and /w/ and print "$_\n" for @a;
| [reply] [Watch: Dir/Any] [d/l] |
Re: how to select which words have Y and W
by rammohan (Acolyte) on Dec 26, 2013 at 11:19 UTC
|
I didn't find character class :( | [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re: how to select which words have Y and W
by rammohan (Acolyte) on Dec 26, 2013 at 11:08 UTC
|
what is the functionality of [] and |? | [reply] [Watch: Dir/Any] |
Re: how to select which words have Y and W
by rammohan (Acolyte) on Dec 26, 2013 at 11:46 UTC
|
suppose i have an array like (12,-85,36,-10,75,-38),in this array i've to delete negative elements using grep.is it possible ?let me know | [reply] [Watch: Dir/Any] |
|
DB<114> @a=(12,-85,36,-10,75,-38)
=> (12, -85, 36, -10, 75, -38)
DB<115> @a = grep { $_ >= 0 } @a
=> (12, 36, 75)
But for the basics people here appreciate if you first read docs (or a Perl book) and try the examples there before asking.
People already provided links (like here) and they would like to get feedback if those links helped (and if not, why, to be able to improve them)
Thats the way we help to learn efficiently! :-)
Cheers Rolf
( addicted to the Perl Programming Language)
| [reply] [Watch: Dir/Any] [d/l] |
|
$ perl -e '@positive_int = grep {$_ >=0 } (12,-85,36,-10,75,-38); pri
+nt "@positive_int"'
12 36 75
| [reply] [Watch: Dir/Any] [d/l] |
|
$ perl -Mstrict -Mwarnings -E '
my @array = ( 12, -85, 36, -10, 75, -38 );
say qq{@array};
my @notNegatives = grep { $_ >= 0 } @array;
say qq{@notNegatives};'
12 -85 36 -10 75 -38
12 36 75
$
I hope this is helpful.
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
|
Thanks to all it works for me..its silly point sorry for asking here.. from now on words i'll try my level best..Thank you for advices
| [reply] [Watch: Dir/Any] |