Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: help with splitting and printing the array

by pme (Monsignor)
on Jan 25, 2015 at 11:19 UTC ( [id://1114427]=note: print w/replies, xml ) Need Help??


in reply to Re^3: help with splitting and printing the array
in thread help with splitting and printing the array

Hi Luke,

It doesn't help, it is just a simpler solution. perlnewbie012215 says about 20 lines hence a simple solution might do the job as well.

BTW your code can be improved by checking the regexp match because it prints out the previous line if the pattern doesn't match:

if (/-S.+?($servname).+-D.+?($servname).+-C.+?($servname).+$/) { print "Server after -S: $1; Server after -D: $2; Server after -C: +$3;\n"; } else { print "Unknown record structure: $_\n"; }
Or the important command line switches could be checked one by one and add them to the output if they exist.

Replies are listed 'Best First'.
Re^5: help with splitting and printing the array
by blindluke (Hermit) on Jan 25, 2015 at 12:41 UTC

    If it doesn't help, then it's only simple, not a solution. You should not suggest a split / field index based method when it is clear that the field indexes and their order might easily change, due to the (known) nature of the input data. Especially since this potential problem has already been pointed out to the OP.

    As to error checking - it's not an 'improvement', it's a necessity. It's obvious that before the OP uses this in production code, he should check for possible error, both upon matching and upon opening his input file.

    - Luke

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-24 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found