in reply to foreach type of deal?

?

Please show some code and data to help us understand.

see How do I post a question effectively?

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

Replies are listed 'Best First'.
Re^2: foreach type of deal?
by hoagies (Initiate) on Mar 15, 2017 at 20:26 UTC
    #!/usr/bin/perl use strict; use warnings; main(@ARGV); sub main { open(FH, "gtype.txt"); foreach( my $line = <FH> ) { s/^g//; #toolic's idea. } } close FH; #and kennethk's idea #!/usr/bin/perl use strict; use warnings; main(@ARGV); sub main { open(FH, "gtype.txt"); while( my $line = <FH> ){ substr($_,1); # Start with the second letter } }

    So, using kennethk's input, I kind of hacked this up...? I can kind of see how it works...

    I looked at the perldocs linked in the replies, and I'm still working through them trying to understand all the various differences.

    the file I'm working with looks something like this:

    gOrd_3342.png

    gOrd_3343.png

    500k of those going down a file. I need to leave all 500k of those with "Ord_xxxx.png. I have yet to try either of mentioned options, but my idea here is to figure this out and learn at the same time, and not simply get an answer I can plug in and call it quits. Thanks.

      Using my $line = <FH> means $_ never gets set so your next line needs to now be $line=substr($line,1);

        Thanks! I just ran into that little bit :D.

        However, I read the perldoc about substr, and I get the idea. Now my question is, what modifies the string? substr just locates the particular part of the string I want to single out, then what?

        #!/usr/bin/perl use strict; use warnings; main(@ARGV); sub main { open(FH, "gtype.txt"); while( my $line = <FH> ) { my $line = substr($line,1); printf $line; } } close FH;

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

Re^2: foreach type of deal?
by Anonymous Monk on Mar 15, 2017 at 19:04 UTC