|
Hi ,
newbie here.
jus a snippet I was trying. I've been coding in ksh/bash, wondering bout the perl alternative.
@arr=(1,2,3);
I declare a variable which contains the value as :
$new=$arr[0]|$arr[1]|$arr[2];
print "$new\";==> $arr[0]|$arr[1]|$arr[2]
now I want to print the result of $new as the values of the original array,i.e. my print output should be like :
1|2|3.
Any suggestions?
Thanks ppl..
|
|
|
foreach(@arr)
{
print STDOUT "$_";
#unless we have reached the "3", add a | behind it.
if($_ =~ /3/){next;}
print STDOUT "|";
}
#was this helpful?
|
|
|
here , the code just prints the array with a "|".
I need something which would print the value of the variable $new, which would inturn print out values of the original array @arr.
Do I need to read the contents of new into an array through 'split' and then print the array ?
Thanks for the update..
|
|
|
@arr = (1,2,3);
#just shove that array into the variable...
foreach(@arr)
{
$new .= $_;
if($_ =~ /3/){next;}
$new .= "|";
}
#and then print it out.
print STDOUT "$new";
#otherwise i dont know.
|
|
|
|
|
|
|
// |