Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: archival storage ($/--)

by tye (Sage)
on Jun 29, 2016 at 16:49 UTC ( #1166891=note: print w/replies, xml ) Need Help??

in reply to archival storage

Note that your tatoo requires that the string "-1" not appear in the first file (or for it to be used as the delimiter between the body and the 'pad' in a single file). At least in my testing...

- tye        

Replies are listed 'Best First'.
Re^2: archival storage ($/--)
by mr_mischief (Monsignor) on Jun 30, 2016 at 14:49 UTC

    Thanks for the heads up. It also seems the string "-1" in the second file shortens what is worked on there and leaves the rest as plaintext.

    This would be fixed by using undef$/; rather than $/--;. However, this is supposed to be using the record size setting mentioned in perlvar rather than stringification. According to perlvar, for 5.22 and 5.24:

    Trying to set the record size to zero or less is deprecated and will cause $/ to have the value of "undef", which will cause reading in the (rest of the) whole file.
    ... and using $/-- does leave the variable with a numeric value of -1. In a suitably old version of perlvar (that for 5.10.1), the text reads:
    Trying to set the record size to zero or less will cause reading in the (rest of the) whole file.
    ... and in perl 5.10.1 we also get that the numeric value has been successfully set to -1.
    perl -e '$/--; printf "%d\n", $/; printf "%f\n", $/; $foo = <>; $bar = + <>; $_ = $foo ^ $bar; print $_ . "\n"' in1 in2 -1 -1.000000 '1
    where in1 is:
    and in2 is:
    while the proper output for the important line is:

    This appears to my eyes to be a bug in perl or the documentation, but in the bigger picture is what happens when one pushes into dark corners in the name of cleverness.


      works for me. The \ character is important as it isn't being a number that causes $/ to be interpreted as a record length, but it being a reference to a scalar (containing what gets interpreted as a number).

      - tye        

        Ah. So it seems on rereading very carefully, I've tripped up on some slight ambiguities in this line:

        Setting $/ to a reference to an integer, scalar containing an integer, or scalar that's convertible to an integer will attempt to read records instead of lines, with the maximum record size being the referenced integer.
        That should be read as reference to (integer|scalar containing integer|scalar convertible to an integer) and not as (reference to integer|scalar containing an integer|scalar convertible to an integer). It's not talking about scalar values. It's talking about Perl's idea of Scalar variables, a definitional ambiguity for which I should have been prepared as it's peppered through the Perl documentation that way. The "reference to" part covers all three cases in the list, a structural ambiguity that I should have tested out.

        So in trying to golf out three characters and testing edge cases insufficiently (IIRC I tested with all alpha text) I ended up with a bug on my arm. Again, if clear but still shortened was the goal I'd have just gone with undef$/, but $/=\-1; is pretty nice. It still comes down to trying to be overly clever. It's a minimal code change to fix it and the code still makes its intended point with or without the bug.

        Just please forgive me if I don't patch the hardcopy right away...

Re^2: archival storage ($/--)
by choroba (Bishop) on Jun 30, 2016 at 15:16 UTC
    String "-1" is OK, the number -1 is the problem. Easily fixed by (a bit longer)
    Error in my test. Please ignore.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1166891]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-06-20 19:16 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.