Re: Mooch a regex
On 01/12/2016 12:22 PM, Tobias Leich wrote: First of all, your fist line contains a bug, unless the topic variable ($_) is set to something meaningful. Because the regex after the 'and' matches against said topic. See: ~$ perl -E '$_ = "bar"; say ("foo" =~ /f+/ and /o/)' # "", so false ~$ perl -E '$_ = "bar"; say ("foo" =~ /f+/ and /a/)' # "1", so true I guess you wanted to match $ClickLine against both regexes. In Perl 6 I would it as: # Continue if any of the two match, that pipe char describes an alternation. if $ClickLine ~~ / aes256 | $BaseTag / { push @WebClickHere, $ClickLine; # Capture all non-dash characters in $. if $Line ~~ / 'select id="' $=[ <-[-]>* ] / { push @WebVersions, $ } } If $BaseTag contains a regex rule, say "fo+b.r", then you'd enclose it in angle brackets: if $ClickLine ~~ / aes256 | <$BaseTag> / { # ... This is alled a "regex assertion". Am 12.01.2016 um 20:59 schrieb ToddAndMargo: On 01/11/2016 11:24 PM, Tobias Leich wrote: hi, what's in ${BaseTag}? Is it a regex rule or just a plain string? (Because that matters in Perl 6) It is a string and can vary. Would you show me both ways to keep me out of trouble? Am 12.01.2016 um 01:55 schrieb ToddAndMargo: Hi All, Would yo all terribly mind if I ask how to do this Perl 5 regex in Perl 6? (I learn best by example.) if ( $ClickLine =~ /aes256/ and /${BaseTag}/ ) { push ( @WebClickHere, $ClickLine ); if ( $Line =~ m{select id=\"(.*?)[-]} ) { my $VerLine = $1; push ( @WebVersions, $VerLine ); } } Many thanks, -T Thank you! -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: Mooch a regex
On 01/12/2016 12:47 PM, Bruce Gray wrote: On Jan 11, 2016, at 6:55 PM, ToddAndMargowrote: Would yo all terribly mind if I ask how to do this Perl 5 regex in Perl 6? (I learn best by example.) if ( $ClickLine =~ /aes256/ and /${BaseTag}/ ) { push ( @WebClickHere, $ClickLine ); if ( $Line =~ m{select id=\"(.*?)[-]} ) { my $VerLine = $1; push ( @WebVersions, $VerLine ); } } —snip— I don’t mind; I am happy that you have asked for the way you learn best :^) You presented three regexes: 1. $ClickLine =~ /aes256/ $ClickLine ~~ /aes256/ Where you would use `=~` in Perl 5 to bind to a match or a subst, you now use the `~~` smartmatch operator in Perl 6. Yes, it is safe, even though smartmatch has some problems in Perl 5; this is Perl 6's smartmatch! 2. /${BaseTag}/ /$BaseTag/ # Use for simple text /<$BaseTag>/# Use for a full regular expression. As FROGGS (Tobias Leich) said, the correct translation depends on whether $BaseTag contains simple text, or should be interpreted as a regex. Perl 5 always did the latter unless you used quotemeta(). 3a. $Line =~ m{select id=\"(.*?)[-]} $Line ~~ / select \s 'id="' (.*?) '-' / * Space is now significant in Perl 6 regexes. * Alphanum are literal text to match, or special if backslashed; `n` is just the character `n`, `\n` means `newline` . * Non-alphanum are special, or literal text to match if backslashed or quoted; `+` means `one or more`, while the plus character is written as `\+` or `'+'` . * Note: my translation is not tested. 3b. my $VerLine = $1; my $VerLine = $0.Str; # or ~$0 or $/[0].Str * The capture vars ($1, $2...) have moved from being 1-based to 0-based; $1 is now $0, $2 is now $1, etc. * Perl 5 capture vars held plain strings. In Perl 6, they hold Match objects, and must be stringified to behave like Perl 5. See also: http://docs.perl6.org/language/5to6-perlvar#Variables_related_to_regular_expressions http://docs.perl6.org/type/Match https://github.com/Util/Blue_Tiger/blob/master/translate_regex.pl Thank you! -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: Mooch a regex
First of all, your fist line contains a bug, unless the topic variable ($_) is set to something meaningful. Because the regex after the 'and' matches against said topic. See: ~$ perl -E '$_ = "bar"; say ("foo" =~ /f+/ and /o/)' # "", so false ~$ perl -E '$_ = "bar"; say ("foo" =~ /f+/ and /a/)' # "1", so true I guess you wanted to match $ClickLine against both regexes. In Perl 6 I would it as: # Continue if any of the two match, that pipe char describes an alternation. if $ClickLine ~~ / aes256 | $BaseTag / { push @WebClickHere, $ClickLine; # Capture all non-dash characters in $. if $Line ~~ / 'select id="' $=[ <-[-]>* ] / { push @WebVersions, $ } } If $BaseTag contains a regex rule, say "fo+b.r", then you'd enclose it in angle brackets: if $ClickLine ~~ / aes256 | <$BaseTag> / { # ... This is alled a "regex assertion". Am 12.01.2016 um 20:59 schrieb ToddAndMargo: On 01/11/2016 11:24 PM, Tobias Leich wrote: hi, what's in ${BaseTag}? Is it a regex rule or just a plain string? (Because that matters in Perl 6) It is a string and can vary. Would you show me both ways to keep me out of trouble? Am 12.01.2016 um 01:55 schrieb ToddAndMargo: Hi All, Would yo all terribly mind if I ask how to do this Perl 5 regex in Perl 6? (I learn best by example.) if ( $ClickLine =~ /aes256/ and /${BaseTag}/ ) { push ( @WebClickHere, $ClickLine ); if ( $Line =~ m{select id=\"(.*?)[-]} ) { my $VerLine = $1; push ( @WebVersions, $VerLine ); } } Many thanks, -T
Re: Mooch a regex
On 01/11/2016 11:24 PM, Tobias Leich wrote: hi, what's in ${BaseTag}? Is it a regex rule or just a plain string? (Because that matters in Perl 6) It is a string and can vary. Would you show me both ways to keep me out of trouble? Am 12.01.2016 um 01:55 schrieb ToddAndMargo: Hi All, Would yo all terribly mind if I ask how to do this Perl 5 regex in Perl 6? (I learn best by example.) if ( $ClickLine =~ /aes256/ and /${BaseTag}/ ) { push ( @WebClickHere, $ClickLine ); if ( $Line =~ m{select id=\"(.*?)[-]} ) { my $VerLine = $1; push ( @WebVersions, $VerLine ); } } Many thanks, -T -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~