Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^6: Sorting text-number values

by merrymonk (Hermit)
on Nov 30, 2016 at 10:49 UTC ( [id://1176916]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Sorting text-number values
in thread Sorting text-number values

If I use exactly your Perl, I get the output.

If I ‘hash’ out your ‘use 5.010;’ - I get the following error message on the MSDOS screen

Bareword "say" not allowed while "strict subs" in use at ………..amonk_f_sort.pz line 28.

Using

use strict; print "perl version $^V\n";
and the output is perl version v5.20.2

Therefore it seems it is something to do with the version of Perl being used.

It would be good to know how to change your Perl so that it works using 'use strict;" and with my current version of Perl (and I would like to know where the sorted data is stored or how I can store it in an array).

Replies are listed 'Best First'.
Re^7: Sorting text-number values
by hippo (Bishop) on Nov 30, 2016 at 11:12 UTC
    If I ‘hash’ out your ‘use 5.010;’ - I get (... a syntax error)

    So, don't do that then. Leave the working line in place.

      Fair enough - but I need to use this sort in a Perl application that may need facilities in 5.20 which are not in 5.010. To some extent this will be fine unless the difference in behaviour is 'hidden' so that it is not simple to detect 'odd' things that are going wrong.

      Also, I do need to understand where the data is stored or how to store the sorted data in an array.

        Also, I do need to understand where the data is stored or how to store the sorted data in an array.

        Just assign to an array!

        my @sorted = map { substr $_, 54 } sort map { do { no warnings qw{ uninitialized }; pack qq{A${width}NA*}, m{(.*\D)?(\d+)$}, $_; } } @data;

        Simples!

        Cheers,

        JohnGG

        Are you aware what this line means?

        use 5.010;

        This enables features from Perl 5.10, but works on any version of Perl later than that.

        As Perl 5.20 is a later version, use 5.010; has little effect there beyond enabling the say keyword.

        Fair enough - but I need to use this sort in a Perl application that may need facilities in 5.20 which are not in 5.010.

        And in what way do you suppose having the use 5.010; statement in the code would prohibit that?

        You cannot take working code, remove lines which you don't understand and then complain that it no longer works. This is as true of Perl as in any other language.

        If you do remove a line from working code which then breaks then the appropriate course of action is to learn what that line means. In many cases this is as simple as running perldoc -f use which would have told you. Among other very useful information it says:

        "use VERSION" also lexically enables all features available in the requested version as defined by the "feature" pragma, disabling any features not in the requested version's feature bundle. See feature. Similarly, if the specified Perl version is greater than or equal to 5.12.0, strictures are enabled lexically as with "use strict". Any explicit use of "use strict" or "no strict" overrides "use VERSION", even if it comes before it. Later use of "use VERSION" will override all behavior of a previous "use VERSION", possibly removing the "strict" and "feature" added by "use VERSION". "use VERSION" does not load the feature.pm or strict.pm files.

        ... etc. Feel free to play with code, take it apart, break it, reassemble it. All this is good for learning. But when it breaks, try to understand how and why.

        HTH, Hippo

Re^7: Sorting text-number values
by Corion (Patriarch) on Nov 30, 2016 at 11:21 UTC

    Why do you comment out the use 5.010;?

    The code as posted by me works as is with Perl 5.22 and likely every version of Perl between 5.10 and 5.24.

    If you want to avoid say, read say and then reimplement say using print.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2024-04-23 23:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found