"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]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to