Skip to main content
Glama

perl_edit

Edit files using Perl one-liners for text manipulation with cross-platform support, enabling targeted modifications without full file replacement.

Instructions

Edit files using Perl one-liners (more powerful than sed, better cross-platform support)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileYesFile to edit
scriptYesPerl script (e.g., "s/old/new/g" or "$_ = uc" for uppercase)
backupNoCreate backup file
multilineNoEnable multiline mode (-0777)

Implementation Reference

  • The handler function for the perl_edit tool. It executes a Perl one-liner script on the specified file, with options for backup and multiline processing.
    case 'perl_edit': {
      const { file, script, backup = true, multiline = false } = args;
      
      if (!existsSync(file)) {
        throw new Error(`File not found: ${file}`);
      }
      
      const backupExt = backup ? '.bak' : '';
      const multilineFlag = multiline ? '-0777 ' : '';
      const perlCmd = `perl -i${backupExt} ${multilineFlag}-pe '${script}' '${file}'`;
      
      await execAsync(perlCmd);
      
      return {
        content: [{
          type: 'text',
          text: `Successfully edited ${file} using Perl${backup ? ' (backup created as .bak)' : ''}`
        }]
      };
    }
  • src/index.ts:175-202 (registration)
    Registers the perl_edit tool in the listTools response, including its name, description, and input schema.
    {
      name: 'perl_edit',
      description: 'Edit files using Perl one-liners (more powerful than sed, better cross-platform support)',
      inputSchema: {
        type: 'object',
        properties: {
          file: {
            type: 'string',
            description: 'File to edit'
          },
          script: {
            type: 'string', 
            description: 'Perl script (e.g., "s/old/new/g" or "$_ = uc" for uppercase)'
          },
          backup: {
            type: 'boolean',
            default: true,
            description: 'Create backup file'
          },
          multiline: {
            type: 'boolean',
            default: false,
            description: 'Enable multiline mode (-0777)'
          }
        },
        required: ['file', 'script']
      }
    },
  • Input schema definition for the perl_edit tool, specifying parameters and types.
    inputSchema: {
      type: 'object',
      properties: {
        file: {
          type: 'string',
          description: 'File to edit'
        },
        script: {
          type: 'string', 
          description: 'Perl script (e.g., "s/old/new/g" or "$_ = uc" for uppercase)'
        },
        backup: {
          type: 'boolean',
          default: true,
          description: 'Create backup file'
        },
        multiline: {
          type: 'boolean',
          default: false,
          description: 'Enable multiline mode (-0777)'
        }
      },
      required: ['file', 'script']
  • Help content and examples for the perl_edit tool.
      perl_edit: `perl_edit - Perl one-liner execution
    ===================================
    Direct access to perl's text processing power.
    
    Examples:
      // Simple substitution
      perl_edit({ file: "data.txt", script: "s/foo/bar/g" })
      
      // Delete lines
      perl_edit({ file: "log.txt", script: "$_ = '' if /DEBUG/" })
      
      // Transform to uppercase
      perl_edit({ file: "names.txt", script: "$_ = uc" })
      
      // Complex multiline operations
      perl_edit({ 
        file: "code.js", 
        script: "s/function\\s+(\\w+)\\s*\\(/const $1 = (/g",
        multiline: true 
      })
    
    Tips:
    - Use $_ for the current line
    - Escape backslashes in regex
    - multiline mode slurps entire file
    `,

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MikeyBeez/mcp-smalledit'

If you have feedback or need assistance with the MCP directory API, please join our Discord server