CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
declaring the same value for several variables.

 



Zeke_D
Deleted

Aug 10, 2000, 6:14 PM

Post #1 of 4 (628 views)
declaring the same value for several variables. Can't Post

is there an easier way to do this:
$q01='0'; $q02='0'; $q03='0'; $q04='0'; $q05='0'; $q06='0'; $q07='0'; $q08='0';


dws
Deleted

Aug 10, 2000, 8:49 PM

Post #2 of 4 (628 views)
Re: declaring the same value for several variables. [In reply to] Can't Post

Choose your poison:

$q01=$q02=$q03=$q04=$q05=$q06=$q07=$q08='0';

or

($q01,$q02,$q03,$q04,$q05,$q06,$q07,$q08) = 8 x ('0');

[oops: make that ('0') x 8; # thanks, japhy]


[This message has been edited by dws (edited 08-11-2000).]


japhy
Enthusiast

Aug 11, 2000, 3:07 AM

Post #3 of 4 (628 views)
Re: declaring the same value for several variables. [In reply to] Can't Post

You have it slightly backwards.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


($you,$me,$him) = ('foo') x 3;
</pre><HR></BLOCKQUOTE>

The left operand to the 'x' operator is the string or list to be repeated, and the right operand is the number of times.

And Zeke, if you're using variables like $a1, $a2, $a3, ..., you might want to use an array instead.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


@array = (0) x 10;
</pre><HR></BLOCKQUOTE>

------------------
Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher



Zeke_D
Deleted

Aug 11, 2000, 10:58 AM

Post #4 of 4 (628 views)
Re: declaring the same value for several variables. [In reply to] Can't Post

i think my preferred poison would be:
($q01,$q02,$q03,$q04,$q05,$q06,$q07,$q08) = 8 x ('0');

so to declare $q01 - $q20
() = 20 x ('0');

would that work with other variables $wrong $right etc?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives