Convert UNIX to perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert UNIX to perl
# 1  
Old 11-21-2012
Convert UNIX to perl

Hi,

Can someone convert the code into perl ?

Code:
x=(a b c)
y=(d e)
times=$((${#x[*]} * ${#y[*]}))
((xi=yi=0))
for((i=1;i<=times;i++,xi++,yi++))
do
 if((xi>${#x[*]}-1));then xi=0;fi
 if((yi>${#y[*]}-1));then yi=0;fi
 print ${x[$xi]},${y[$yi]}
done

# 2  
Old 11-21-2012
What will this code do??
# 3  
Old 11-21-2012
Code:
x=(a b c)
y=(d e)

The code would print
Code:
a,d
b,e
c,d
a,e
b,d
c,e


Last edited by Franklin52; 11-21-2012 at 03:19 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 11-21-2012
Hi

Code:
#!/usr/bin/perl
use strict;
use warnings;

$\="\n";

my @x=qw(a b c);
my @y=qw(d e);
my ($a,$b);
$a=$b=0;

for(my $i=0;$i<@x*@y; $i++){
        print "$x[$a++],$y[$b++]";
        $a=0 if ($a==@x);
        $b=0 if ($b==@y);
}

Guru.
# 5  
Old 11-21-2012
Hi Thanks,

Can it be done with for each ??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl to shell convert

HI All, I am new in shell scripting ,can any one please help me to convert this scripts from Perl to Shell. Thank in advance. $customer=$ARGV; $rows=`hadoop fs -ls /ncip/$customer/|wc -l`; if($rows==3){ print "$customer directory exists , cleaning up ! \n"; `hadoop fs -rm... (1 Reply)
Discussion started by: Atul301
1 Replies

2. Shell Programming and Scripting

UNIX/PERL script to convert XML file to pipe delimited format

Hello, I need to get few values from a XML file and output needs to be written in another file with pipe delimited format. The Header & Footer of the Pipe Delimited file will be constant. The below is my sample XML file. I need to pull the values in between the XML tags <Operator_info to... (15 Replies)
Discussion started by: karthi1305561
15 Replies

3. UNIX for Advanced & Expert Users

Convert CSV file to nested XML file using UNIX/PERL?

we have a CSV which i need to convert to XML using Perl or Unix shell scripting. I was able to build this XML in oracle database. However, SQL/XML query is running for long time. Hence, I'm considering to write a Perl or shell script to generate this XML file. Basically need to build this XML... (3 Replies)
Discussion started by: laknar
3 Replies

4. Shell Programming and Scripting

UNIX or Perl script to convert JSON to CSV

Is there a Unix or Perl script that converts JSON files to CSV or tab delimited format? We are running AIX 6.1. Thanks in advance! (1 Reply)
Discussion started by: warpmail
1 Replies

5. Shell Programming and Scripting

Convert perl to shell

Hi I am a novice in scripting .Please help me converting perl script into shell my ($ref) = shift; my $id; my $cnt=0; my $first =0; my $filename ; my $filename1 ; FOREACH:foreach my $r (qw(RET LSH PDM )) { $ref->{$cnt}->{num_errors} =0; $ref->{$cnt}->{num_warnings} =0;... (2 Replies)
Discussion started by: apassi
2 Replies

6. Shell Programming and Scripting

perl to shell convert

#!/usr/bin/perl #************************************************************** # # PERL SCRIPT # This script restarts the Application # # ##************************************************************** $ENV{'IFS'} = ' '; #open(STDERR,">&STDOUT"); #select... (2 Replies)
Discussion started by: srikoundinya
2 Replies

7. Shell Programming and Scripting

Convert to Hex in perl

Hi, i want to convert number 5860533159 to hexadecimal. i need to use perl. i used $foo = 5860533159; $hexval3 = sprintf("%#x", $foo); i am getting value as 0xffffffff. i need to get value as 0x15D50A3A7. when i converted using google calculator, i got the correct value, expected... (9 Replies)
Discussion started by: asak
9 Replies

8. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

9. Shell Programming and Scripting

convert unix script to perl

Hi, I have these lines in a unix script: FILEONE = /<filepath1>/<filename1.txt> FILENEW = /<filepath2>/<filename2.txt> head -5 $FILEONE | sed '1d' > $FILENEW PARAM1 = `cat $FILENEW | awk '{print $2;}' ` echo "Param1 Value: $PARAM1" What's the correct syntax of the above lines if same... (2 Replies)
Discussion started by: gholdbhurg
2 Replies

10. Shell Programming and Scripting

awk to perl convert

Dear Collegue Do anybody help me to convert this AWK script to Perl script { for (i = 2; i <= length ($0); i++) { x = substr($0, i , 1) if (c > 0) { b = b x if (x == "(") c++ ... (2 Replies)
Discussion started by: jaganadh
2 Replies
Login or Register to Ask a Question