CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
To print the file in spool with the new format of input file also

 



skr302
Novice

Oct 14, 2015, 6:20 AM

Post #1 of 9 (10038 views)
To print the file in spool with the new format of input file also Can't Post

Hi,

I am totally new to Perl and this is my first post.

Currently i have a perl script which takes the files with a fixed format and prints it to restricted spools.

If the file name is not standard then it sends them to Unhandled folder.

Also, it uses the filename to determine the folder they go to.

Currenty it will process a sample file which is in standard format like:
ISSU------__DCR2?DC???_YYYYMMDD_HHMMSS_USER-ID---_nnnnnnnn.???
ISSU------__??????????_YYYYMMDD_HHMMSS_USER-ID---_nnnnnnnn.???

ISSU------ denotes - 4 character Issuer code

and the output .DAT and .RPT file will be generated in a particular folder like below:
ABC-_DCR2FDCGBP_20151014_093010_ABCFBTEST3_00000000.DAT
ABC-_DCR2FDCGBP_20151014_093010_ABCFBTEST3_00000000.RPT

Now, the requirement is to modify the perl script to take the file of the below format also in addition with the existing format:

ISSU------__CQB???_YYMMDD_HHMMSS_---.???
Name of a sample file:
ABC-_BOANZD_151013034247_589.TXT

Format is like:
==================
Issuer code - 4 characters
Underscore
Bank id - Always CQB ( 3 characters)
Currency code - for example AUD, NZD etc for autralian dollar, new zealand dollar etc
Underscore
Date - in YYMMDD format - 6 digit date
Time - in hhmmss format - 6 digit time
Underscore
File counter - 3 digits file counter or sequence
Dot
Extension - 3 digit (it should be TXT)

Can some please send me the modified code. I am attaching the current code


(This post was edited by skr302 on Oct 14, 2015, 6:42 AM)
Attachments: sample.pl.txt (9.44 KB)


FishMonger
Veteran / Moderator

Oct 14, 2015, 7:00 AM

Post #2 of 9 (10022 views)
Re: [skr302] To print the file in spool with the new format of input file also [In reply to] Can't Post

Sorry, this is not a free code writing service.

Since you're totally new to perl, you obviously didn't write that script, which is very poorly written. That's as polite as I can put it because I don't want to say what I really think about it.

That script should be thrown out and rewritten from scratch. If you want to learn perl, we will be happy to help you, otherwise it might be best for you to hire a programmer to write a replacement script.


skr302
Novice

Oct 14, 2015, 7:09 AM

Post #3 of 9 (10019 views)
Re: [FishMonger] To print the file in spool with the new format of input file also [In reply to] Can't Post

Hi Fishmonger,

As i told i am completely new to Perl. I have seen few topics in this forum and tried to learn it.

I did not learn anywhere apart from this place as i liked this forum.

It is an urgent requirement so please help me or give me some idea on how to approach as i am not aware on how perl works exactly.

I have not written even a sinle perl script in my life.


(This post was edited by skr302 on Oct 14, 2015, 7:16 AM)


FishMonger
Veteran / Moderator

Oct 14, 2015, 7:21 AM

Post #4 of 9 (10012 views)
Re: [skr302] To print the file in spool with the new format of input file also [In reply to] Can't Post

Does your employer know that you don't know anything about perl or were they lead to believe that you are a perl programmer?

Can you contact the person that wrote that script?

That script is too poorly written for me to be willing to adjust it.


skr302
Novice

Oct 14, 2015, 7:35 AM

Post #5 of 9 (10010 views)
Re: [FishMonger] To print the file in spool with the new format of input file also [In reply to] Can't Post

Actually i am a microfocus cobol guy and our program process the input text file and keeps it in a particular location from where the perl script runs and prints it to spool.

I am only aware of cobol(Mainframe) and not aware on perl, since this is only one time change so no one is exclusively hired for this task and I have to learn it and do it but i tried and it looks confusing to me at first stage.


