podian has asked for the wisdom of the Perl Monks concerning the following question:
First one prints this:#test 1 $s ="This is a test"; $d =" "; print "--- output 1 --- \n"; @ar = split($d, $s); foreach $i (@ar) { print "|$i| \n"; } #test 2 #how come this one prints differently? print "--- output 2 --- \n"; @ar = split(" ", $s); foreach $i (@ar) { print "|$i| \n"; }
I think this is the correct behavior. But the second one prints like this(when delimiter is used directly):--- output 1 --- |this| || || |is| || || |a| || || || |test|
I am using perl 5.8.5 on linux. Thanks a lot!--- output 2 --- |this| |is| |a| |test|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Interesting issues with split function
by dragonchild (Archbishop) on Dec 03, 2004 at 17:31 UTC | |
|
Re: Interesting issues with split function
by BrowserUk (Patriarch) on Dec 03, 2004 at 17:31 UTC | |
by ysth (Canon) on Dec 03, 2004 at 18:12 UTC | |
|
Re: Interesting issues with split function
by Joost (Canon) on Dec 03, 2004 at 17:38 UTC | |
|
Re: Interesting issues with split function
by ikegami (Patriarch) on Dec 03, 2004 at 18:11 UTC |