[26893] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8884 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 25 14:05:27 2006

Date: Wed, 25 Jan 2006 11:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 25 Jan 2006     Volume: 10 Number: 8884

Today's topics:
    Re: array question <1usa@llenroc.ude.invalid>
    Re: array question <jurgenex@hotmail.com>
        concatenate variables during looping question <lance-news@augustmail.com>
    Re: concatenate variables during looping question <sbryce@scottbryce.com>
    Re: concatenate variables during looping question (James Taylor)
    Re: concatenate variables during looping question (James Taylor)
    Re: concatenate variables during looping question <sbryce@scottbryce.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 25 Jan 2006 11:24:59 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: array question
Message-Id: <Xns975641583A7CCasu1cornelledu@127.0.0.1>

"a" <a@mail.com> wrote in news:ZgIBf.443643$ki.227071@pd7tw2no:

[ Please don't top-post ]

> By the way, how to comment the whole block of code?

You are expected to read the FAQ before you post here:

perldoc -q "How can I comment out a large block of perl code?"

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: Wed, 25 Jan 2006 15:05:49 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: array question
Message-Id: <htMBf.46215$Ez3.8655@trnddc03>

[Please do not top-post!!!]
[Please do not blindly full-quote]

a wrote:
>>>>> my @ary;
>>>>> $ary[0]="a";
>>>>> $ary[1]="b";
>>>>
>>>> Have you tried it? What happened?

> syntax error at filename line 20, near "]~"

I don't believe you. Your code doesn't even have 20 lines.

jue 




------------------------------

Date: Wed, 25 Jan 2006 11:11:14 -0600
From: lance-news <lance-news@augustmail.com>
Subject: concatenate variables during looping question
Message-Id: <43d7b145$0$1765$8b463f8a@news.nationwide.net>

Hey all,

Trying to create a loop and need some help
in concatenation

My current syntax:

$Sheet->Cells(16,2)->{Value} = $Ja13_1;
$Sheet->Cells(16,3)->{Value} = $Ja13_2;
$Sheet->Cells(16,4)->{Value} = $Ja13_3;
$Sheet->Cells(16,5)->{Value} = $Ja13_4;
$Sheet->Cells(16,6)->{Value} = $Ja13_5;
$Sheet->Cells(16,7)->{Value} = $Ja13_6;

$Sheet->Cells(34,2)->{Value} = $Ks13_1;
$Sheet->Cells(34,3)->{Value} = $Ks13_2;
$Sheet->Cells(34,4)->{Value} = $Ks13_3;
$Sheet->Cells(34,5)->{Value} = $Ks13_4;
$Sheet->Cells(34,6)->{Value} = $Ks13_5;
$Sheet->Cells(34,7)->{Value} = $Ks13_6;

What I am trying to do:

for (my $i=2; $i=7; $i++){
$Sheet->Cells(16,$i)->{Value} = "$Ja13_"."$i-1";
                          }

but doesn't work.



Also, how could I incorporate an array so I could create 2 loops such 
that all the lines above compress to one line?

Thanks in advance,

Lance


------------------------------

Date: Wed, 25 Jan 2006 10:42:12 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: concatenate variables during looping question
Message-Id: <ZdqdnXchkNnpJUrenZ2dnUVZ_t-dnZ2d@comcast.com>

First, please read the posting guidelines for this group. I was unable 
to copy and paste your code and run it. I don't want to take the time to 
re-create your script to run it.

lance-news wrote:
> for (my $i=2; $i=7; $i++)

This for loop will run forever. $i=7 will always evaluate to True.

did you mean:

for my $i (2 .. 7)


------------------------------

Date: Wed, 25 Jan 2006 17:57:29 +0000
From: usenet@oakseed.demon.co.uk.invalid (James Taylor)
Subject: Re: concatenate variables during looping question
Message-Id: <1h9qeqt.id99hyddlbxvN%usenet@oakseed.demon.co.uk.invalid>

lance-news <lance-news@augustmail.com> wrote:

> My current syntax:
> 
> $Sheet->Cells(16,2)->{Value} = $Ja13_1;
> $Sheet->Cells(16,3)->{Value} = $Ja13_2;
> $Sheet->Cells(16,4)->{Value} = $Ja13_3;
> $Sheet->Cells(16,5)->{Value} = $Ja13_4;
> $Sheet->Cells(16,6)->{Value} = $Ja13_5;
> $Sheet->Cells(16,7)->{Value} = $Ja13_6;
> 
> $Sheet->Cells(34,2)->{Value} = $Ks13_1;
> $Sheet->Cells(34,3)->{Value} = $Ks13_2;
> $Sheet->Cells(34,4)->{Value} = $Ks13_3;
> $Sheet->Cells(34,5)->{Value} = $Ks13_4;
> $Sheet->Cells(34,6)->{Value} = $Ks13_5;
> $Sheet->Cells(34,7)->{Value} = $Ks13_6;


You should create a hash to hold all those variables instead of having
so many similarly named variables. I hate to imagine what your my()
declarations look like. What? You don't have any? Aren't you using
strict? Tut tut.

> What I am trying to do:
> 
> for (my $i=2; $i=7; $i++){
> $Sheet->Cells(16,$i)->{Value} = "$Ja13_"."$i-1";
>                           }
> 
> but doesn't work.

Just saying "doesn't work" is something you should avoid as it's just
not helpful to anyone. Say what it doesn't do and what you expect it to
do and people can help.

If you had some hashes called say %Ja and %Ks to hold all those values,
you could just write:

for (my $i=2; $i < 7; $i++) {
    $Sheet->Cells(16, $i + 1)->{Value} = $Ja{"13_$i"};
    $Sheet->Cells(34, $i + 1)->{Value} = $Ks{"13_$i"};
}
 
> Also, how could I incorporate an array so I could create 2 loops such
> that all the lines above compress to one line?

Not sure what you mean, and I'm not sure the clarity and maintainability
of you code would be served particularly well by compressing into just
one line anyway.

-- 
James Taylor


------------------------------

Date: Wed, 25 Jan 2006 18:01:19 +0000
From: usenet@oakseed.demon.co.uk.invalid (James Taylor)
Subject: Re: concatenate variables during looping question
Message-Id: <1h9qfcu.72cpsdpr5pk8N%usenet@oakseed.demon.co.uk.invalid>

James Taylor <usenet@oakseed.demon.co.uk.invalid> wrote:

> for (my $i=2; $i < 7; $i++) {
>     $Sheet->Cells(16, $i + 1)->{Value} = $Ja{"13_$i"};
>     $Sheet->Cells(34, $i + 1)->{Value} = $Ks{"13_$i"};
> }

Oops, that should run from $1=1 to 6, of course.

-- 
James Taylor


------------------------------

Date: Wed, 25 Jan 2006 11:18:45 -0700
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: concatenate variables during looping question
Message-Id: <546dnTMOXvCYXEreRVn-hw@comcast.com>

James Taylor wrote:

> If you had some hashes called say %Ja and %Ks to hold all those values,
> you could just write:
> 
> for (my $i=2; $i < 7; $i++) {
>     $Sheet->Cells(16, $i + 1)->{Value} = $Ja{"13_$i"};
>     $Sheet->Cells(34, $i + 1)->{Value} = $Ks{"13_$i"};
> }

He could write that, but then $Sheet->Cells(16, 2)->{Value} and 
$Sheet->Cells(34, 2)->{Value} would never be assigned.

He might prefer to write:

for my $i (2 .. 7)
{
	$Sheet->Cells(16, $i)->{Value} = $Ja{'13_' . $i - 1};
	$Sheet->Cells(34, $i)->{Value} = $Ks{'13_' . $i - 1};
}

Or he might prefer to use arrays instead of hashes.

my @Ja13;
my @Ks13;

# Assign some values to each array

for my $i (2 .. 7)
{
	$Sheet->Cells(16, $i)->{Value} = $Ja13[$i - 1];
	$Sheet->Cells(34, $i)->{Value} = $Ks13[$i - 1];
}


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8884
***************************************


home help back first fref pref prev next nref lref last post