This thread helped me with a problem I was having. Thanks!

Here is the command line test script that I wrote to test out some options. It allows you to see what response occurs in your system.

This was tested under Xubuntu linux with a Terminator terminal. For my system I found a DIFFERENCE in behavior between a loaded test file with pipe symbol used as the separator and the pipe symbol being used in a test data line entered from the command line.

You can also experiment with other potential separators from the command line, but you will have to edit the script and a sample data file to experiment with various separators loaded from a file on disk. A sample |(pipe) separated test file follows the script.

save program as split-test.pl

#!/usr/bin/perl -w use strict; # no warnings 'uninitialized'; use English; use utf8; binmode(STDOUT, ":utf8"); print "Using | separated data file loaded from disk;\n | IS escaped in + split\n"; open(IN,"< testdata.csv") || die "cannot open testdata.csv"; my @data = <IN>; chomp(@data); foreach my $line(@data){ foreach my $pwd (split(/\|/, "$line")) { print $pwd,"\n"; }; }; print "hit any key to continue: "; my $ans = <STDIN>; print "Using | separated data file from disk; | NOT escaped in split\n"; foreach my $line(@data){ foreach my $pwd (split(/|/, "$line")) { print $pwd,"\n"; }; }; print "hit any key to continue: "; $ans = <STDIN>; print "following examples use | separated test string in script in \n different ways\n"; print"default separator | NOT escaped in default test string\n"; foreach my $pwd (split(/\|/, "| *foo | *foo1 | *foo2")) { print $pwd,"\n"; }; print"default separator | IS escaped in default test string\n"; foreach my $pwd (split(/\|/, "\| *foo \| *foo1 \| *foo2")) { print $pwd,"\n"; }; print "this section is a loop that allows you to try different separat +ors that you enter from command line\n"; print "you can experiment by using a character alone or proceeding the + character with an \ as an escape'\n for example, using | and then using \ |/.\n"; while(-1){ print "start of loop enter NEW separator: "; my $sep = <STDIN>; chomp($sep); print "separator IS escaped in split command:\n"; print "separator $sep is NOT escaped in split command:\n"; foreach my $pwd (split(/\\$sep/, "$sep *foo $sep *foo1 $sep *foo2")) { print $pwd,"\n"; }; print"\n\t ****\n\n"; print "test separator ($sep) on command line testline\n"; print "using $sep: paste testline here: "; my $testline =<STDIN>; chomp($testline); print "separator IS escaped in split command:\n"; my @testarray = split(/\\$sep/,$testline) ; foreach my $item(@testarray){ print "$item\n"; }; print "separator is NOT escaped in split command:\n"; @testarray = split(/"$sep"/,$testline) ; foreach my $item(@testarray){ print "$item\n"; }; }#endwhile

sample test file - save as "testdata.csv

| *foo | *foo1 | *foo2 | *foo4| *foo5 | *foo6

In reply to Re: A problem with using the split command by bdalzell
in thread A problem with using the split command by TASdvlper

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.