Home  |  Linux  | Mysql  | PHP  | XML
From:Richard Lee Date:Mon May 12 21:39:07 2008
Subject:want to assign default value to variable I assign from split but

while (<FILE>) {
     my($file1,$file2,$file3,$file4,$file5,$file6,$file10,$file25,$file27)
         = (split( /\|/, $_))[3,4,6,7,12,40,41,42,43,46,56,64]
}

while doing above, what is the easiest way to make sure all the variable 
that's being given a value is true and if not
assign something default value (such as 'default' or 'X') ?

I was doing (after the while loop)

$file |= 'default'
$file2 |= 'default2'
$file3 |= 'default3'

but I stopped and thought this cannot be so repetitious

so I didn't want to but tried( I didn't want to put them in array since 
I need to use individual named variable later)

while (<FILE>) {
       my @array = (split( /\|/, $_))[3,4,6,7,12,40,41,42,43,46,56,64]
}
for (@array) {
     $_  |= 'default';
}

but is that the best way to do this?

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