Skip to content

Commit

Permalink
added handling of $1..$9
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenvr committed Oct 3, 2013
1 parent 2413e87 commit 20a430a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion diary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ Date Start Stop Activity Comments
02/10 10:40am 12:00pm hash, bitwise added basic hash handling, as well as a few missing things such as bitwise operators
03/10 10:30am 11:00am keys, variables in regex

Total Time: 875min = 14hr 35min
Total Time: 905min = 15hr 05min
10 changes: 6 additions & 4 deletions perl2python
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ our $lines_imports = 0;
while ($line = <>) {
chomp $line;
if ($line =~ /^#!/ && $. == 1) {

# translate #! line

print "#!/usr/bin/python2.7 -u\n";
} elsif ($line =~ /^\s*#/ || $line =~ /^\s*$/) {

# Blank & comment lines can be passed unchanged
addToSourceArray("$line\n");
} elsif ($line =~ /^\s*print\s*("*.*\s*[\\n]?\s*")*\s*\;*$/) {
Expand All @@ -42,7 +39,6 @@ while ($line = <>) {
#still not done, can only work when only printing variable
$temp = $1;
printFunction($temp);

} elsif ($line =~ /^\s*\$(.+)\;$/) {
#declaring a variable
#python just removes the dollar sign and semi-colon
Expand Down Expand Up @@ -130,6 +126,10 @@ sub handleIntegerVariables {
sub variableDec {
my $variable_name = $_[0];
my $variable_assign = $_[1];
print "$variable_name = $variable_assign\n";
if ($variable_assign =~ /^\$([1-9])$/) {
$variable_assign = "m.group($1)";
}
if ($variable_name =~ /{(.*)}/) {
#ie its a hash
$variable_name = handleHash($variable_name,$1);
Expand Down Expand Up @@ -332,6 +332,8 @@ sub conditionHandling {
$hash_key = $1;
$cond_to_check =~ s/^\$//; #need to remove perl's variable metacharacter "$"
return handleHash($cond_to_check,$hash_key);
} elsif ($cond_to_check =~ /^\$([1-9])$/) {
return "m.group($1)";
} elsif ($cond_to_check =~ /^\$(.*)$/) {
#variable declaration, just remove "$"
return $1;
Expand Down

0 comments on commit 20a430a

Please sign in to comment.