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

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 :-))

Replies are listed 'Best First'.
Re^4: Counting iterations of 1 and 0
by AwsedreswA (Initiate) on Feb 04, 2014 at 08:19 UTC

    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 :-))
Re^6: Counting iterations of 1 and 0
by AwsedreswA (Initiate) on Feb 05, 2014 at 01:22 UTC

    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