Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Not able to capture information

by oko1 (Deacon)
on Feb 17, 2012 at 07:52 UTC ( #954431=note: print w/ replies, xml ) Need Help??


in reply to Re: Not able to capture information
in thread Not able to capture information

My 2 cents on your 2 cents: validating user input is very simple. Never try to "enumerate badness"; just define what is valid and reject everything else.

my $in; { print "Input 'foo': "; chomp($in=<STDIN>); redo unless /^foo$/; }
-- 
I hate storms, but calms undermine my spirits.
 -- Bernard Moitessier, "The Long Way"


Comment on Re^2: Not able to capture information
Download Code
Re^3: Not able to capture information
by Marshall (Prior) on Feb 17, 2012 at 09:02 UTC
    I don't think that we need to get into a big discussion in the context of this thread.

    Part of what I'm saying is that with:
    [2012/02/16 00:08:34] [29] ERRORMSG unknown error

    There is no reason or need to parse the date time format with some huge regex eg:
     m/\[(\d{4}\/\d{2}\/\d{2}\s+\d{2}\:\d{2}\:\d{2})\]\s+\[(\d{1,3})\]

    If the line begins with "[" it is a date/time and there is no reason to parse or otherwise try to understand it. Maybe this changes to YYYY-MM-DD or YYYY.MM.DD instead of YYYY/MM/DD? In the context of this re-formatting program, it shouldn't matter.

    Basically, if a complex regex is not essential to the program operation, don't even do that. Here all that is needed is to understand that the square brackets on the first part of a line signifies a "new record". Past that, the parser shouldn't care about the format between the square brackets, because it doesn't need to do that in order to do its job!

    Maybe we are actually in agreement here?
    ^[...] starts a new "message line" and that is all we need to know - that is considered "valid input" no matter what is between the [...].

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2014-10-01 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (31 votes), past polls