Last active
March 30, 2021 23:26
-
-
Save DanyelMorales/8d27d2b5ca6c9590a465e55dcea1c328 to your computer and use it in GitHub Desktop.
Serialize a perl array into a php array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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