punch_card_don has asked for the wisdom of the Perl Monks concerning the following question:
Parsing a pipe-delimited text file, line by line.
When the line being parsed isopen(FILE, 'my_file.txt'); while ($line = <FILE>) { @line_parts = split(/\|/, $line); print "<br>$line_parts[0]\n"; } close(FILE);
the above code correctly outputs1.1.2|W|foo|abc
But if I replace the split delimiter with a variable, like this:1.1.2
it outputs$delimiter = "\|"; ..... @line_parts = split(/$delimiter/, $line);
I've tried various permutations like :1
to no avail.$delimiter = "|"; ..... @line_parts = split(/\$delimiter/, $line);
What's up?
Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Variable as split delimiter
by ysth (Canon) on Mar 26, 2008 at 15:47 UTC | |
by punch_card_don (Curate) on Mar 26, 2008 at 15:59 UTC | |
|
Re: Variable as split delimiter
by Not_a_Number (Prior) on Mar 26, 2008 at 15:58 UTC | |
|
Re: Variable as split delimiter
by jwkrahn (Abbot) on Mar 26, 2008 at 19:30 UTC |