(This post was edited by skr302 on Oct 14, 2015, 7:36 AM)


skr302
Novice

Oct 14, 2015, 9:39 PM

Post #6 of 9 (9986 views)
Re: [skr302] To print the file in spool with the new format of input file also [In reply to] Can't Post

Anyone who can help me on this please


skr302
Novice

Oct 14, 2015, 10:03 PM

Post #7 of 9 (9982 views)
Re: [skr302] To print the file in spool with the new format of input file also [In reply to] Can't Post

Can some one please explain me what is happening here?

Code
# 
# Care needs to be taken as the full file name (containing the path) is
# 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, $delimiter, $basename, $dupe_extn) == 0) {
abort __LINE__,"bad filename '$filename', moved to unhandled directory";
}
else {
abort __LINE__,"failed to move unhandled file '$filename'!";
}
}
else {
#
# File Name Format Fits
#
($issuercode, $outputname, $date, $time, $userid, $sequenceno, $filetype) =
($1, $2, $3, $4, $5, $6, $7);
}


what unless ($basename= .............is doing?


(This post was edited by FishMonger on Oct 15, 2015, 6:29 AM)


FishMonger
Veteran / Moderator

Oct 15, 2015, 6:23 AM

Post #8 of 9 (9964 views)
Re: [skr302] To print the file in spool with the new format of input file also [In reply to] Can't Post

Others on your cross post thread on perlmonks have given broad explanations on what that section of code is doing. Here's a more detailed explanation of the regex in that unless ($basename =~ ....) statement.


Code
(?-imsx:/^(.{4}|.{10})_(.{10})_(.{8})_(.{6})_(.{10})_(.{8})\.(.{3})(\.gz)?$/) 

matches as follows:

NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
/ '/'
----------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
.{4} any character except \n (4 times)
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
.{10} any character except \n (10 times)
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
_ '_'
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
.{10} any character except \n (10 times)
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
_ '_'
----------------------------------------------------------------------
( group and capture to \3:
----------------------------------------------------------------------
.{8} any character except \n (8 times)
----------------------------------------------------------------------
) end of \3
----------------------------------------------------------------------
_ '_'
----------------------------------------------------------------------
( group and capture to \4:
----------------------------------------------------------------------
.{6} any character except \n (6 times)
----------------------------------------------------------------------
) end of \4
----------------------------------------------------------------------
_ '_'
----------------------------------------------------------------------
( group and capture to \5:
----------------------------------------------------------------------
.{10} any character except \n (10 times)
----------------------------------------------------------------------
) end of \5
----------------------------------------------------------------------
_ '_'
----------------------------------------------------------------------
( group and capture to \6:
----------------------------------------------------------------------
.{8} any character except \n (8 times)
----------------------------------------------------------------------
) end of \6
----------------------------------------------------------------------
\. '.'
----------------------------------------------------------------------
( group and capture to \7:
----------------------------------------------------------------------
.{3} any character except \n (3 times)
----------------------------------------------------------------------
) end of \7
----------------------------------------------------------------------
( group and capture to \8 (optional
(matching the most amount possible)):
----------------------------------------------------------------------
\. '.'
----------------------------------------------------------------------
gz 'gz'
----------------------------------------------------------------------
)? end of \8 (NOTE: because you are using a
quantifier on this capture, only the LAST
repetition of the captured pattern will be
stored in \8)
----------------------------------------------------------------------
$ before an optional \n, and the end of the
string
----------------------------------------------------------------------
/ '/'
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------



(This post was edited by FishMonger on Oct 15, 2015, 6:23 AM)


Laurent_R
Veteran / Moderator

Oct 15, 2015, 8:36 AM

Post #9 of 9 (9957 views)
Re: [skr302] To print the file in spool with the new format of input file also [In reply to] Can't Post

If you're totally new to Perl, perhaps you should not post in the "'Advanced" section of this forum, but rather in the "Beginners' section.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives