in reply to Re: To print the file in spool with the new format of input file also
in thread To print the file in spool with the new format of input file also

Hi, I am new to PErl. Can you please modify this script and update if you dont mind. Actually i have not written even a single perl script.
  • Comment on Re^2: To print the file in spool with the new format of input file also

Replies are listed 'Best First'.
Re^3: To print the file in spool with the new format of input file also
by GotToBTru (Prior) on Oct 15, 2015 at 12:44 UTC
    Actually i have not written even a single perl script.

    So said every monk ever. There's always a first time!

    Dum Spiro Spero
Re^3: To print the file in spool with the new format of input file also
by skr302 (Initiate) on Oct 15, 2015 at 05:02 UTC
    Can some one please explain me what is happening here?
    # # Care needs to be taken as the full file name (containing the path) i +s # sent to the RPM server. # # Validate Filename Structure unless ($basename =~ /^(.{4}|.{10})_(.{10})_(.{8})_(.{6})_(.{10})_(.{8 +})\.(.{3})(\.gz)?$/) { if ((system @COPY, $filename, sprintf "%s%s%s%s", $UNHANDLED, $del +imiter, $basename, $dupe_extn) == 0) { abort __LINE__,"bad filename '$filename', moved to unhandled d +irectory"; } else { abort __LINE__,"failed to move unhandled file '$filename'!"; } } else { # # File Name Format Fits # ($issuercode, $outputname, $date, $time, $userid, $sequenceno, $fi +letype) = ($1, $2, $3, $4, $5, $6, $7); }
    what is unless ($basename= .............is doing?

      Here's some explanatations and links (the useful kind, I hope):

      • unless is a negated if. Just like if executes certain code if a condition is true, unless executes it if it is not - that is to say, it executes the code unless the condition is true. See Compound Statements for more.

      • =~ is the regular expression binding operator. With a "regular" regular expression (rather than a substitution or transliteration), it matches a variable ($basename) against a regular expression. If you're not familiar with regular expressions, think of it as a pattern describing what the contents of $basename should look like. See perlop.html#Binding-Operators for more on the =~ operator, and perlretut and perlre for more on regular expressions.

      If you're new to Perl, there's a number of helpful books as well, e.g. Learning Perl and Beginning Perl; I also highly recommend Programming Perl, affectionally known as "The Camel". (There's many more books, but they're not necessarily well-suited for beginners.)

      unless ($basename =~ /^(.{4}|.{10})_(.{10})_(.{8})_(.{6})_(.{10})_(.{8 +})\.(.{3})(\.gz)?$/) { # ...
      If the base name does not match the pattern, then abort with either of the two messages, depending on the condition on the next code line. If it does match, do what's in the else instruction.

      It is equivalent (and usually slightly clearer) to turn the instructions around:

      # Validate Filename Structure if ($basename =~ /^(.{4}|.{10})_(.{10})_(.{8})_(.{6})_(.{10})_(.{8})\. +(.{3})(\.gz)?$/) { # # File Name Format Fits # ($issuercode, $outputname, $date, $time, $userid, $sequenceno, $fi +letype) = ($1, $2, $3, $4, $5, $6, $7); } else { if ((system @COPY, $filename, sprintf "%s%s%s%s", $UNHANDLED, $del +imiter, $basename, $dupe_extn) == 0) { abort __LINE__,"bad filename '$filename', moved to unhandled d +irectory"; } else { abort __LINE__,"failed to move unhandled file '$filename'!"; } }

      In addition to what has been said: the "(" and ")" characters create so-called "groups", and the first group is assigned to $1, the second to $2, and so on. See perlre, especially the section on Capture groups.

      For more "basic" information you might want to look into perlintro (which is part of perl's "official" doc), or http://learn.perl.org or http://perl-begin.org

      BTW if you have perl on your computer, you can get at perl's documentation via perldoc, e.g.
      perldoc perlintro