Re: Multiple variable initialization

2005-03-12 Thread Alfred Vahau
my ($var1, $var2, $var3) = (1) x 3;
Now that is neat! This usage of the repetition operator (x) is actually 
described in 'The Camel' book, p. 94

Alfred
Peter Scott wrote:
On Fri, 11 Mar 2005 16:20:50 -0500, Peter Rabbitson wrote:
 

On Fri, Mar 11, 2005 at 04:09:12PM -0500, Todd W wrote:
   

"Peter Rabbitson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
 

On Fri, Mar 11, 2005 at 12:45:10PM -0800, Wagner, David --- Senior
   

Programmer Analyst --- WGO wrote:
 

Peter Rabbitson wrote:
 

Is there a quick way to initialize a number of variables at once?
Something like
my ($var1, $var2, $var3);
   

my ($var1, $var2, $var3) = ( 1,1,1 );
 

[snip]
 

What I meant however was something along the lines of 
my ($var1, $var2, $var3... arbitrary number of vars) = 1, 
which obviously doesn't work, but I hoped it's only due to my lack of syntax 
knowledge.
   

my ($var1, $var2, $var3) = (1) x 3;
 

--
Perl - 
"... making the easy jobs easy,
without making the hard jobs impossible."
'The Camel', 3ed

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Multiple variable initialization

2005-03-12 Thread Peter Scott
On Fri, 11 Mar 2005 16:20:50 -0500, Peter Rabbitson wrote:
> On Fri, Mar 11, 2005 at 04:09:12PM -0500, Todd W wrote:
>> 
>> "Peter Rabbitson" <[EMAIL PROTECTED]> wrote in message
>> news:[EMAIL PROTECTED]
>> > On Fri, Mar 11, 2005 at 12:45:10PM -0800, Wagner, David --- Senior
>> Programmer Analyst --- WGO wrote:
>> > > Peter Rabbitson wrote:
>> > > > Is there a quick way to initialize a number of variables at once?
>> > > > Something like
>> > > >
>> > > > my ($var1, $var2, $var3);
>> > > my ($var1, $var2, $var3) = ( 1,1,1 );
[snip]
> What I meant however was something along the lines of 
> my ($var1, $var2, $var3... arbitrary number of vars) = 1, 
> which obviously doesn't work, but I hoped it's only due to my lack of syntax 
> knowledge.

my ($var1, $var2, $var3) = (1) x 3;

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Multiple variable initialization

2005-03-11 Thread Randal L. Schwartz
> "Peter" == Peter Rabbitson <[EMAIL PROTECTED]> writes:

Peter> Is there a quick way to initialize a number of variables at once? 
Something 
Peter> like 

Peter> my ($var1, $var2, $var3);

Peter> but instead of having undef in all of them, let's say I want to have 1 
in 
Peter> each. Any takers?

First, I generally don't declare a lot of variables at the beginning
of my program.  I introduce them into the smallest scope where they
make sense.  Globals Are Evil.  Haven't you heard? :)

Second, if I do have three variables to declare, I do them with
separate statements, so I can also COMMENT them.  You *do* comment
your variables, right?

my $rate = 23; # how fast are we going, initially
my $age = 43; # getting old!

etc.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Multiple variable initialization

2005-03-11 Thread Alfred Vahau
my ($var1, $var2, $var3... arbitrary number of vars) = 1, 
which obviously doesn't work, but I hoped it's only due to my lack of syntax 
knowledge.

my $var1 = my $var2 = my $var3 = 1;
works. Still ugly?
alfred
Peter Rabbitson wrote:
On Fri, Mar 11, 2005 at 04:09:12PM -0500, Todd W wrote:
 

"Peter Rabbitson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
   

On Fri, Mar 11, 2005 at 12:45:10PM -0800, Wagner, David --- Senior
 

Programmer Analyst --- WGO wrote:
   

Peter Rabbitson wrote:
   

Is there a quick way to initialize a number of variables at once?
Something like
my ($var1, $var2, $var3);
 

my ($var1, $var2, $var3) = ( 1,1,1 );
Wags ;)
   

but instead of having undef in all of them, let's say I want to have
1 in each. Any takers?
Peter
 

But... isn't... this... ahem... like... um... ugly? :)
 

other than the program reading your mind, how could it be more consise?
   

Well, this would definitely be a very neat feature, I hope Larry Wall is 
reading this list and is already cracking on the new Telepathy::Simple :)

What I meant however was something along the lines of 
my ($var1, $var2, $var3... arbitrary number of vars) = 1, 
which obviously doesn't work, but I hoped it's only due to my lack of syntax 
knowledge.

Peter
 

--
Perl - 
"... making the easy jobs easy,
without making the hard jobs impossible."
'The Camel', 3ed

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Multiple variable initialization

