Also, note that shell backticks remove the trailing newline, while Perl backticks preserve it.
Given you are just starting with Perl, it is a good idea to sprinkle print statements and error checks in your script to help you understand what is going on. To get you started, try this:
Study the script above, referring to the Perl documentation, and you should be on your way to rewriting your old shell scripts in Perl. As for learning Perl, take a look at learn.perl.org and Perl Tutorial Hub. Good luck!use strict; use warnings; my $cmd = '/usr/well561/bin/well.newlogfile'; -f $cmd or die "error: '$cmd' not found"; -x $cmd or die "error: '$cmd' not executable"; my $out = `$cmd 1`; my $rc = $? >> 8; print "command exit code is $rc\n"; $rc == 0 or warn "warning: command returned $rc\n"; chomp $out; # remove trailing new line from command output print "command output:$out:\n"; if ($out eq 'Y') { print "command returned Y\n"; }
In reply to Re: shellscript to Perl
by eyepopslikeamosquito
in thread shellscript to Perl
by kluther
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |