in reply to Re: Help required on understanding regular expressions
in thread Help required on understanding regular expressions

Thanks monks for the reply.

I am not converting anything, just wanted to learn new feature, Still not able to get it working ... below is the code.

use strict; use Data::Dumper; my %hash=(); my $str="Test Tester Testing [Feb 18: 28_10_10] Test"; #my $reg='(?<fname>\w+\b)\s(?<mname>\w+)\s(?<lname>\w+\s).*\[(?<date>[ +^\]]+)/'; my $reg='^(?<fname>\S+)\s+(?<mname>\S+)\s+(?<lname>\S+)\s+\[(?<date>[^ +\]]*)\]\+s+\k<fname>\z'; { if($str =~ /$reg/) { %hash=%+; } } print Dumper \%hash;

Thanks.

Replies are listed 'Best First'.
Re^3: Help required on understanding regular expressions
by JavaFan (Canon) on Feb 20, 2012 at 12:10 UTC
    Still not able to get it working
    As in, you get compile errors? Run time errors? Unexpected results? Or does the program sit on the couch, demanding beer and crips?

    Be specific, don't expect us to download your code and run it, just to find out what your "does not work" means. Tell us what you mean by "not working", and show us the errors and output you are getting.

      Thanks for all monks for the insights and flaws pointed out in my code and ways to improve.

      Well, i did clicked download link and downloaded code, it didn't work means - i didn't get any results in hash, and printing something on if loop also did not printed o/p on screen, that's what i was referring at. But looks like some peoples words are little more "harsh" than expected. I use to get my doubts on perl cleared in this website, but this time it was something else.

      Thanks

        The code works fine, after you fix the typo pointed out by Anonymous Monk.

        Please continue to ask questions at this website. Hopefully the mild criticism you (justifiably) received will encourage you to post questions with more thought, and following the guidelines in How do I post a question effectively?.

        Update:: As en encouragement for you to post research/questions here - I wanted to thank you for posting this particular question.

        I'm an "old school" perl programmer, and your question encouraged me to research these new RE features - something I would not have done otherwise, so -- Thanks --.

                    “PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.”
                ― Jon Ribbens

Re^3: Help required on understanding regular expressions
by Anonymous Monk on Feb 20, 2012 at 10:50 UTC

    You got typos :) this means start using /x so you can see them clearly

    my $reg = qr/ ^ (?<fname>\S+) \s+ (?<mname>\S+) \s+ (?<lname>\S+) \s+ \[ (?<date>[^\]]*) \] \+s+ # TYPOS \k<fname> \z /x;
Re^3: Help required on understanding regular expressions
by Anonymous Monk on Feb 20, 2012 at 10:54 UTC