I am porting a csh script to Perl. I am doing a switch statement in Perl. I am not sure if this is right, based on the different comments that switch statements are no longer in use in Perl. Can you please give me an idea if this is right? Also in switch statement do we use 'when' or 'case'?
This is the csh code:
set machine = c16991
set pgMachine = lc0140
if ( ! -e /abc/site/home/$USER/.userauthentication) then
echo "-F- .userauthentication file must be created in /abc/site/home/$USER "
echo "-I- .userauthentication file format: <emailaddress> <unix pwd>.
echo "-I- Please make sure /abc/site/home/$USER/.userauthentication permission is set to 000"
exit
endif
set permissionCheck = `ls -ltra /abc/site/home/$USER/.userauthentication | awk '{print $1}' |
if ($permissionCheck != 'DASHrwDASHDASHDASHDASHDASHDASHDASH') then
echo "-F- /abc/site/home/$USER/.userauthentication permission is set to $permission1"
exit
endif
@ i = 1
while ($i <= $#argv)
switch ($argv[$i])
case -block:
shift
set DBB1 = $argv[$i]
shift
breaksw
case -tag:
shift
set tag = $argv[$i]
shift
breaksw
case -local:
shift
set local = $argv[$i]
shift
breaksw
case -ar:
shift
set arType = $argv[$i]
shift
breaksw
default:
echo "-E- Invalid switch -> {$argv[$i]} found!"
goto usage
exit
endsw
end
if ($local == 'y') then
if ($tag == "")then
echo "-F- Please enter tag value to proceed!"
exit
endif
endif
set DBB1 = $DBB
### grab data locally
set shipLogFile = "$WARD/ship/log/${DBB1}.ship.log"
set shipUsername = `grep "Username:" $shipLogFile | sed 's/.*Username: //' | sed 's/;.*//'`
set reviewCloseFile = "$WARD/ship/ip/${DBB1}/swizzled/review/${DBB1}.close"
set accept10SumFile = "$WARD/ship/ip/${DBB1}/swizzled/pds/logs/${DBB1}.ccdo_accept10.iss.log.sum"
set shipDate = `zgrep "::RUNTIME:: SHIP end time/date:" $shipLogFile | sed 's/.*time\/date\://g' | sed 's#"##g'`
else
###grab data from archive [DEFAULT]
if ($shipTag == "") then
if ($DBB1 == "") then
# grab DEFAULT hip value from running WARD, $DBB
set DBB1 = $DBB
endif
# grab DEFAULT ship tag value for archive from the latest tag
set shipTag = `ls -t $PROJ_ARCHIVE/noa/${DBB1}/ip_handoff_noa | grep "^$STEPPING" | grep RTL | grep -v RTL0 | grep -v "_TEMP" | head -n 1`
else
if ($DBB1 == "") then
# grab DEFAULT hip value from running WARD, $DBB
set DBB1 = $DBB
endif
endif
set shipUsername = `zgrep "User Name:" $PROJ_ARCHIVE/noa/${DBB1}/ip_handoff_noa/$shipTag/${DBB1}.ip_handoff_noa.manifes t.gz | sed 's/.*\.//g' | sed 's/^ \+\| \+$//g'`
set shipLogFile = "$PROJ_ARCHIVE/noa/${DBB1}/ship_noa/${shipTag}/ship/log/${DBB1}.ship.log"
set reviewCloseFile = "$PROJ_ARCHIVE/noa/${DBB1}/iphandoff_review_noa/${shipTag}/review/${DBB1}.close. gz"
set accept10SumFile = "$PROJ_ARCHIVE/noa/${DBB1}/ipqa_noa/${shipTag}/pds/logs/${DBB1}.ccdo_accept10.is s.log.sum.gz"
set shipDate = `zgrep "Current Date:" $PROJ_ARCHIVE/noa/${DBB1}/ship_noa/${shipTag}/${DBB1}.ship_noa.manifest.gz | sed 's/.*\. //g'`
endif
### create /tmp/transpose_$$.pl script
touch /tmp/transpose_$$.pl; rm /tmp/transpose_$$.pl
echo '#\!/usr/intel/pkgs/perl/5.8.5/bin/perl -w' >> /tmp/transpose_$$.pl
echo 'use strict;' >> /tmp/transpose_$$.pl
echo 'use English;' >> /tmp/transpose_$$.pl
echo '(our $PROG_NAME = $0) =~ s#^.*/##;' >> /tmp/transpose_$$.pl
echo 'my $file = shift;' >> /tmp/transpose_$$.pl
echo 'open (FILE, $file) or die "***E: Error opening $file for reading: $!\n";' >> /tmp/transpose_$$.pl
echo 'my @lines;' >> /tmp/transpose_$$.pl
echo 'while (<FILE>){' >> /tmp/transpose_$$.pl
echo ' chomp $_;' >> /tmp/transpose_$$.pl
echo ' push (@lines, $_);' >> /tmp/transpose_$$.pl
echo '}' >> /tmp/transpose_$$.pl
echo 'print "@lines";' >> /tmp/transpose_$$.pl
echo 'print "\n";' >> /tmp/transpose_$$.pl
echo '1;' >> /tmp/transpose_$$.pl
chmod 740 /tmp/transpose_$$.pl
This is the Perl code:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper; ##print Dumper()
use feature qw(switch);
my $machine = c16991;
my $pgMachine =lc0140;
if ( ! -e /abc/site/home/$USER/.userauthentication)
system (echo "-F- .userauthentication file must be created in /abc/site/home/$USER" )
system (echo "-I- .userauthentication file format: <emailaddress> <unix pwd>.")
system (echo "-I- Please make sure /abc/site/home/$USER/.userauthentication permission is set to 000")
exit
endif
my $permissionCheck = `ls -ltra /nfs/site/home/$USER/.userauthentication | awk '{print $1}'
if ($permissionCheck != 'DASHrwDASHDASHDASHDASHDASHDASHDASH')
system(echo "-F- /abc/site/home/$USER/.userauthentication permission is set to $permission1")
exit
endif
@ i = 1
given ($i <= $#argv)
switch ($argv[$i])
when(block):
return $argv[$i]
when(tag):
return $argv[$i]
when (local):
return $argv[$i]
when (ar):
return $argv[$i]
default:
system(echo "-E- Invalid switch -> {$argv[$i]} found!")
goto usage
exit
endsw
end