{
    "content": [
        {
            "type": "text",
            "text": "# cat (perldoc)\n\n## TLDR\n\n> Print and concatenate files.\n\n- Print the contents of a file to `stdout`:\n  `cat {{path/to/file}}`\n- Concatenate several files into an output file:\n  `cat {{path/to/file1 path/to/file2 ...}} > {{path/to/output_file}}`\n- Append several files to an output file:\n  `cat {{path/to/file1 path/to/file2 ...}} >> {{path/to/output_file}}`\n- Copy the contents of a file into an output file without buffering:\n  `cat -u {{/dev/tty12}} > {{/dev/tty13}}`\n- Write `stdin` to a file:\n  `cat - > {{path/to/file}}`\n\n*Source: tldr-pages*\n\n---\n\n## Section Outline\n\n- **Found in /usr/share/perl/5.34/pod/perlfaq4.pod** (48 lines)\n- **Found in /usr/share/perl/5.34/pod/perlfaq7.pod** (9 lines)\n\n## Full Content\n\n### Found in /usr/share/perl/5.34/pod/perlfaq4.pod\n\nHow can I remove duplicate elements from a list or array?\n(contributed by brian d foy)\n\nUse a hash. When you think the words \"unique\" or \"duplicated\", think\n\"hash keys\".\n\nIf you don't care about the order of the elements, you could just create\nthe hash then extract the keys. It's not important how you create that\nhash: just that you use \"keys\" to get the unique elements.\n\nmy %hash   = map { $, 1 } @array;\n# or a hash slice: @hash{ @array } = ();\n# or a foreach: $hash{$} = 1 foreach ( @array );\n\nmy @unique = keys %hash;\n\nIf you want to use a module, try the \"uniq\" function from\nList::MoreUtils. In list context it returns the unique elements,\npreserving their order in the list. In scalar context, it returns the\nnumber of unique elements.\n\nuse List::MoreUtils qw(uniq);\n\nmy @unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 1,2,3,4,5,6,7\nmy $unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 7\n\nYou can also go through each element and skip the ones you've seen\nbefore. Use a hash to keep track. The first time the loop sees an\nelement, that element has no key in %Seen. The \"next\" statement creates\nthe key and immediately uses its value, which is \"undef\", so the loop\ncontinues to the \"push\" and increments the value for that key. The next\ntime the loop sees that same element, its key exists in the hash *and*\nthe value for that key is true (since it's not 0 or \"undef\"), so the\nnext skips that iteration and the loop goes to the next element.\n\nmy @unique = ();\nmy %seen   = ();\n\nforeach my $elem ( @array ) {\nnext if $seen{ $elem }++;\npush @unique, $elem;\n}\n\nYou can write this more briefly using a grep, which does the same thing.\n\nmy %seen = ();\nmy @unique = grep { ! $seen{ $ }++ } @array;\n\n### Found in /usr/share/perl/5.34/pod/perlfaq7.pod\n\nHow can I catch accesses to undefined variables, functions, or methods?\nThe AUTOLOAD method, discussed in \"Autoloading\" in perlsub lets you\ncapture calls to undefined functions and methods.\n\nWhen it comes to undefined variables that would trigger a warning under\n\"use warnings\", you can promote the warning to an error.\n\nuse warnings FATAL => qw(uninitialized);\n\n"
        }
    ],
    "structuredContent": {
        "command": "cat",
        "section": "-q",
        "mode": "perldoc",
        "summary": null,
        "synopsis": null,
        "tldr_summary": "Print and concatenate files.",
        "tldr_examples": [
            {
                "description": "Print the contents of a file to `stdout`",
                "command": "cat {{path/to/file}}"
            },
            {
                "description": "Concatenate several files into an output file",
                "command": "cat {{path/to/file1 path/to/file2 ...}} > {{path/to/output_file}}"
            },
            {
                "description": "Append several files to an output file",
                "command": "cat {{path/to/file1 path/to/file2 ...}} >> {{path/to/output_file}}"
            },
            {
                "description": "Copy the contents of a file into an output file without buffering",
                "command": "cat -u {{/dev/tty12}} > {{/dev/tty13}}"
            },
            {
                "description": "Write `stdin` to a file",
                "command": "cat - > {{path/to/file}}"
            }
        ],
        "tldr_source": "official",
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "Found in /usr/share/perl/5.34/pod/perlfaq4.pod",
                "lines": 48,
                "subsections": []
            },
            {
                "name": "Found in /usr/share/perl/5.34/pod/perlfaq7.pod",
                "lines": 9,
                "subsections": []
            }
        ],
        "sections": {
            "Found in /usr/share/perl/5.34/pod/perlfaq4.pod": {
                "content": "How can I remove duplicate elements from a list or array?\n(contributed by brian d foy)\n\nUse a hash. When you think the words \"unique\" or \"duplicated\", think\n\"hash keys\".\n\nIf you don't care about the order of the elements, you could just create\nthe hash then extract the keys. It's not important how you create that\nhash: just that you use \"keys\" to get the unique elements.\n\nmy %hash   = map { $, 1 } @array;\n# or a hash slice: @hash{ @array } = ();\n# or a foreach: $hash{$} = 1 foreach ( @array );\n\nmy @unique = keys %hash;\n\nIf you want to use a module, try the \"uniq\" function from\nList::MoreUtils. In list context it returns the unique elements,\npreserving their order in the list. In scalar context, it returns the\nnumber of unique elements.\n\nuse List::MoreUtils qw(uniq);\n\nmy @unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 1,2,3,4,5,6,7\nmy $unique = uniq( 1, 2, 3, 4, 4, 5, 6, 5, 7 ); # 7\n\nYou can also go through each element and skip the ones you've seen\nbefore. Use a hash to keep track. The first time the loop sees an\nelement, that element has no key in %Seen. The \"next\" statement creates\nthe key and immediately uses its value, which is \"undef\", so the loop\ncontinues to the \"push\" and increments the value for that key. The next\ntime the loop sees that same element, its key exists in the hash *and*\nthe value for that key is true (since it's not 0 or \"undef\"), so the\nnext skips that iteration and the loop goes to the next element.\n\nmy @unique = ();\nmy %seen   = ();\n\nforeach my $elem ( @array ) {\nnext if $seen{ $elem }++;\npush @unique, $elem;\n}\n\nYou can write this more briefly using a grep, which does the same thing.\n\nmy %seen = ();\nmy @unique = grep { ! $seen{ $ }++ } @array;\n",
                "subsections": []
            },
            "Found in /usr/share/perl/5.34/pod/perlfaq7.pod": {
                "content": "How can I catch accesses to undefined variables, functions, or methods?\nThe AUTOLOAD method, discussed in \"Autoloading\" in perlsub lets you\ncapture calls to undefined functions and methods.\n\nWhen it comes to undefined variables that would trigger a warning under\n\"use warnings\", you can promote the warning to an error.\n\nuse warnings FATAL => qw(uninitialized);\n",
                "subsections": []
            }
        }
    }
}