in reply to Re: extracting variables from regex
in thread extracting variables from regex

echo 1234.45.67.890 | perl -ne'split /\./; printf "%X%X%X%X",@_'

From split's documentation:

In scalar context, returns the number of fields found and splits into the @_ array. Use of split in scalar context is deprecated, however, because it clobbers your subroutine arguments.
Why not have split in list context, and forget about @_?
printf "...", split /\./

U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk

Replies are listed 'Best First'.
(MeowChow) Re3: extracting variables from regex
by MeowChow (Vicar) on Apr 03, 2002 at 12:01 UTC
    Why have split at all?
      
    echo 192.168.0.1 | perl -nle 'printf "%02X"x4, /\d+/g'
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
Re: Re: Re: extracting variables from regex
by RMGir (Prior) on Apr 02, 2002 at 22:17 UTC
    Because... No particular reason :)

    I always do that for one liners, out of laziness.

    For any real script, I use -w and strict, and have gotten out of the bad habit.

    You're right, I shouldn't be doing it in one-liners, either.
    --
    Mike