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
    `,
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions that Perl one-liners are 'more powerful than sed' and have 'better cross-platform support', which adds some behavioral context. However, it fails to disclose critical traits: it doesn't clarify that this is a destructive write operation (edits files in-place), doesn't mention permissions or error handling, and doesn't explain the backup behavior implied by the 'backup' parameter. For a mutation tool with zero annotation coverage, this is inadequate.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Edit files using Perl one-liners') and adds value with comparative context. Every word earns its place, making it appropriately concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a file-editing mutation tool with 4 parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral risks (e.g., file modification, backup defaults), error cases, or output expectations. The comparative note adds some context, but for a tool that alters files, more completeness is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no parameter-specific information beyond what's in the schema. According to the rules, with high schema coverage (>80%), the baseline is 3 even with no param info in the description, which applies here.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Edit files using Perl one-liners'. It specifies the verb ('Edit') and resource ('files'), and distinguishes it from alternatives by mentioning 'more powerful than sed, better cross-platform support'. However, it doesn't explicitly differentiate from all siblings like 'sed_edit' or 'line_edit' by name, keeping it at 4 rather than 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implied usage guidance by comparing Perl one-liners to sed and noting cross-platform advantages, which suggests when to prefer this tool over alternatives like 'sed_edit'. However, it lacks explicit when-to-use or when-not-to-use instructions, and doesn't mention specific alternatives by name, resulting in a score of 3.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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