Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://442644]
Discipulus dscivered BASH supports also double quotes..
choroba recommends ABSG to Discipulus
[erix]: yes, very handy that. I always use the one-page html version (dumped a local copy of it)
[erix]: (easier for searching)

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2017-11-24 11:52 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (348 votes). Check out past polls.