{
    "mode": "perldoc",
    "parameter": "Clone",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Clone/json",
    "generated": "2026-06-10T16:22:38Z",
    "synopsis": "use Clone 'clone';\nmy $data = {\nset => [ 1 .. 50 ],\nfoo => {\nanswer => 42,\nobject => SomeObject->new,\n},\n};\nmy $cloneddata = clone($data);\n$cloneddata->{foo}{answer} = 1;\nprint $cloneddata->{foo}{answer};  # '1'\nprint $data->{foo}{answer};         # '42'\nYou can also add it to your class:\npackage Foo;\nuse parent 'Clone';\nsub new { bless {}, shift }\npackage main;\nmy $obj = Foo->new;\nmy $copy = $obj->clone;",
    "sections": {
        "NAME": {
            "content": "Clone - recursively copy Perl datatypes\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Clone 'clone';\n\nmy $data = {\nset => [ 1 .. 50 ],\nfoo => {\nanswer => 42,\nobject => SomeObject->new,\n},\n};\n\nmy $cloneddata = clone($data);\n\n$cloneddata->{foo}{answer} = 1;\nprint $cloneddata->{foo}{answer};  # '1'\nprint $data->{foo}{answer};         # '42'\n\nYou can also add it to your class:\n\npackage Foo;\nuse parent 'Clone';\nsub new { bless {}, shift }\n\npackage main;\n\nmy $obj = Foo->new;\nmy $copy = $obj->clone;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides a \"clone()\" method which makes recursive copies of nested hash, array,\nscalar and reference types, including tied variables and objects.\n\n\"clone()\" takes a scalar argument and duplicates it. To duplicate lists, arrays or hashes, pass\nthem in by reference, e.g.\n\nmy $copy = clone (\\@array);\n\n# or\n\nmy %copy = %{ clone (\\%hash) };\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Storable's \"dclone()\" is a flexible solution for cloning variables, albeit slower for\naverage-sized data structures. Simple and naive benchmarks show that Clone is faster for data\nstructures with 3 or fewer levels, while \"dclone()\" can be faster for structures 4 or more\nlevels deep.\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 2001-2019 Ray Finch. All Rights Reserved.\n\nThis module is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Ray Finch \"<rdf@cpan.org>\"\n\nBreno G. de Oliveira \"<garu@cpan.org>\" and Florian Ragwitz \"<rafl@debian.org>\" perform routine\nmaintenance releases since 2012.\n",
            "subsections": []
        }
    },
    "summary": "Clone - recursively copy Perl datatypes",
    "flags": [],
    "examples": [],
    "see_also": []
}