Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: What am I breaking?

by bliako (Monsignor)
on May 09, 2019 at 19:25 UTC ( [id://1233526]=note: print w/replies, xml ) Need Help??


in reply to What am I breaking? (solved - double unquoting needing 'qw')

In our @num2nam = (... [       six =>    0.1.1], ...) not quoting the values (e.g. 0.1.1) results in unprintable characters (0.1.1 concatenates ascii 0, 1 and 1 to a string) that confuse eval. After fixing it, you will only have to find why $res is undefined.

Edit: I am slightly out of my depth here as I was not aware of the "version strings" before haukex's Re^2: What am I breaking?. Although quoting the version strings may have fixed the problem, there is the danger of short-circuiting the test logic. Perhaps one can sprintf() those naked version strings using the special sprintf formatter mentioned by AnomalousMonk.

bw, bliako

Replies are listed 'Best First'.
Re^2: What am I breaking?
by haukex (Archbishop) on May 09, 2019 at 20:49 UTC

      question: how does one sprintf() version strings?

        See "vector flag" in sprintf:

        c:\@Work\Perl\monks>perl -wMstrict -le "printf qq{perl version is v%vd \n}, $^V; ;; my $v = v1.23.456.7891; printf qq{some version is v%vd \n}, $v; " perl version is v5.8.9 some version is v1.23.456.7891


        Give a man a fish:  <%-{-{-{-<

Re^2: What am I breaking?
by perl-diddler (Chaplain) on May 10, 2019 at 02:42 UTC
    Hitting the nail askance you did!

    This should replace the table and results in 0 errors/everything working:

    our @num2nam = ( [ qw(zero 0 )], [ qw(one '0.0.5')], [ qw(two '0.1.1')], [ qw(three 0.000005)], [ qw(four 0.000101)], [ qw(five 0.0.5)], [ qw(six 0.1.1)], [ qw(seven 1.10)], [ qw(eight 1.5)], [ qw(nine 0.1.5)], [ qw(ten 0.1.10)], [ qw(eleven '000005')], [ qw(twelve '001010')], [ qw(thirteen 3.0014)], [ qw(fourteen 3.1)], [ qw(fifteen '3.0014')], [ qw(sixteen '3.1')], );
    Those items were being dequoted twice, so the ones that need to be quoted had to be quoted twice, and the ones that didn't still needed quoting once.

    Thanks for the hint!

Re^2: What am I breaking?
by perl-diddler (Chaplain) on May 10, 2019 at 01:30 UTC
    In light of them intentionally being 'version strings', are they still a problem?

    As far as I know, they should result a string with (if ^@=NUL), like '^@^A^A^@^@^@^@^@'. It may not be standardized or desirable, but this is a test program to test/verify how such things are handled. I.e. I wouldn't want such things to cause a core-breach or similar :-).

      Probably you should not modify the quotation of the version strings in the array. Can you just use the "vector flag" mentioned by node:AnomalousMonk for the unquoted version strings only and the "string formatter - %s" for the quoted cases? See also my edited previous answer.

Re^2: What am I breaking?
by perl-diddler (Chaplain) on May 10, 2019 at 10:02 UTC
    No, it's fine -- cuz what I meant by hitting the nail askance -- is that eval really didn't like binary embedded in the source it was 'eval'ing -- as you mentioned. That section was being 'eval'ed twice, once by the new code that looped through the table to create the packages, and second, in the 'use pkg X.Y.Z;' code because you can't use an expression with 'use', so the only way to put in the version I wanted was have the eval "evaluate" the expression so it would behave normally.

    My "hints" were that in some of the version strings I had quoted them and had done so deliberately, while in some of the I had not done so (again deliberately) -- and that the final test resulted in some tests that were quoted strings, while others used the 'binary' (as formed by the vector) value of the version string.

    That's when I put it together -- why didn't the binary cause problems in original code -- because it is only turned into binary as it is eval'ed in the test case. Since I was evaling it twice, my first eval had to result in both a quoted (the qw('quoted string')) and a non-quoted value (qw(vec.tor)) for the different test cases.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1233526]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-25 20:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found