Re: easiest way to set $1 $2 $3...

Discussion in 'Perl Misc' started by Wolf Behrenhoff, Jul 18, 2012.

  1. Am 18.07.2012 11:25, schrieb :
    > In /bin/sh it merely takes a
    > $ set a b c
    > to set $1 $2 $3.
    >
    > So what is the easiest way to do the same in perl?
    >
    > Yes in perl they are related to regexps. No don't ask me why I want to
    > set them, Just pretend I need to use them on the next line and want to
    > try some different values.


    I do ask: why would you want to do that? Just put different values in
    the next line?

    > If it takes more than just a one-liner, then perl has problems.


    Don't understand!

    > So we see on perlvar there is no array that can give us even read-only
    > access to
    > $<digits> ($1, $2, ...)
    > not of course even to think of an easy way to set them by all directly by hand
    > if we need to.


    There are @+ and @- and (it is in pervar)
    $1 is the same as "substr($var, $-[1], $+[1] - $-[1])"
    $2 is the same as "substr($var, $-[2], $+[2] - $-[2])"
    and so on.

    - Wolf
     
    Wolf Behrenhoff, Jul 18, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gianni Galore
    Replies:
    0
    Views:
    363
    Gianni Galore
    Jan 12, 2011
  2. enspired

    easiest way to set future date

    enspired, Oct 30, 2005, in forum: Ruby
    Replies:
    1
    Views:
    107
    Gene Tani
    Oct 30, 2005
  3. RichardOnRails
    Replies:
    4
    Views:
    145
    RichardOnRails
    Jan 23, 2011
  4. Jürgen Exner

    Re: easiest way to set $1 $2 $3...

    Jürgen Exner, Jul 18, 2012, in forum: Perl Misc
    Replies:
    1
    Views:
    537
    Tim McDaniel
    Jul 18, 2012
  5. hymie!

    Re: easiest way to set $1 $2 $3...

    hymie!, Jul 18, 2012, in forum: Perl Misc
    Replies:
    0
    Views:
    394
    hymie!
    Jul 18, 2012
Loading...

Share This Page