[32529] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3793 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 11 14:09:22 2012

Date: Thu, 11 Oct 2012 11:09:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 11 Oct 2012     Volume: 11 Number: 3793

Today's topics:
    Re: Differential pattern match <graham.stow@stowassocs.co.uk>
    Re: Differential pattern match <glex_no-spam@qwest-spam-no.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 11 Oct 2012 18:09:25 +0100
From: "Graham" <graham.stow@stowassocs.co.uk>
Subject: Re: Differential pattern match
Message-Id: <GKKdnTkmH_HTYOvNnZ2dnUVZ8sudnZ2d@bt.com>


"Ben Morrow" <ben@morrow.me.uk> wrote in message 
news:ubi1k9-0u7.ln1@anubis.morrow.me.uk...
>
> Quoth "Graham S" <graham.stow@gmail.com>:
>> I haven't had time to check this out fully yet, but the following is a 
>> quick
>> guide to guitar tabs:
>>
>> The six strings of a guitar, from lowest to highest pitch, are tuned 
>> EADGBE.
>> Thus a tab of  333x22 would mean 3rd fet on the E, A and D strings, the G
>> string muted (not played) and the 2nd fret on the B and E strings. This 
>> is
>> the normal tablature for chords where all the notes are from up to but 
>> not
>> exceeding the 9th fret. Beond the 9th fret, one or two spaces are left to
>> make it clear which strings are being played and at what fret. Thus '999x
>> 10x' would mean 9th fret on the E, A & D strings, the G and E strings 
>> muted,
>> and 10th fret on the B string. However, some tab writers might equally 
>> show
>> this as '999x 10  x'  or '9 9 9 x 10 x '. Whatever the denotation, there
>> should always be a reference to all 6 strings.
>
> OK, I see: I was assuming they were *fingers* when actually they are
> strings, and I didn't understand what the Xs were for. All my previous
> patterns were wrong then :).
>
> It sounds to me like
>
>    / (?: (?: [12][0-9] | [1-9Xx] ) [ ]* ){6} /x;
>
> might be sufficient; that is: a string is two or one digits or an X, and
> a chord has six strings possibly separated by spaces. It's important the
> two possibilities are listed in that order, since the | regex operator
> tries the alternatives in the order they are given and [1-9Xx] will
> match the first digit of '10' if you let it.
>
> This will allow chord patterns a human wouldn't necessarily read
> correctly, like 'xxx11119' (which will be parsed as 'x x x 11 11 9'),
> but that may not be a problem in practice. If it is, one way to fix it
> is like this:
>
>    / (?: (?: \b [12][0-9] \b | [1-9Xx] ) [ ]* ){6} /x
>
> where the \bs insist that two-digit fret numbers don't get jammed up
> against other numbers.
>
> If you want to pull out just the string numbers (ignoring the spaces)
> you unfortunately can't use the {6} notation, because capturing
> (bracketed) groups inside repetitions still only capture once. That
> means it's probably easiest to build up the pattern programatically,
> like this:
>
>    my $string  = '(\b [12][0-9] \b | [1-9Xx]) [ ]*';
>    my $chord   = $string x 6;
>
>    my $text    = "999x 10  x";
>    my @strings = $text =~ /$chord/x;
>
> Ben
>

Don't know if you're still about Ben, but pulling out the string numbers is 
proving tricky. The following code (predominately yours)

$string = '(\b[12][0-9]\b|[0-9Xx])[]*';
$chord = $string*6;
$text = "999x 10 x";
@strings=$text=~/$chord/x;
print "String = $string<br>\n";
print "Chord = $chord<br>\n";
print "Text = $text<br>\n";
foreach $line(@strings) {
 print "String = $line<br>\n";
}

produces this output

String = (\b[12][0-9]\b|[0-9Xx])[]*
Chord = 0
Text = 999x 10 x
String = 1

Where am I going wrong?

Graham 




------------------------------

Date: Thu, 11 Oct 2012 12:26:49 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Differential pattern match
Message-Id: <50770159$0$75674$815e3792@news.qwest.net>

On 10/11/12 12:09, Graham wrote:

> Don't know if you're still about Ben, but pulling out the string numbers is
> proving tricky. The following code (predominately yours)
>
> $string = '(\b[12][0-9]\b|[0-9Xx])[]*';
> $chord = $string*6;
                   ^ --- that should be x not *

'x' is the repetition operator.

See Multiplicative Operators in perldoc perlop.

A stare and compare was easy enough, but 'use warnings' would have
pointed it out too.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3793
***************************************


home help back first fref pref prev next nref lref last post