geniuskid has asked for the wisdom of the Perl Monks concerning the following question:

Sub Target_write_wide(depth As Integer) 'Debug.Print "Target write depth = "; depth; "Targetvalues" & TargetV +alues(depth) Dim l As Integer Dim TargetValueslist() As String TargetValueslist = Split(TargetValues(depth), " ") For l = LBound(TargetValueslist) To UBound(TargetValueslist) If Not (TargetValueslist(l) = "") Then Celldata = "add_wide_split(" & Chr(34) & Targets(dept +h) & Chr(34) & "," & TargetValueslist(l) & ");" & vbLf Print #1, Celldata End If Next l If (depth > 0) Then Target_write_wide (depth - 1) Else Current_split = Current_split + 1 Num_combinations = Num_combinations + 1 Celldata = "run_all_wide_split(" & Chr(34) & testname & "_ +combination:" & Current_split & Chr(34) & ");" Print #1, Celldata End If End Sub

2019-02-05 Athanasius added code tags

Replies are listed 'Best First'.
Re: tO CONVERT vb SCRIPT TO PERL
by harangzsolt33 (Deacon) on Feb 05, 2019 at 06:03 UTC
    I think, this is what it would look like. I noticed that you seem to be printing to a file. In perl, if you write to a file, you need a file handle, which is usually a variable. And you need to pass that variable to the function OR it could be a global variable... So, that needs to be modified... In BASIC, you print to a file by writing PRINT #1, data$ but if you translate that to Perl, it looks like this: print $filehandle $data

    AND PLEASE NOTE THAT IN PERL, THERE IS NO COMMA BETWEEN FILEHANDLE AND DATA!

    Otherwise, I think, this is a strict translation of the above VB code to Perl:

    #!/usr/bin/perl -w use strict; use warnings; my $testname = 'a'; Target_write_wide(1); sub Targets { return 'abc'; } sub TargetValues { return 'abc def int hun son'; } sub Target_write_wide { @_ or return; my $depth = shift; defined $depth or return; length($depth) or return; # Debug: print "Target write depth = $depth", 'Targetvalues', TargetVa +lues($depth); my $Celldata; my $Current_split = 0; my $Num_combinations = 0; my @TargetValueslist = split(' ', TargetValues($depth)); foreach (@TargetValueslist) { length($_) or next; $Celldata = "add_wide_split(\"" . Targets($depth) . "\",$_);\n"; print $Celldata; } if ($depth > 0) { Target_write_wide($depth - 1); } else { $Current_split++; $Num_combinations++; $Celldata = "run_all_wide_split(\"$testname" . "_combination:$Curr +ent_split\");"; print $Celldata; } }

    Edit: I also made the assumption that Targets() and TargetValues() are functions. If those happen to be global arrays, then you need to change the parentheses to square brackets and put a dollar sign in front of the array name. But that should be easy...