0

I want to read a number of lines from a for loop and split them. After that i want to do a replace on A SINGLE array element.

my @fs = split(';', $line);
$fs[0] =~ s/\"//g;

This doesnt work however. The line

$fs[0] =~ s/\"//g;

returns a compiler error.

Is there a better way to do this?

3
  • 6
    Can you include the error, please? Commented Feb 26, 2013 at 14:56
  • 2
    That line has no errors, could yo have the whole code and the concrete error? Commented Feb 26, 2013 at 14:57
  • 5
    Never say "an error", like all errors are the same thing. That's about as useful as saying "a number", when referring to a specific telephone number. Commented Feb 26, 2013 at 15:19

1 Answer 1

1

Change the line with split to

my @fs = split(/;/, $line);

because split takes a regex as its first operand.

I suspect the parse error you are seeing is due to an error somewhere else because the syntax of the code in your question is correct.

In general, always fix the first error diagnosed by the parser. Good parsers try to recover so as to report as many errors as possible, but this process is not always reliable. What is the exact text of the error you are seeing?

Sign up to request clarification or add additional context in comments.

4 Comments

it's wrong. you can put string instead regex into split. but it always be regex
perldoc perlstyle: “Just because you CAN do something a particular way doesn't mean that you SHOULD do it that way.”
use strict and use warnings and also some idioms.
When i commented out the line of code, the script compiled as it should. It turned out that there was a windows-line-break in the line that was invisible until i opened it with VI. That is why that line was acting out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.