Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Parse string and extract word after specific pattern

by RonW (Parson)
on Mar 24, 2017 at 18:55 UTC ( [id://1185819]=note: print w/replies, xml ) Need Help??


in reply to Re: Parse string and extract word after specific pattern
in thread Parse string and extract word after specific pattern

FWIW, split(/\./, $string) can be rewritten as split('.', $string) which avoids using a regular expression.

Replies are listed 'Best First'.
Re^3: Parse string and extract word after specific pattern
by choroba (Cardinal) on Mar 25, 2017 at 09:56 UTC
    It also avoids the result, though.

    my $s = 'a.b.c'; say "1: $_" for split /\./, $s; say "2: $_" for split '.', $s;
    ($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,

      Apparently, the first argument to split is always treated as a regex, because split '\.', $s worked.

      The documentation implies a string and a regex are treated differently:

      (such as ' ' or "\x20" , but not e.g. / / )

      Seems that, as luck would have it, I never happened to use a regex meta character split 'x'.

      In light of the described differences in handling of ' ' vs / /, the documentation should state that the first argument is always treated as a regex even supplied as a string.

        > the documentation should state that the first argument is always treated as a regex

        It does at the very beginning of split:

        split /PATTERN/,EXPR,LIMIT split /PATTERN/,EXPR split /PATTERN/ split

        There are only three exceptions, space, empty regex, and /^/ .

        ($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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-19 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found