in reply to Re^2: Extract data from CSV field.
in thread Extract data from CSV field.

This snippet correctly identifies the section of the CSV I want to extract. But I am doing perl wrong. I keep getting a "true" or "1" in my test output.

my $var = $row->[5] =~ /(#[^ ]+)/;

I can do a replace with this code and overwrite the data I want to keep, I would bet I could use the "not" operator and replace only the other data, but I haven't tried it, and that may not be desirable for reporting purposes later on. How do I assign this "found" value to a new field in the modified dataset? I think I am missing something in my understanding of the syntax.

Replies are listed 'Best First'.
Re^4: Extract data from CSV field.
by MidLifeXis (Monsignor) on Dec 09, 2015 at 18:15 UTC

    To further expand on poj's response, this is a case of calling context. You called the match (and capture) in scalar context, so the pattern match returned the number of matches (which would be at most 1, since you didn't use the g modifier on your RE). poj's addition of the parenthesis around the variable assignment changes the context to 'array context'. The results of a capture in scalar context return the number of matches, and in array context return the matches themselves.

    --MidLifeXis

Re^4: Extract data from CSV field.
by poj (Abbot) on Dec 09, 2015 at 17:51 UTC
    my ($var) = $row->[5] =~ /(#[^ ]+)/ ;
    poj