Re: Regex Newbie Q: Non-Trivial Substitution and Modifying the Matched String

2005-10-10 Thread Kenneth McNamara


Veli-Pekka

You're implying that the music macro language is pos() sensitive.   
That is a pretty severe problem in itself.


Can you output the macro language in a format that is not position  
sensitive - do a global change - then process the macro language back  
into original format?


I think I'd be more inclined to use a $noteindex{$note} = $pitch  
hash table than a regex - then process the input one note at a time.


KenMc


On Oct 9, 2005, at 2:58 PM, Veli-Pekka Tätilä wrote:


Hi,
Yet another newbie question about regular expressions:
I'd like to find and replace bits of text as usual. However, rather  
than replace all occurrences in one quick swoop using the s- 
operator and the g-flag, the replacement is so complex that it  
cannot be expressed as a straight substitution. So I would have to  
find a piece of text, process it in a separate function, and  
replace the matched text with the newly computed text. This goes on  
for n interesting matches in the input.


Can I do this kind of thing in a simple loop, processing all  
matches one by one? My understanding is that pos and some special  
variables will tel me the character index of the mach in a string.  
But if I then go and modify the string  using substr to do the  
substitution, wil it reset the search position to the beginning  
when trying to match the next interesting bit? The replacement text  
is by nature longer than the original so the input string needs to  
grow on each substitution which might present a problem to the  
matching operator. I took a look at perlop and some books I have on  
Perl but didn't end up with a definitive answer of how I should  
solve this problem.


That was the problem abstractly put, here's the specific instance:
I'm writing a program to convert notes given in the music macro  
language to their equivalent pitches that are applied using markup  
tags for speech synthesizers. I can match a note easily, and have  
functions for computing the pitch and the tag in question. As the  
note values don't depend on each other in any way, I'd like to  
completely process one note at a time, doing the replacement, and  
then continue matching the next note where it previously left off.  
Naturally there are other tokens than just notes in the input so I  
need to maintain the position of the note data in the input string.  
If I modify a separate copy of the string, it will throw off the pos 
() indeces because the substitutions will change the length of the  
copy.


Any help appreciated as usual.

PS: If the problem statement is still a bit fuzzy or incomplete,  
just ask and I'll try to provide more info.


--
With kind regards Veli-Pekka Tätilä ([EMAIL PROTECTED])
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila/
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs




___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: filename sorting by last letter in the filename

2005-10-10 Thread Kenneth McNamara


Miha -

Drop the extension.  Split the name into an array, reverse the array  
and join it, put it into an array.  Sort alphabetically the array  
(special subroutine that you can find online) -- then reverse the  
name, add the extension and print out.


KenMc

On Oct 10, 2005, at 5:16 AM, Miha Radej wrote:


Hi!

I have the following problem. As input data I have an array of  
filenames, ie:


@files_a = qw(file1a.ext file1.ext file1m.ext file1g.ext)
@files_b = qw(file2w.ext file2a.ext file2z.ext file2b.ext file2.ext  
file2x.ext file2y.ext file2c.ext)


What I need to is sort the arrays by the versions (the files I have  
been presented with use alphabetical versioning, ie. no letter  
means original, then versions go as a, b, c, ...). That is not a  
problem. The problem I have is when instead of an array @files_a I  
get one like @files_v, which contains letters from the end of the  
alpahbet and the beginning, which should mean that the users ran  
out of letters and began from a, b, ... again. I am at a loss how  
to sort an array like @files_b without making it overly complicated  
(I have an idea in mind, with a few if's and else's and comparisons  
and stuff :) ). I have looked at some sort modules but I only have  
the out-of-the package ActivePerl installation to work with, with  
no option to install additional modules.


The desired sort order would be something like:
- first the file without the version letter, ie. ends with a number  
(if it exists)

- then a-z

In case of @files_b like arrays:
- first the file without the version letter (if it exists)
- then versions from the last part of the alphabet
- versions from the first part of the alphabet

The desired sort order of the @files_b array would be:
file2.ext
file2w.ext
file2x.ext
file2y.ext
file2z.ext
file2a.ext
file2b.ext
file2c.ext

There can be holes in versions (ie. a, b, e, f) but not very  
likely. The versionless files often do not exist but I need to take  
them into consideration in case if they do.


Before I go and implement my idea, I would like to ask you for any  
advice what to do in order to achieve what I need, where to find  
more information on sorting, etc.


Thank you in advance,
Miha
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs