Re: assign default value to variables I assign from split

[email protected] (Richard Lee)
Newsgroups perl.beginners
Message-ID <[email protected]>
Dr.Ruud wrote:
> "Jenda Krynicky" schreef:
>   
>> Dr.Ruud:
>>     
>>> Richard Lee:
>>>       
>
>   
>>>> [$file1,$file2,$file3,$file4,$file5,$file6,$file10,$file25]
>>>> I didn't want to put them in array
>>>> since I need to use individual named variable later
>>>>         
>>> And why is that?
>>>       
>> Maybe because in the real code they are not $file1, $file2,...
>> but rather $username, $password, $last_login, $created,
>> $permissions, ...
>>     
>
> Then you create named constants for that, with enumeration if you like;
> or use a hash.
>
>
>   
>> And assigning the default is the last thing that's done to all of
>> them.
>>     
>
> There would be no problem to do that.
>
> But better stop guessing and let Richard answer.
>
>   
yes, variables are particular names and later I wanted to refer back by 
variable names.

However, for now I have done this so far so I just added as array 
instead of breaking out by var names..
-- code is incomplete (meaning I haven't finished yet) --

use warnings;
use strict;
use Data::Dumper;

my $directory = q#/home/server1/arch#;
my @array = qx/ls -tr $directory | tail -1/;

my @hh;
for ( @array ) {
        my $file = $_;
        open FILE, "ls -tr | zcat -d $directory/$file |", or die qq/you 
truly suck $!\n/;
        my $count;
        my %hh;
        while (<FILE>) {
             chomp;
             next if /^$/;
             next if /^#/;
  
             my @array   = map $_||'default', (split 
/\|/)[3,4,6,7,12,40,41,42,43,46,56,64];
             next if $array[0] eq 'default';
             $array[10] =~ s/\,/\-/g;
             push @hh, \@array;
        }
        close FILE;
}

system("clear");
print 
"===================================================================================================\n\n";

my %missing_address;
my %duration_report;

for (@hh) {
    my $yahoo = $_;
    $missing_address{$$yahoo[1]}++ if $$yahoo[8] =~ /^default$/ and 
$$yahoo[0] != m/espn|google|msn/;
    $$yahoo[4] +=
}

if (%missing_cics) {
   for (keys %missing_address) {
       print "MISSING ADD: $_ : $missing_address{$_} \n";
   }
}

for (keys %duration_report) {
     print "total duration $_  : $duration_report{$_}\n";
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.