- Show quoted text -
On 5 August 2010 04:58, Chas. Owens <chas.ow...@gmail.com> wrote:
> On Wed, Aug 4, 2010 at 11:36, Mike Martin <redt...@gmail.com> wrote:
> snip
>> This fails but if I replace
>> $type_g=$options{$key}->[4] if $chk=~/$type/
>>
>> with either
>> $type_g=$options{$key}->[4] if $type=~/$chk/; (ie:reversing the match)
>>
>> or
>>
>> $type_g=$options{$key}->[4] if $type eq $chk;
>>
>> any idea on the reasons for this behaviour
> snip
>
> This is just a guess because you have not told us what $chk holds, but
> I strongly suspect that $chk contains more than just "val".  It
> probably has a newline or some other characters in it: "val\n"
> contains the substring "val", but "val" does not contain the substring
> "val\n".  You may find it helpful to add the following line to your
> script for debugging purposes:
>
> warn join ", ", map { "[$_]: " . ord } split //, $chk;
>
> This will split $chk into characters and then map those characters
> into a string that contains the character surrounded by brackets
> followed by a colon and the characters Unicode position (which is
> identical to ASCII for the first 127 characters).  Knowing the Unicode
> position is important because there are many unprintable characters
> like Unicode position 0 (ASCII null character) and Unicode position 8
> (ASCII backspace character).
>
output of above within this block

if ($type=~/$chk/){
print "chk\t",$chk,"\n";
warn join ", ", map { "[$_]: " . ord } split //, $chk,"\n";
print "type\t",$type,"\n";
warn join ", ", map { "[$_]: " . ord } split //, $type,"\n";
};

chk     ogg
[o]: 111, [g]: 103, [g]: 103 at /usr/bin/burn_360 line 1390, <OPTS> line 30.
type    ogg
[o]: 111, [g]: 103, [g]: 103 at /usr/bin/burn_360 line 1392, <OPTS> line 30.
chk
Warning: something's wrong at /usr/bin/burn_360 line 1390, <OPTS> line 30.
type    ogg
[o]: 111, [g]: 103, [g]: 103 at /usr/bin/burn_360 line 1392, <OPTS> line 30.
chk
Warning: something's wrong at /usr/bin/burn_360 line 1390, <OPTS> line 30.
type    ogg
[o]: 111, [g]: 103, [g]: 103 at /usr/bin/burn_360 line 1392, <OPTS> line 30.

## This opt works ##
vid_type        To mp3
chk     To mp3
[T]: 84, [o]: 111, [ ]: 32, [m]: 109, [p]: 112, [3]: 51 at
/usr/bin/burn_360 line 1390, <OPTS> line 30.
type    To mp3
[T]: 84, [o]: 111, [ ]: 32, [m]: 109, [p]: 112, [3]: 51 at
/usr/bin/burn_360 line 1392, <OPTS> line 30.

also if I put a numerical sort on the keys everything works

It seems to be matching wrongly on the ogg value (and some but not all
others) without a sort

> On a related note, you most likely have a bug with the placement of
> the variable $type_g and the print statement.  You are only printing
> $type_g after the loop, so you will print the value of $type_g for the
> last key (and which key is last is not guaranteed by Perl 5) that has
> a match.  This may be your intended behavior, but it looks odd to me.
> I would expect it to look like this:
>

There should only be one match - the value of key4 where $type equals key3
- Show quoted text -

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to