Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: RE question...yup, another one ;)

by nardo (Friar)
on May 26, 2001 at 23:23 UTC ( [id://83529]=note: print w/replies, xml ) Need Help??


in reply to RE question...yup, another one ;)

perl -e 'for ( $dec = 0 ; $dec <= 300 ; $dec++ ) {$dec =~ /(\d)$/ && print "$dec -> $1\n"; }'

Replies are listed 'Best First'.
Re: Re: RE question...yup, another one ;)
by snafu (Chaplain) on May 26, 2001 at 23:25 UTC
    Wow, that was fast. I was actually about to say that I figured it out. But now, I notice my solution is a bit different from yours nardo. Which is better?

    perl -e 'for ( $dec = 0 ; $dec <= 300 ; $dec++ ) { ($one = $dec) =~ s +/(\d)+(\d)/$2/;print "$dec -> $one\n"; }'

    ----------
    - Jim

      Which is better I suppose depends on personal style. Personally, I think that
      perl -e 'for (0..300) {print "$_ -> ", chop, "\n"; }'
      is best, but the best approach using a regex is, in my opinion,
      perl -e 'for (0..300) {/(\d)$/ && print "$_ -> $1\n"; }'
      I think it's better style to use parenthesis inside a regex to match data and put it in $1 than it is to assign the whole thing to a new variable and then remove everything except what you want.
        Yeah. It was faster than mine too, noticeably...

        ----------
        - Jim

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-18 21:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found