Re: grep and regex

2010-05-25 Thread Akhthar Parvez K
On Sunday 23 May 2010, Rob Dixon wrote: > I think you may have simplified the problem you are facing a little too > much, but the code below does what you ask for. If, as I suspect, this > solution is not applicable to your real data, then please try to > describe the problem rather than coding

Re: grep and regex

2010-05-22 Thread Rob Dixon
On 22/05/2010 15:22, Akhthar Parvez K wrote: On Saturday 22 May 2010, Jim Gibson wrote: On 5/21/10 Fri May 21, 2010 12:13 PM, "Akhthar Parvez K" scribbled: Jim, thanks for your continued help. Jim, forget everything that I "scribbled" upto now, how would you tell Perl to pick 'cd' of 'abc

Re: grep and regex

2010-05-22 Thread Dr.Ruud
Akhthar Parvez K wrote: Jim, Why do you call us Jim? [...] how would you tell Perl to pick 'cd' of 'abcd' and 'abcd' itself and 'pq' of 'pqrs' and 'pqrs' itself, and nothing else, from an array ( = 'abcdpqrsxyz') by a single statement. Why an array? Don't you mean a string? my $s = 'a

Re: grep and regex

2010-05-22 Thread Akhthar Parvez K
On Saturday 22 May 2010, Jim Gibson wrote: > On 5/21/10 Fri May 21, 2010 12:13 PM, "Akhthar Parvez K" > scribbled: > > Shouldn't > > Perl be smart enough to understand that the outer most pair of paranthesis > > and > > | symbol were solely used for alternation (since there're nothing within

Re: grep and regex

2010-05-21 Thread Jim Gibson
On 5/21/10 Fri May 21, 2010 12:13 PM, "Akhthar Parvez K" scribbled: > On Friday 21 May 2010, Jim Gibson wrote: >> You are getting undefs because you >> have alternation (|) between two >> sub-patterns and capturing parentheses in >> each sub-pattern. You also have >> nested parentheses, with

Re: grep and regex

2010-05-21 Thread Akhthar Parvez K
On Friday 21 May 2010, Jim Gibson wrote: > You are getting undefs because you have alternation (|) between two > sub-patterns and capturing parentheses in each sub-pattern. You also have > nested parentheses, with a capturing parenthese pair around the whole. > > Your regular expression is this: >

Re: grep and regex

2010-05-21 Thread Jim Gibson
On 5/21/10 Fri May 21, 2010 8:42 AM, "Akhthar Parvez K" scribbled: > On Friday 21 May 2010, Akhthar Parvez K wrote: > I am stuck with regex again, this time I really need to *fix* it: > > Code: > > my @data = ( 'Twinkle twinkle little star > How I wonder what you are > Up above the world so

Re: grep and regex

2010-05-21 Thread Akhthar Parvez K
On Friday 21 May 2010, Akhthar Parvez K wrote: > Look at this code: > > my @data = ( 'Twinkle twinkle little star > How I wonder what you are > Up above the world so high > Like a diamond in the sky. > 123 > Twinkle twinkle little star > How I wonder what you are'); > my $rx1 = qr{ world.*diamond

Re: grep and regex

2010-05-20 Thread Akhthar Parvez K
On Thursday 20 May 2010, Shawn H Corey wrote: > #!/usr/bin/perl > > use strict; > use warnings; > > use Data::Dumper; > > # Make Data::Dumper pretty > $Data::Dumper::Sortkeys = 1; > $Data::Dumper::Indent = 1; > > # Set maximum depth for Data::Dumper, zero means unlimited > local $Data::Dumpe

Re: grep and regex

2010-05-20 Thread Shawn H Corey
On 10-05-20 03:52 PM, Uri Guttman wrote: i didn't say it was for output but for debugging. and i didn't say YOU shouldn't do it. i wrote for others to learn when to and not to use Dumper. it isn't always the best choice. you can use it all the time. they don't need to. simpler print/map is fine f

Re: grep and regex

2010-05-20 Thread Uri Guttman
> "SHC" == Shawn H Corey writes: SHC> On 10-05-20 03:17 PM, Uri Guttman wrote: >>> "SHC" == Shawn H Corey writes: >> SHC> On 10-05-20 02:07 PM, Uri Guttman wrote: >> >> not a major point, but why do you use dumper just to print a list of >> >> tokens? i use dumper for deep

Re: grep and regex

2010-05-20 Thread Shawn H Corey
On 10-05-20 03:17 PM, Uri Guttman wrote: "SHC" == Shawn H Corey writes: SHC> On 10-05-20 02:07 PM, Uri Guttman wrote: >> not a major point, but why do you use dumper just to print a list of >> tokens? i use dumper for deeper stuff where i can't just print the data >> easily wit

Re: grep and regex

2010-05-20 Thread Uri Guttman
> "SHC" == Shawn H Corey writes: SHC> On 10-05-20 02:07 PM, Uri Guttman wrote: >> not a major point, but why do you use dumper just to print a list of >> tokens? i use dumper for deeper stuff where i can't just print the data >> easily without some code. even single level hashes i wil

Re: grep and regex

2010-05-20 Thread Shawn H Corey
On 10-05-20 02:07 PM, Uri Guttman wrote: not a major point, but why do you use dumper just to print a list of tokens? i use dumper for deeper stuff where i can't just print the data easily without some code. even single level hashes i will print directly as i can format it my way and not dumper's

Re: grep and regex

2010-05-20 Thread Uri Guttman
> "SHC" == Shawn H Corey writes: SHC> my @data = qw( The quick brown fox jumped over the lazy dogs. ); SHC> my $regx = qr{ [aeiou] }msx; SHC> my @matches = map { /($regx)/ } @data; SHC> print '@matches : ', Dumper \...@matches; not a major point, but why do you use dumper just to pri

Re: grep and regex

2010-05-20 Thread Shawn H Corey
On 10-05-20 12:52 PM, Akhthar Parvez K wrote: Hi all, Can Perl regex match a string in a list (like Perl grep)? eg:- #won't work $_ = @data; my @matches = /($regx)/g; #works, but not as quite really wanted since it would show the line contains the string, not just the matched string: my @matche

grep and regex

2010-05-20 Thread Akhthar Parvez K
Hi all, Can Perl regex match a string in a list (like Perl grep)? eg:- #won't work $_ = @data; my @matches = /($regx)/g; #works, but not as quite really wanted since it would show the line contains the string, not just the matched string: my @matches = grep /($regx)/, @data; So, can Perl grep s