Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3842586
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:48:54+00:00 2026-05-19T15:48:54+00:00

I have some document into which I want to add something at the beginning

  • 0

I have some document into which I want to add something at the beginning and at the end of each line. The original document looks like this:

firstLine
secondline

I want to turn it into this:

put 'firstLine';
put 'secondline';

By using the following Perl script, I can only turn it into this:

put 'firstLine';
';put 'secondline';

It seems that there is a $ at the end of the first line and at the beginning of the second line. Could someone help me to figure out what is wrong with the following Perl script?

use File::Find;
use strict;

my ($filename, @lines, $oldterm, $newterm);    #,$File::Find::name);
my $dir = ".";

open MYFILE, ">error.txt" or die $!;
find(\&edits, $dir);

sub edits() {
    $filename = $File::Find::name;
    if (grep(/\.txt$/, $filename)) {           #only process the perl files

        # open the file and read data
        # die with grace if it fails
        open(FILE, "<$filename") or die "Can't open $filename: $!\n";
        @lines = <FILE>;
        close FILE;

        # open same file for writing, reusing STDOUT
        open(STDOUT, ">$filename") or die "Can't open $filename: $!\n";

        # walk through lines, putting into $_, and substitute 2nd away
        for (@lines) {
            s/(&.+)/' "$1" '/ig;
            s/^/put '/ig;
            s/$/';/ig;
            print;
        }

        #Finish up
        close STDOUT;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:48:55+00:00Added an answer on May 19, 2026 at 3:48 pm

    If you do it in one step you should have better luck. Something like:

    s/^(&.+)$/put '$1';/im;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a problem with our current TFS installation. For some reason, which I
I have some jQuery code that runs on every $(document).ready() event. I also have
A simple question I'm sure, but I can't figure it out. I have some
I have created a database diagram in sql server which is consist of number
I want to write a program in Motorola 68000 assembler, the target platform is
I've been playing with RavenDB recently and there is something that is annoying me
I am developing a website which needs to contain functionality in which the user
I have been perusing the internet in search of the best way to accomplish
I'm trying to modify the HTML markup of a page in order to add
There might be some very simple answer to this, but i am really stuck

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.