Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: Regex Parsing

by toadi (Chaplain)
on Mar 27, 2005 at 17:04 UTC ( #442644=note: print w/ replies, xml ) Need Help??


in reply to Re: Regex Parsing
in thread Regex Parsing

Did not really have any code. Did not have a idea howto do it.
But after some more pondering:

my @array = (split/\n/, $data); my $firstmatch = $array[3]; my $secondmatch = $array[4];

But is this the best/fastes way. Got lots of files with this kind of data.

This happens over and over:

Open the file split the records parse this data insert it into db close file


--
My opinions may have changed,
but not the fact that I am right


Comment on Re^2: Regex Parsing
Select or Download Code
Re^3: Regex Parsing
by dragonchild (Archbishop) on Mar 28, 2005 at 13:55 UTC
    I think you have an excellent solution using split and array access. There is no reason to use a regex when other solutions will work equally well. Often, a regex will be more complicated or more fragile.

    Now, there are some parsing problems that are better solved with a regex, but this isn't one of them. And, personally, I only use a regex when I cannot use other solutions.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

      solution using split

      There is no reason to use a regex

      Technically speaking, a split uses a regex O:-)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (11)
As of 2015-07-06 19:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (81 votes), past polls