Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aembleton/870812 to your computer and use it in GitHub Desktop.
Save aembleton/870812 to your computer and use it in GitHub Desktop.
Call Perl number normalisation from Java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Run {
public static void main(String args[]) {
Process process;
try {
process = Runtime.getRuntime().exec("perl normalize.pl 07882085327 GB");
process.waitFor();
if (process.exitValue() == 0) {
System.out.println("Command Successful");
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("Command Failure");
}
} catch (Exception e) {
System.out.println("Exception: " + e.toString());
}
}
}
#!/usr/bin/perl
use strict;
use warnings;
my $n = $ARGV[0];
my $country = $ARGV[1];
if ($country eq "GB") {
if ($n =~ /^0(\d{10})$/x) {
$n = "44" . "$1";
}
}
print "+" . $n . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment