in reply to Re^2: How can I sort my array numerically on part of the string? (updated)
in thread How can I sort my array numerically on part of the string?

TY I didnt realise I needed the [0] I'm gonna try that. Although I'm unclear as to what "list" is involved with $a and $b which appear to be scalar?
  • Comment on Re^3: How can I sort my array numerically on part of the string? (updated)

Replies are listed 'Best First'.
Re^4: How can I sort my array numerically on part of the string? (updated)
by LanX (Saint) on Dec 02, 2020 at 13:41 UTC

    > > You need that (...)[0] for the match to return the captures in list context, ( <=> is enforcing scalar context and m// only returns captures in list context otherwise boolean )

    DB<96> $_= "123,foo" DB<97> p scalar m/(\d+,)/ # boolean value 1 DB<98> p m/(\d+,)/ # list of captures 123, DB<99>

    see https://perldoc.perl.org/perlop#Matching-in-list-context

    If the /g option is not used, m// in list context returns a list consisting of the subexpressions matched by the parentheses in the pattern, that is, ($1, $2, $3...) (Note that here $1 etc. are also set). When there are no parentheses in the pattern, the return value is the list (1) for success. With or without parentheses, an empty list is returned upon failure.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Re^4: How can I sort my array numerically on part of the string? (updated)
by Anonymous Monk on Dec 02, 2020 at 13:26 UTC
    the list is the return values of the regex