in reply to Re^4: foreach type of deal?
in thread foreach type of deal?

now what can I use to replace the printf, to use to delete?

You have now entered a situation i dont like. You seem to want to want to replace the original file. for the most part i dont like to do that (at first). I dont like to modify my only copy of the original data. What i do instead is write a new file, then use the new file in later processing.

use strict; use warnings; main(@ARGV); sub main { open(my $in ,'<', "gtype.txt"); open(my $out ,'>', "fixed-gtype.txt"); while( my $line = <$in> ) { my $line = substr($line,1); print $out $line; } } close $in; close $out;
Note also the change from printf to print. You should read about what printf does in regards to the first argument being a format. What you wanted instead was print.

Replies are listed 'Best First'.
Re^6: foreach type of deal?
by hoagies (Initiate) on Mar 15, 2017 at 21:47 UTC

    Wow, I'm thinking I have a lot to learn. I was with you until the in, out deal. I never even considered that I had to use something like that. You're right, I shouldn't have been thinking about making a change to the original copy.

    I tried the code, and it works, but it will only work if I comment out use strict mode. Otherwise, I'm getting errors on declarations. I'm currently trying to figure out how to declare this code correctly. As I said, the code works like a charm, but I want to see if I can at least get the declarations correct. :/.

    I learned a few things with this, but I wouldn't have come close to figuring this out without you guys. Thanks!

      ug... will "too early in the morning" work at 4pm?

      while( my $line = <$in> ) { $line = substr($line,1); print $out $line; }

        I got it!!! The error was coming from:

        close $in

        close $out

        They were outside of the block! :D. Now the whole thing works flawlessly. Thanks again for everything!