Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
easiest way to set $1 $2 $3...
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
jida...@jidanni.org  
View profile  
 More options Jul 18 2012, 5:25 am
Newsgroups: comp.lang.perl.misc
From: jida...@jidanni.org
Date: Wed, 18 Jul 2012 17:25:03 +0800
Local: Wed, Jul 18 2012 5:25 am
Subject: easiest way to set $1 $2 $3...
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.

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

$ perl -wle '"abc" =~ /(.)(.)(.)/; print $1, $2, $3;'
abc

Big drag.

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.

Well maybe perlvar should mention what the best way so-far to access
them all (like /bin/sh's $@, $*), and set them all (like /bin/sh's set) is!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wolf Behrenhoff  
View profile  
 More options Jul 18 2012, 5:58 am
Newsgroups: comp.lang.perl.misc
From: Wolf Behrenhoff <NoSpamPleaseButThisIsVal...@gmx.net>
Date: Wed, 18 Jul 2012 11:58:11 +0200
Local: Wed, Jul 18 2012 5:58 am
Subject: Re: easiest way to set $1 $2 $3...
Am 18.07.2012 11:25, schrieb jida...@jidanni.org:

> 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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jürgen Exner  
View profile  
 More options Jul 18 2012, 6:44 am
Newsgroups: comp.lang.perl.misc
From: J rgen Exner <jurge...@hotmail.com>
Date: Wed, 18 Jul 2012 03:44:41 -0700
Local: Wed, Jul 18 2012 6:44 am
Subject: Re: easiest way to set $1 $2 $3...

jida...@jidanni.org wrote:
>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?

In Perl you would say: "Whenever you find yourself enumerating your
variables with numbers, then maybe it's a good time to think about using
an array instead". So take @foo and use
        @foo = (a, b, c);

>Yes in perl they are related to regexps. No don't ask me why I want to
>set them,

Sorry, but that question is at the core of your problem. For all
practical purposes you should consider those variables read-only. Yes,
technically you can assign to them, but whenever you feel the urge to do
so normally there is a different, much better way.

>Just pretend I need to use them on the next line and want to
>try some different values.

Then why don't you use different variables like @foo[1], @foo[2], ... in
this next line?

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

-v, please

>$ perl -wle '"abc" =~ /(.)(.)(.)/; print $1, $2, $3;'
>abc

>Big drag.

>So we see on perlvar there is no array that can give us even read-only
>access to
>       $<digits> ($1, $2, ...)

Why would you want to do that? The only time those variables are being
set is during a m// or s/// operation. And if you really want that list
of captured groups then you can easily capture your imaginary $<digit>
array:

    Matching in list context
        If the "/g" option is not used, "m//" in list context returns a
        list consisting of the subexpressions matched by the parentheses
        in the pattern, i.e., ($1, $2, $3...).

>not of course even to think of an easy way to set them by all directly by hand
>if we need to.

Why would you want to set them manually in the first place unless you
have some very unusual needs, e.g. interpreter-level debugging or
something like that?

>Well maybe perlvar should mention what the best way so-far to access
>them all (like /bin/sh's $@, $*), and set them all (like /bin/sh's set) is!

What for?

jue


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hymie!  
View profile  
 More options Jul 18 2012, 8:38 am
Newsgroups: comp.lang.perl.misc
From: hy...@lactose.homelinux.net (hymie!)
Date: 18 Jul 2012 12:38:25 GMT
Local: Wed, Jul 18 2012 8:38 am
Subject: Re: easiest way to set $1 $2 $3...
In our last episode, the evil Dr. Lacto had captured our hero,
  jida...@jidanni.org, who said:

>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?

Um... you *do* understand that "the shell" and "a perl program" are
two completely different things, right?  I mean, $1 $2 $3 in the context
of the shell, and $1 $2 $3 in the context of a running perl program
have no relation to each other beyond the fact that they are composed of
two characters, a dollar sign and a number.

>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.

You could (and probably should) use $q $w $e . Set them like they were
normal variables (which they are). They take no more keystrokes than
$1 $2 $3 do.

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

I would like perl to mow my lawn.  The fact that it can't doesn't mean
that "perl has problems".

This is funny -- my sig generater is random, and this is the one it picked.

--hymie!    http://lactose.homelinux.net/~hymie    hy...@lactose.homelinux.net
--------------------------------------------------------------------------- ----
It's not Perl's fault if you don't know how to program.      --Ronald J Kimball
--------------------------------------------------------------------------- ----


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rainer Weikusat  
View profile  
 More options Jul 18 2012, 9:00 am
Newsgroups: comp.lang.perl.misc
From: Rainer Weikusat <rweiku...@mssgmbh.com>
Date: Wed, 18 Jul 2012 14:00:43 +0100
Local: Wed, Jul 18 2012 9:00 am
Subject: Re: easiest way to set $1 $2 $3...

jida...@jidanni.org writes:
> 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.

Trivially, you don't "need to use them" except if capturing parts of a
string matched by some regexp. So, why don't you just use a suitable
string as input?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim McDaniel  
View profile  
 More options Jul 18 2012, 12:16 pm
Newsgroups: comp.lang.perl.misc
From: t...@panix.com (Tim McDaniel)
Date: Wed, 18 Jul 2012 16:16:39 +0000 (UTC)
Local: Wed, Jul 18 2012 12:16 pm
Subject: Re: easiest way to set $1 $2 $3...

>>So we see on perlvar there is no array that can give us even
>>read-only access to
>>       $<digits> ($1, $2, ...)

You can muck about with the symbol table, but I agree with the other
answers:

Perl: you're trying to do it wrong.

In article <gf3d08d7agdb9jpol3h27om4uln95pj...@4ax.com>,
J_rgen Exner  <jurge...@hotmail.com> wrote:

>Then why don't you use different variables like @foo[1], @foo[2],
>... in this next line?

$foo[1], $foo[2], ...

--
Tim McDaniel, t...@panix.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Seymour J. Shmuel Metz  
View profile  
 More options Jul 19 2012, 10:40 am
Newsgroups: comp.lang.perl.misc
From: Shmuel (Seymour J.) Metz <spamt...@library.lspace.org.invalid>
Date: Thu, 19 Jul 2012 10:40:14 -0400
Local: Thurs, Jul 19 2012 10:40 am
Subject: Re: easiest way to set $1 $2 $3...
In <ju5vf7$a...@news.datemas.de>, on 07/18/2012
   at 05:25 PM, jida...@jidanni.org said:

>So what is the easiest way to do the same in perl?

An assignment in array context.

>No don't ask me why I want to set them,

Why not? You're almost certainly asking the wrong question.

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

Only if it's something that programmers need to do frequently, which
it is not.

>$ perl -wle '"abc" =~ /(.)(.)(.)/; print $1, $2, $3;'

Looks normal.

>Big drag.

Why?

>So we see on perlvar there is no array that can give us even
>read-only access to
>       $<digits> ($1, $2, ...)

Who cares? There's also no array to give even read-only access to $_,
$&, and $/.

>not of course even to think of an easy way to set them by all
>directly by hand if we need to.

Of course there's an easy way, but it's pointless.

>Well maybe perlvar should mention what the best way so-far to access
>them all (like /bin/sh's $@, $*), and set them all (like /bin/sh's
>set) is!

If there were a point to it and it was relevant to perlvar then yes,
but since there isn't and it isn't then no.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamt...@library.lspace.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Randal L. Schwartz  
View profile  
 More options Jul 19 2012, 11:45 am
Newsgroups: comp.lang.perl.misc
From: mer...@stonehenge.com (Randal L. Schwartz)
Date: Thu, 19 Jul 2012 08:45:54 -0700
Local: Thurs, Jul 19 2012 11:45 am
Subject: Re: easiest way to set $1 $2 $3...

>>>>> "Shmuel" == Shmuel (Seymour J ) Metz <spamt...@library.lspace.org.invalid> writes:

Shmuel> An assignment in array context.

*list* context.  "wantarray" is misnamed.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »