Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
#!/usr/bin/ksh
Str="Tom|Andy|Jacob|Sid|Pat"
OLDIFS=$IFS
IFS='|'
set -A myarray $Str
i=0
while (( i < ${#myarray[*]} ))
do
echo ${myarray[$i]}
(( i=i+1 ))
done
OFS=$OLDIFS
#!/usr/bin/perl -w
my $st="yxs|yud|abc|def|ghi";
# break down the string using a native command "split"
my @arr = split(/\|/,$st);
# count the array elements using basic perl functionality
my $count=@arr;
print "count: $count\n";
# loop over the array and print it, one item per line
foreach (@arr) {
print "$_\n";
}
split(/\|/,$st);
#!/usr/bin/perl
use strict; # always!
use warnings; # same as -w on shebang line
my $pipeString = 'yxs|yud|abc|def|ghi'; # (1)
my @names = split(/\|/, $pipeString); # (2)
print "count: ", scalar @names, "\n"; # (3)
print join("\n", @names); # (4)
Absolutely right. Shell scripting is the lowest common denominator. Sure, it's guaranteed to be on every system, which is why install scripts and the like are written in shell script. But just because flints and stone tools are available, it doesn't mean we have to use them. You can do anything in Perl that you can do in the shell, but more easily, so if you expect to be doing any amount of scripting, it is well worth taking the time to learn it.thedaver said:this is being made way too difficult by attempting it in shell scripting...
print 'Count: ', scalar s/\|/\n/g + 1, "\n", $_ while (<>);