It's difficult to help when you don't tell us what the problem is. We only know that the code you've given us doesn't do what you want it to to - but you haven't told us what results you were expecting.

But my telepathy is strong this early in the morning and I think I've worked out what you want. You want to extract the three string values from each line of the data. You're looking for a lightweight CSV parser. Is that right?

If that's the case, then split might not be the best approach. I'd recommend using Text::ParseWords instead - it's a standard part of the Perl distribution.

#!/usr/bin/perl use strict; use warnings; use Text::ParseWords; my @data = <DATA>; foreach my $entry (@data) { my ($var1, $var2, $var3) = parse_line(',', 0, $entry); print "Var1: $var1\n"; print "Var2: $var2\n"; print "Var3: $var3\n"; } __DATA__ "value 1","something else","other stuff" "asdf123","omg","hope this works" "more tests","testy","blah"
--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg


In reply to Re: Help with Regex in Split by davorg
in thread Help with Regex in Split by jeiku

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.