Skip to content

Instantly share code, notes, and snippets.

@DanyelMorales
Last active March 30, 2021 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanyelMorales/8d27d2b5ca6c9590a465e55dcea1c328 to your computer and use it in GitHub Desktop.
Save DanyelMorales/8d27d2b5ca6c9590a465e55dcea1c328 to your computer and use it in GitHub Desktop.
Serialize a perl array into a php array
#!/usr/bin/perl
use strict;
use warnings;
sub serializeToPhpArray {
my @arr = @{$_[0]};
my $content = "a:".@arr.":{";
for (my $i=0; $i < @arr; $i++) {
my $val = $arr[$i];
$content .="i:".$i.";s:".length($val).":\"".$val."\";";
}
$content .= "}";
return $content
}
my @cccc = ("caca/ca.php", "b/b.php","aaaa/asas.php");
print serializeToPhpArray(\@cccc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment