Home  |  Linux  | Mysql  | PHP  | XML
From:Rob Dixon Date:Tue May 13 18:02:40 2008
Subject:Re: want to assign default value to variable I assign from split
Richard Lee wrote:
>
> Rob Dixon wrote:
>>     
>> while (<FILE>) {
>>   my ($file1,$file2,$file3,$file4,$file5,$file6,$file10,$f`ile25,$file27) =
>>       map $_||'default', (split /\|/)[3,4,6,7,12,40,41,42,43,46,56,64];
>> }
> 
> Thank you everyone.
> 
> I like this solution the best and thanks for pointing out that I was 
> misusing |= vs ||=

I'm not entirely happy with it as it stands. The numbered $file99 variables are
ugly and are screaming for an array, but without knowing more about what you're
doing I can't improve on what you originally wrote.

But I would prefer to see list of indices declared as a constant and the data
values defaulted separately, like this:

  use constant INDICES => (3,4,6,7,12,40,41,42,43,46,56,64);

  while (<FILE>) {
    my @data = map $_ || 'default', split /\|/;
    my ($file1,$file2,$file3,$file4,$file5,$file6,$file10,$file25,$file27) =
@data[(INDICES)];
  }

HTH,

Rob


Navigate in group perl.beginners at sever nntp.perl.org
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants