in reply to Re: Counting iterations of 1 and 0
in thread Counting iterations of 1 and 0

Sorry about my indention error guys, it made sense to me.

I tested that code Bloodnok Here is what I made it into..

use warnings; use strict; use autodie; open IN, "<baseline_pattern.txt"; binmode IN; my @content = <IN>; close IN; foreach my $num (keys %rec) { my @count = ("@content" =~ /$num+/sg); open my $fh, ">iterations$num.txt"; print "$_\n" for @count; close $fh; }

And here is the error message.

Global symbol "%rec" requires explicit package name at D:\iterations counter.pl

Line 10.

Replies are listed 'Best First'.
Re^3: Counting iterations of 1 and 0
by Bloodnok (Vicar) on Feb 03, 2014 at 13:52 UTC
    Hmm, methinx I made a bit of a showstopping suggestion ... try - foreach my $num (qw/0 1/) {...

    A user level that continues to overstate my experience :-))

      Well, now at least I am getting a long list of 1's.

      Here is what I am using.

      use warnings; use strict; use autodie; open IN, "<D:\\baseline_pattern.txt"; binmode IN; my @content = <IN>; close IN; foreach my $num (qw/0 1/) { my @count = ("@content" =~ /$num+/sg); open my $fh, ">iterations$num.txt"; print "$_\n" for @count; close $fh; }

      There are files "D:\iterations_1.txt" and "D:\iterations_0.txt" that I created.

      However there was nothing written to these files.

      Should there be a sprintf?

        Nope, print is, or should be doing the job - looks like there might've been 2 mistakes -, try print $fh "$_\n" for @count;
        A user level that continues to overstate my experience :-))

      Well something is working right because I got no errors.

      However, nothing was written to either file.

      This is the code now.

      use warnings; use strict; use autodie; open IN, "<D:\\baseline_pattern.txt"; binmode IN; my @content = <IN>; close IN; foreach my $num (qw/0 1/) { my @count = ("@content" =~ /$num+/sg); open my $fh, ">iterations_$num.txt"; print $fh "$_\n" for @count; close $fh; }

      Should the '>' in front of iterations be a '>>' for appending?

      How can I fully qualify where the files are that data should be written?

      I can barely make sense of what is going on in this script