2005-03-11 Thread Peter Rabbitson
On Fri, Mar 11, 2005 at 04:09:12PM -0500, Todd W wrote:
> 
> "Peter Rabbitson" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On Fri, Mar 11, 2005 at 12:45:10PM -0800, Wagner, David --- Senior
> Programmer Analyst --- WGO wrote:
> > > Peter Rabbitson wrote:
> > > > Is there a quick way to initialize a number of variables at once?
> > > > Something like
> > > >
> > > > my ($var1, $var2, $var3);
> > > my ($var1, $var2, $var3) = ( 1,1,1 );
> > > Wags ;)
> > > >
> > > > but instead of having undef in all of them, let's say I want to have
> > > > 1 in each. Any takers?
> > > >
> > > > Peter
> > >
> >
> > But... isn't... this... ahem... like... um... ugly? :)
> 
> other than the program reading your mind, how could it be more consise?

Well, this would definitely be a very neat feature, I hope Larry Wall is 
reading this list and is already cracking on the new Telepathy::Simple :)

What I meant however was something along the lines of 
my ($var1, $var2, $var3... arbitrary number of vars) = 1, 
which obviously doesn't work, but I hoped it's only due to my lack of syntax 
knowledge.

Peter

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Multiple variable initialization

2005-03-11 Thread Todd W

"Todd W" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> "Peter Rabbitson" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > On Fri, Mar 11, 2005 at 12:45:10PM -0800, Wagner, David --- Senior
> Programmer Analyst --- WGO wrote:
> > > Peter Rabbitson wrote:
> > > > Is there a quick way to initialize a number of variables at once?
> > > > Something like
> > > >
> > > > my ($var1, $var2, $var3);
> > > my ($var1, $var2, $var3) = ( 1,1,1 );
> > > Wags ;)
> > > >
> > > > but instead of having undef in all of them, let's say I want to have
> > > > 1 in each. Any takers?
> > > >
> > > > Peter
> > >
> >
> > But... isn't... this... ahem... like... um... ugly? :)
>
> other than the program reading your mind, how could it be more consise?
>
wasnt finished...

$_ = 1 foreach ( my($foo, $bar, $baz) );
print(map "$_\n", $foo, $bar, $baz);

???

My code rarely has something like this. My stuff usually looks like:

use IO::File;
if ( my $fh = IO::File->new('< somefile') ) {
  while ( my $line = $fh->getline ) {
   # ...
  }
} else {
  applicationSpecificErrorHandler("cant open file: $!");
}

this $fh lives only in if (...) {...} so I know Im not changing the values
of variables elsewhere.

I may be lying, but I'd guess its been a few years since I used an index
variable in perl. Use arrays and hashes to enumerate your data.

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Multiple variable initialization

2005-03-11 Thread Todd W

"Peter Rabbitson" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Fri, Mar 11, 2005 at 12:45:10PM -0800, Wagner, David --- Senior
Programmer Analyst --- WGO wrote:
> > Peter Rabbitson wrote:
> > > Is there a quick way to initialize a number of variables at once?
> > > Something like
> > >
> > > my ($var1, $var2, $var3);
> > my ($var1, $var2, $var3) = ( 1,1,1 );
> > Wags ;)
> > >
> > > but instead of having undef in all of them, let's say I want to have
> > > 1 in each. Any takers?
> > >
> > > Peter
> >
>
> But... isn't... this... ahem... like... um... ugly? :)

other than the program reading your mind, how could it be more consise?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Multiple variable initialization

2005-03-11 Thread Peter Rabbitson
On Fri, Mar 11, 2005 at 12:45:10PM -0800, Wagner, David --- Senior Programmer 
Analyst --- WGO wrote:
> Peter Rabbitson wrote:
> > Is there a quick way to initialize a number of variables at once?
> > Something like
> > 
> > my ($var1, $var2, $var3);
>   my ($var1, $var2, $var3) = ( 1,1,1 );
> Wags ;)
> > 
> > but instead of having undef in all of them, let's say I want to have
> > 1 in each. Any takers?
> > 
> > Peter
> 

But... isn't... this... ahem... like... um... ugly? :)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Multiple variable initialization

2005-03-11 Thread Chris Devers
On Fri, 11 Mar 2005, Peter Rabbitson wrote:

> Is there a quick way to initialize a number of variables at once? Something 
> like 
> 
> my ($var1, $var2, $var3);
> 
> but instead of having undef in all of them, let's say I want to have 1 in 
> each. Any takers?

Yes.

my ($var1, $var2, $var3) = (1, 1, 1);

 

-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Multiple variable initialization

2005-03-11 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Peter Rabbitson wrote:
> Is there a quick way to initialize a number of variables at once?
> Something like
> 
> my ($var1, $var2, $var3);
my ($var1, $var2, $var3) = ( 1,1,1 );
Wags ;)
> 
> but instead of having undef in all of them, let's say I want to have
> 1 in each. Any takers?
> 
> Peter



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]