problem with naming of variables
--_c5d3b091-f5d3-4f37-9734-59faf196b5d9_
Content-Type: text/plain; charset="big5"
Content-Transfer-Encoding: quoted-printable
Hi, How do I name this variable correctly, [at] {bet$random_bet_position);
With regards to the script below, [at] selected_bet is suppose to select eith=
er [at] bet1, [at] bet2 or [at] bet3 depending on the chosen number held by $random_b=
et_position, so how do I do this? Thanks
[at] bet1 =3D (0,0,0,0);
[at] bet2 =3D (0,0,0,1);
[at] bet3 =3D (0,0,1,0);
$random_bet_position =3D int(rand(3) + 1);
[at] selected_bet =3D [at] {bet$random_bet_position);
--_c5d3b091-f5d3-4f37-9734-59faf196b5d9_--
Re: problem with naming of variables
--90e6ba180db29ad0f5049f8be39c
Content-Type: text/plain; charset=ISO-8859-1
2011/3/28 jj mahoney <itshardtogetone [at] hotmail.com>
>
> Hi, How do I name this variable correctly, [at] {bet$random_bet_position);
> With regards to the script below, [at] selected_bet is suppose to select either
> [at] bet1, [at] bet2 or [at] bet3 depending on the chosen number held by
> $random_bet_position, so how do I do this? Thanks
>
> [at] bet1 = (0,0,0,0);
> [at] bet2 = (0,0,0,1);
> [at] bet3 = (0,0,1,0);
>
> $random_bet_position = int(rand(3) + 1);
>
> [at] selected_bet = [at] {bet$random_bet_position);
>
[at] bets = ( [0,0,0,0], [0,0,0,1], [0,0,1,0] );
[at] selected_bet = [at] {$bets[$random_bet_position]};
--
Robert Wohlfarth
--90e6ba180db29ad0f5049f8be39c--
RE: problem with naming of variables
Maybe this way:
[at] bet1 =3D (0,0,0,0);
[at] bet2 =3D (0,0,0,1);
[at] bet3 =3D (0,0,1,0);
$random_bet_position =3D int(rand(3) + 1);
$name =3D 'bet' . $random_bet_position;
[at] selected_bet =3D [at] {$name};
-----Original Message-----
From: jj mahoney [mailto:itshardtogetone [at] hotmail.com]
Sent: Monday, March 28, 2011 4:28 PM
To: beginners [at] perl.org
Subject: problem with naming of variables
Hi, How do I name this variable correctly, [at] {bet$random_bet_position);
With regards to the script below, [at] selected_bet is suppose to select either=
[at] bet1, [at] bet2 or [at] bet3 depending on the chosen number held by $random_bet_p=
osition, so how do I do this? Thanks
[at] bet1 =3D (0,0,0,0);
[at] bet2 =3D (0,0,0,1);
[at] bet3 =3D (0,0,1,0);
$random_bet_position =3D int(rand(3) + 1);
[at] selected_bet =3D [at] {bet$random_bet_position);
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: problem with naming of variables
2011/3/28 jj mahoney <itshardtogetone [at] hotmail.com>:
>
> Hi, How do I name this variable correctly, [at] {bet$random_bet_position);
> With regards to the script below, [at] selected_bet is suppose to select either [at] bet1, [at] bet2 or [at] bet3 depending on the chosen number held by $random_bet_position, so how do I do this? Thanks
>
> [at] bet1 = (0,0,0,0);
> [at] bet2 = (0,0,0,1);
> [at] bet3 = (0,0,1,0);
>
> $random_bet_position = int(rand(3) + 1);
>
> [at] selected_bet = [at] {bet$random_bet_position);
What you want is an Array of Arrays. Other replies have given you
syntax that covers it, but you would be well served by reading the
documentation that covers them: perldoc perldsc or the web version
http://perldoc.perl.org/perldsc.html. You will also want to become
familiar with references and how they work: perldoc perlref and
http://perldoc.perl.org/perlref.html. If you find that document too
formidable, you may want to start with: perldoc perlreftut or
http://perldoc.perl.org/perlreftut.html.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: problem with naming of variables
--0016e6dd8f44de3faf049f8d0829
Content-Type: text/plain; charset=ISO-8859-1
On Mon, Mar 28, 2011 at 12:10 PM, Katya Gorodinsky <
Katya.Gorodinsky [at] ecitele.com> wrote:
> $random_bet_position = int(rand(3) + 1);
>
> $name = 'bet' . $random_bet_position;
> [at] selected_bet = [at] {$name};
>
> No no no.
Gosh no.
Don't do that.
http://perl.plover.com/varvarname.html
Brian.
--0016e6dd8f44de3faf049f8d0829--
Re: problem with naming of variables
On Mon, Mar 28, 2011 at 11:10, Katya Gorodinsky
<Katya.Gorodinsky [at] ecitele.com> wrote:
> Maybe this way:
>
> [at] bet1 =3D (0,0,0,0);
> [at] bet2 =3D (0,0,0,1);
> [at] bet3 =3D (0,0,1,0);
>
> =C2=A0$random_bet_position =3D int(rand(3) + 1);
>
> =C2=A0$name =3D 'bet' . $random_bet_position;
> =C2=A0 [at] selected_bet =3D [at] {$name};
Symbolic references are incredibly dangerous and mostly unnecessary in
Modern Perl. This is why the [strict pragma][0] bans their use. The
proper solution is to use the correct data structure (in this case an
array of arrays).
[0]: http://perldoc.perl.org/strict.html
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/