Thank you very much for your help, and I'm sorry for all my mistakes. Please understand that if I were as versed as you all then I probably wouldn't be writing for help about this.

There is no need to "assume" what my code looks like, since I described it exactly. I'm sorry that troubled you. In any event, you did list it exactly as I described it.

When you say, "This is bad, of course...", it was not "of course" to me that it was bad, and if it were then I wouldn't have done it that way.

On checking whether filename.html is in the current directory, my full program first scans the directory for a list of files to work on, and then gets to work on each one, so I'm reasonably certain that the files are there, as no one else has access to the system besides me.

As for "I don't believe you that the inclusion of ^ was the only thing," I'm sorry that you think I am lying to you, but I am not.

When you said, "A saner solution would be to use system instead of backticks," I do not doubt you, but since I am a novice, I do not understand what is "insane" about using backticks.

I used the Tie::File suggestion and it works for me just fine. After reformatting was able to get it down to two lines, which I prefer. Thank you very much for that solution. I am still interested in getting the sed version to wor too, if for no other reason that on occasion I will need to process only one file and I am attracted to a one-line solution.

I don't think I was clear about my goal: It is to remove all leading spaces on *every line* of various files.

In the following examples, I collected the changed text into an array and printed the array so I didn't actually change the file, although in my final solution I will change it to actually write the file back to the disk.

This successfully removes all the spaces in the file, as a test, though that is not my ultimate goal:

    @output = `sed 's/ //g' $filename`;

This removes the very first character, which is a space, but doesn't affect any other lines besides the very first line. This is a problem because I'm trying to process every line.

    @output = `sed 's/^ //g' $filename`;

In my initial testing I did not realize that sed was indeed processing the first line, because the first character in the file used to be a nonspace, so I didn't see any change after I ran the script. I added an initial space to the file for testing.

The sed documentation seems to indicate that sed does not allow the "m" flag from Perl-style regexps which I understand to make the ^ operator work on every line, not just the first line. Then again, my understanding is that sed operates line-by-line by default, and indeed it works that way when I run it from the command line. However I can't get it to work properly when I call it from a Perl script using backticks.


In reply to Re^2: sed regexp works on the command line, but not from Perl script by Anonymous Monk
in thread sed regexp works on the command line, but not from Perl script by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.