> if anyone tries this, please let me know your thoughts.
I don't think you're handling the case where a user might store this data in
a file and have plain old integers and strings:
i:5;
s:5:"aaaaa";
What does PHP serialize() do when it gets badly formatted strings?
These couple lines handle integers and strings on their own:
#================
sub unserialize {
#================
$_[0] =~ /^i/ && return substr($_[0],2)+0;
# substr($_[0],0,1) eq 'i' && return substr($_[0],2)+0;
#
# Will fail on badly formated strings
#
# qq|s:5:"aaaaa";foo|;
#
# my($len) = $_[0] =~ /^s:(\d+):/;
# /^s/ && return substr($_[0],-2,$len);
#
$_[0] =~ /^s/ && do { $_[0] =~ /^s:(\d+):/;
return substr($_[0],length($1)+4,$1) }
} # end sub
print join "\n", unserialize('i:50;'),
unserialize('i:5;'),
unserialize('i:5;foo'),
unserialize('s:5:"aaaaa";'),
unserialize('s:10:"aaaaaaaaaa";foo');
50
5
5
aaaaa
aaaaaaaaaa
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web