Skip to content

Perl snippets vscode

Perl Json Snippets for VsCode

{
    // Place your snippets for perl here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    // "Print to console": {
    //  "prefix": "log",
    //  "body": [
    //      "console.log('$1');",
    //      "$2"
    //  ],
    //  "description": "Log output to console"
    // }
    "PrintF Snip":{
        "prefix": "prf",
        "body": "printf(\"$0\\n\");",
        "description": "Printf Formatting"
    },
    "Simple Print":{
        "prefix": "pr",
        "body": "print(\"$0\");",
        "description": "Print Formatting"
    },
    "Main Imports":{
        "prefix": ["im","hd","mn","import"],
        "body": [
        "#!/usr/bin/perl",
        "use strict;",
        "use warnings;",
        "\n",
        "sub main {",
            "\t$0",
        "}",
        "main();"

        ],
        "description": "Importing often used features"
    },
    "Open File Read":{
        "prefix": "openr",
        "body": "open(my $1,\"<\",$2);",
        "description": "Open File In read mode"
    },
    "Open File Write":{
        "prefix": "openw",
        "body": "open(my $1,\">>\",$2);",
        "description": "Open File in Write/Append mode"
    },
    "Close File":{
        "prefix": "close",
        "body": "close($0);"
    },

    "STDIN":{
        "prefix": "std",
        "body": "<STDIN>;",
        "description": "Standart Input. Taking input from user"
    },
        "Join Function":{
            "prefix": "jn",
            "body": "join($0);",
            "description": "Join function"
        },
        "Chompy":{
            "prefix": "chomp",
            "body": "chomp($0);"
        },
        "Add strict and warning directives": {
            "prefix": "usw",
            "body": [
                "use strict;",
                "use warnings;",
                "$1",
                "1;"
            ],
            "description": "Adds strict and warning directives"
        },

        "Add dumper": {
            "prefix": "udd",
            "body": [
                "use Data::Dumper;"
            ],
            "description": "Adds data dumper"
        },
        "Chomp Function":{
            "prefix": "chomp",
            "body": "chomp($0);"
        },
        "Add a new subroutine": {
            "prefix": "sub",
            "body": [
                "sub $1 {",
                "$2",
                "}"
            ],
            "description": "Adds a subroutine"
        },
        "Add a new subroutine with params": {
            "prefix": "sub",
            "body": [
                "sub $1 ($2) {",
                "$3",
                "}"
            ],
            "description": "Adds a subroutine with params"
        },
        "Add new print Dumper statement": {
            "prefix": "pd",
            "body": [
                "print Dumper( $1 );"
            ],
            "description": "Adds a new print Dumper statement"
        },
        "Add new for block": {
            "prefix": "for",
            "body": [
                "for($1 = $2; $3 <= $4; $5){",
                "$6",
                "}"
            ],
            "description": "Adds a new for block"
        },
        "Add new while block": {
            "prefix": "while",
            "body": [
                "while ($1){",
                "$2",
                "}"
            ],
            "description": "Adds a new while block"
        },
        "Add new if block": {
            "prefix": "if",
            "body": [
                "if($1){",
                "$2",
                "}"
            ],
            "description": "Adds a new if block"
        },
        "Add new if/else block": {
            "prefix": "ifel",
            "body": [
                "if($1){",
                "$2",
                "}",
                "else{",
                "$3",
                "}"
            ],
            "description": "Adds a new if/else block"
        },
        "Add new unless block": {
            "prefix": "unless",
            "body": [
                "unless($1){",
                "$2",
                "}"
            ],
            "description": "Adds a new un;ess block"
        },
        "Add new unless/else block": {
            "prefix": "unel",
            "body": [
                "unless($1){",
                "$2",
                "}",
                "else{",
                "$3",
                "}"
            ],
            "description": "Adds a new unless/else block"
        },
        "Add new try/catch block": {
            "prefix": "try",
            "body": [
                "try {",
                "$1",
                "}",
                "catch{",
                "$2",
                "}"
            ],
            "description": "Adds a new try/catch block"
        },
        "Add new BEGIN block": {
            "prefix": "begin",
            "body": [
                "BEGIN {",
                "$1",
                "}",
            ],
            "description": "Adds a new BEGIN block"
        },
        "Add say": {
            "prefix": "uss",
            "body": [
                "use feature qw/ say /;"
            ],
            "description": "Adds say to the script"
        },
        "Add a new package": {
            "prefix": "pkg",
            "body": [
                "package $1",
                "",
                "use strict;",
                "use warnings;",
                "$2",
                "",
                "1;"
            ],
            "description": "Adds a new package"

    },
}