Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: can't use string refs while "strict refs"

by Marshall (Canon)
on Jul 30, 2012 at 06:34 UTC ( [id://984359]=note: print w/replies, xml ) Need Help??


in reply to can't use string refs while "strict refs"

You have sort of copied an example straight out of the Perlretut without really understanding what it does.

I would say that not everything that you read in the tutorials is common - there are some very complicated and rare things - and this is one of them!

This is so rare, that I don't think that it is worth delving into the mind-numbing details. VERY seldom do you even care in the slightest about the pos(position) of a match - that is 'C' thinking.

Perl regex is most commonly used to capture stuff that is between other stuff and whether this happens at index 5 or 95 usually just doesn't make any difference at all. The purists would say: "well sometimes it does matter" and I would agree with them. What I am saying here is that the pos() almost always does not matter.

I show some more common ideas in Perl below.

#!usr/bin/perl use warnings; use strict; my $x = "Mmm...donut, thought... Homer...Yech...peas"; my @matches = $x =~ /(Mmm|Yech)\.\.\.(donut|peas)/g; print "number of matches is: ".@matches."\n"; print "matches are: @matches\n"; print "\n"; $x = "MmmABCdonut, thought... HomerABXYechABYpeas"; my @moreMatches = $x =~ /(?:Mmm|Yech)(...)(?:donut|peas)/g; print "moreMatches number: ".@moreMatches,"\n"; print "@moreMatches\n"; __END__ prints: number of matches is: 4 matches are: Mmm donut Yech peas moreMatches number: 2 ABC ABY

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found