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:

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"; }
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!


In reply to Re: shellscript to Perl by eyepopslikeamosquito
in thread shellscript to Perl by kluther

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.