HI
This is just another perl newbie here.Thanks every1 for replying to my question about merging files.
.Phew! i really do have a long way to go. Anyway i was going through some C exercises i had done previously and i came across an interesting
exercise. You have to write a program to produce
the following output
Well, um i wrote the code , but since er i just baby talk perl,
the code is very big i just know that there
is a more better and more intelligent way to do it
.I will really appreciate your help perl monks if you kindly
SHOW A BETTER WAY TO DO IT
THANKS
ankur
ABCDEFGFEDCBA
ABCDEF FEDCBA
ABCDE EDCBA
ABCD DCBA
ABC CBA
AB BA
A A
<CODE>
#!/usr/bin/perl -w
@store=('a'..'g');
$i=@store;
$count=0;
while($i>=0){
&printline($i-1,@store);
&revline($i-1,$count,@store); $count++;
pop(@store);
}
sub printline{
($itemp,@printarray)=@_;
for($j=0;$j<=$itemp;$j++){
print "$printarray[$j]";
}
}
sub revline{
($it,$cou,@linarray)=@_;
if ($cou==0){
for($k=$it;$k>=0;$k--){
print "$linarray[$k]";
}
print '/n';
return;
}
$p=$cou-1;
$r=2*$p + 1;
for ($j=1;$j<=$r;$j++){
print " ";
}
for($k=@linarray-1;$k>=0;$k--){
print "$store[$k]";
if ($k==0){
print '\n' ;
}
}
}
er i dont know formatting yet
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.