Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
... I'm trying to count digits in a scalar

That's what the OP says, but the  /\d\D*/g regex suggests misterperl is trying to count occurrences of some kind of digit-group pattern. If that's the case, I can, offhand, think of some  s/// approaches (in the vein of a  tr/// operation) that would do the trick as well as the  m// approach that misterperl seems to favor:

c:\@Work\Perl\monks>perl -wMstrict -le "$_ = '+++1223w3433.45+34***'; ;; my $ndg; ;; $ndg =()= /\d\D*/g; print qq{A: $ndg digit grps.; m// change unpossible '$_'}; ;; $ndg = do { (my $r = $_) =~ s/\d\D*//g }; print qq{B: $ndg digit grps.; s/// string unchanged '$_'}; ;; $ndg = s/(\d\D*)/$1/g; print qq{C: $ndg digit grps.; s/// string unchanged '$_'}; ;; $ndg = s/\d\D*//g; print qq{D: $ndg digit grps.; s/// string CHANGED '$_'}; " A: 12 digit grps.; m// change unpossible '+++1223w3433.45+34***' B: 12 digit grps.; s/// string unchanged '+++1223w3433.45+34***' C: 12 digit grps.; s/// string unchanged '+++1223w3433.45+34***' D: 12 digit grps.; s/// string CHANGED '+++'
My own preference would be for the  m// approach.


Give a man a fish:  <%-{-{-{-<


In reply to Re^2: Some odd ambiguity in this regex by AnomalousMonk
in thread Some odd ambiguity in this regex by misterperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-25 14:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found