![]() |
|
Do you know where your variables are? | |
PerlMonks |
Re: Str extract the word between the first and the 2nd '|' characterby radiantmatrix (Parson) |
on Apr 11, 2008 at 16:41 UTC ( [id://679755]=note: print w/replies, xml ) | Need Help?? |
Well, the regex and split will certainly work. I'd like to provide two more options for you. The first uses index and substr. This has the advantage of being very fast (often faster than regex -- regexes can do more, though). I don't know if it's faster than split (probably not), but there may be reasons for you to use it.
The second suggestion I have is a bit more robust, and leverages the module Text::CSV_XS. You'd use this approach if you have, e.g. a file of lines that look like your example -- and especially if you're interested in more than one field in that line, and/or if your data might have escaped pipes in it.
Even if your data isn't in a file, Text::CSV_XS can parse it for you; it's worth looking into.
<–radiant.matrix–>
Ramblings and references The Code that can be seen is not the true Code I haven't found a problem yet that can't be solved by a well-placed trebuchet
In Section
Seekers of Perl Wisdom
|
|