R
Rocky
I am trying to use strict all the time now. I have a problem with the
following code. When I use strict the value of $highest won't leave the
foreach construct. I know this is by design but I cannot figure out how
make that variable available outside the loop. Any advice?
Also if someone could tell me where to find perldoc regarding "use
strict;" or scoping in general I would appreciate it.
#!/usr/bin/perl
my $number = 1;
my $dir = "/etc/backup";
opendir DIR1, $dir;
my @files = readdir(DIR1);
closedir DIR1;
foreach my $filename (@files)
{
push(@filenum, $1) if ($filename =~ /^CUX(\d+)\.txt$/);
#my $highest = (sort { $a <=> $b } @filenum)[-1];
}
$highest = (sort { $a <=> $b } @filenum)[-1];
$final = $highest + $number;
print "CUX00" . "$final" . ".txt\n";
following code. When I use strict the value of $highest won't leave the
foreach construct. I know this is by design but I cannot figure out how
make that variable available outside the loop. Any advice?
Also if someone could tell me where to find perldoc regarding "use
strict;" or scoping in general I would appreciate it.
#!/usr/bin/perl
my $number = 1;
my $dir = "/etc/backup";
opendir DIR1, $dir;
my @files = readdir(DIR1);
closedir DIR1;
foreach my $filename (@files)
{
push(@filenum, $1) if ($filename =~ /^CUX(\d+)\.txt$/);
#my $highest = (sort { $a <=> $b } @filenum)[-1];
}
$highest = (sort { $a <=> $b } @filenum)[-1];
$final = $highest + $number;
print "CUX00" . "$final" . ".txt\n";