Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: position of first matching regex

by AnomalousMonk (Archbishop)
on May 17, 2014 at 02:25 UTC ( [id://1086408]=note: print w/replies, xml ) Need Help??


in reply to position of first matching regex

Note also the general point that an expression like  $startloc = @- evaluates an array in scalar context and thus gives you the number of elements in the array, not the value of any particular element. See Context in perldata, and the tutorials Context tutorial, and Arrays: A Tutorial/Reference, in particular the section "Get count of elements".

Replies are listed 'Best First'.
Re^2: position of first matching regex
by techtaskers.com (Novice) on May 17, 2014 at 14:59 UTC

    Yup. That is an excellent goof on my part. I should be good at goofs, I've practiced all my life.

    My two lessons here are that: (@- != $-[0]) && $-[0] requires /...(...).../ re positional variables.

    Thank you for your reply.


    David
      ... $-[0] requires /...(...).../ re positional variables.

      You show a capturing group in your example and refer to "positional variables", so I thought I'd mention that  $-[0] is the offset of the start of the overall match and does not depend at all on capture groups.

      c:\@Work\Perl>perl -wMstrict -le "my $s = 'xxxabcyyy'; ;; print qq{overall match begining at offset $-[0] in '$s'} if $s =~ m{ abc }xms; " overall match begining at offset 3 in 'xxxabcyyy'

      (And BTW: I've been practicing goofs for quite a while myself.)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-23 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found