#!/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 = ; chomp(@data); foreach my $line(@data){ foreach my $pwd (split(/\|/, "$line")) { print $pwd,"\n"; }; }; print "hit any key to continue: "; my $ans = ; 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 = ; 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 separators 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 = ; 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 =; 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 #### | *foo | *foo1 | *foo2 | *foo4| *foo5 | *foo6