Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Read and Create File

by AnomalousMonk (Archbishop)
on Jun 28, 2021 at 14:30 UTC ( [id://11134397]=note: print w/replies, xml ) Need Help??


in reply to Re: Read and Create File
in thread Read and Create File

An excess of caution would suggest adding a defined test to the while-loop conditional. This test is not added by default by the compiler in the case of a complex conditional expression like the do-block:
    while ( defined($_ = do { ... }) ) { ... }


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^3: Read and Create File
by BillKSmith (Monsignor) on Jun 28, 2021 at 20:20 UTC
    Yes, good practice does require the 'defined'. In this application, I am already assuming the format of a 'block'. The special case (block is defined, but evaluates to FALSE), which requires 'defined', should never happen.
    Bill
Re^3: Read and Create File
by szpt9m (Novice) on Jun 30, 2021 at 16:05 UTC
    Hello, Thanks a lot for your response and is working fine for the fixed format given before. Now I have a situation where I may get somehting like this
    &LOG &LOG TEXT: "C:\temp\xyz.txt" &LOG Action: DEFAULT &LOG Naming_Technique: DEFAULT_NAMING Default_Name: @ST/ABC1234/00001 &LOG Container: "current:entity" &LOG Type: SIMILAR &LOG Name: ABC-Y &LOG Description: ABC-Z &LOG Associated_Files_Directory: "" &LOG &LOG TEXT: "C:\temp\PQR.txt" &LOG Naming_Technique: USER_NAME Default_Name: @ST/ABC9999/00001 &LOG &LOG &LOG TEXT: "C:\temp\abc.txt" &LOG Action: DEFAULT &LOG Naming_Technique: DEFAULT_NAMING Default_Name: @ST/ABC5678/00001 &LOG Container: "current:entity" &LOG Type: SIMILAR &LOG Name: EWQ-Y &LOG Description: EWQ-Z &LOG Associated_Files_Directory: "" &LOG &LOG TEXT: "C:\temp\rtq.txt" &LOG Action: DEFAULT &LOG Naming_Technique: DEFAULT_NAMING Default_Name: @ST/ABC2345/00002 &LOG Container: "current:entity" &LOG Type: SIMILAR &LOG Name: ERD-Y &LOG Description: ERD-Z &LOG Associated_Files_Directory: "" &LOG
    Here I do not want PQR.txt and its number ABC9999 in the output. Difference here is that, whenever I have USERNAME after Naming_Technique, i should avoid its .txt and number in the output. So my output remains same as before
    [xyz.txt] db_part_no=ABC1234 db_part_rev=00001 [abc.txt] db_part_no=ABC5678 db_part_rev=00001 [rtq.txt] db_part_no=ABC2345 db_part_rev=00002
    could you please help?

      Ahh, changing requirements in the middle of a contract - usually this requires a negotiation for more money :)

      #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11134376 use warnings; { local $/ = 'Associated_Files_Directory:'; while( <DATA> ) { /TEXT:.*?([.\w]+)".*Naming_Technique:.*?(\w+).(\w+)\n/s and print $. > 1 && "\n", <<END; [$1] db_part_no=$2 db_part_rev=$3 END } } __DATA__ &LOG &LOG TEXT: "C:\temp\xyz.txt" &LOG Action: DEFAULT &LOG Naming_Technique: DEFAULT_NAMING Default_Name: @ST/ABC1234/00001 &LOG Container: "current:entity" &LOG Type: SIMILAR &LOG Name: ABC-Y &LOG Description: ABC-Z &LOG Associated_Files_Directory: "" &LOG &LOG Part: "C:\temp\PQR.txt" &LOG Naming_Technique: USER_NAME Default_Name: @ST/ABC9999/00001 &LOG &LOG &LOG TEXT: "C:\temp\abc.txt" &LOG Action: DEFAULT &LOG Naming_Technique: DEFAULT_NAMING Default_Name: @ST/ABC5678/00001 &LOG Container: "current:entity" &LOG Type: SIMILAR &LOG Name: EWQ-Y &LOG Description: EWQ-Z &LOG Associated_Files_Directory: "" &LOG &LOG TEXT: "C:\temp\rtq.txt" &LOG Action: DEFAULT &LOG Naming_Technique: DEFAULT_NAMING Default_Name: @ST/ABC2345/00002 &LOG Container: "current:entity" &LOG Type: SIMILAR &LOG Name: ERD-Y &LOG Description: ERD-Z &LOG Associated_Files_Directory: "" &LOG

      Outputs:

      [xyz.txt] db_part_no=ABC1234 db_part_rev=00001 [abc.txt] db_part_no=ABC5678 db_part_rev=00001 [rtq.txt] db_part_no=ABC2345 db_part_rev=00002
      could you please help?

      Sure. Which part are you having problems with?


      🦛

      I am sorry my mistake. Now I correct the input file.. The one with PQR.txt also starts with TEXT and not Part.
        #!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11134376 use warnings; { local $/ = 'Associated_Files_Directory:'; while( <DATA> ) { /.*TEXT:.*?([.\w]+)".*Naming_Technique:.*?(\w+).(\w+)\n/s and print $. > 1 && "\n", <<END; [$1] db_part_no=$2 db_part_rev=$3 END } } __DATA__ &LOG &LOG TEXT: "C:\temp\xyz.txt" &LOG Action: DEFAULT &LOG Naming_Technique: DEFAULT_NAMING Default_Name: @ST/ABC1234/00001 &LOG Container: "current:entity" &LOG Type: SIMILAR &LOG Name: ABC-Y &LOG Description: ABC-Z &LOG Associated_Files_Directory: "" &LOG &LOG TEXT: "C:\temp\PQR.txt" &LOG Naming_Technique: USER_NAME Default_Name: @ST/ABC9999/00001 &LOG &LOG &LOG TEXT: "C:\temp\abc.txt" &LOG Action: DEFAULT &LOG Naming_Technique: DEFAULT_NAMING Default_Name: @ST/ABC5678/00001 &LOG Container: "current:entity" &LOG Type: SIMILAR &LOG Name: EWQ-Y &LOG Description: EWQ-Z &LOG Associated_Files_Directory: "" &LOG &LOG TEXT: "C:\temp\rtq.txt" &LOG Action: DEFAULT &LOG Naming_Technique: DEFAULT_NAMING Default_Name: @ST/ABC2345/00002 &LOG Container: "current:entity" &LOG Type: SIMILAR &LOG Name: ERD-Y &LOG Description: ERD-Z &LOG Associated_Files_Directory: "" &LOG

        Outputs:

        [xyz.txt] db_part_no=ABC1234 db_part_rev=00001 [abc.txt] db_part_no=ABC5678 db_part_rev=00001 [rtq.txt] db_part_no=ABC2345 db_part_rev=00002

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11134397]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-25 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found