Well,
1) is easy. Use the modulo operator %
It returns the remainder after a division so $number % 2 is only zero for even numbers and is 1 for odd numbers. See the perlop page for lots of info.

2) is a bit harder. I'm sure there are many elegant solutions. Some probably got posted while I was looking into it. My first try, if the files aren't too big, would be to slurp them into arrays and then fold them together.

use strict; use warnings; open (T1, "t1") or die; my @file1 = <T1>; my @file2 = <DATA>; my @file; while (@file1 and @file2) { push @file, (shift @file1, shift @file2); } push @file, @file1 or @file2; #catch any leftover while (my $line = shift @file) { #do 'things' with it print $line; } __END__ file1 file1 file1 file1
the t1 file looks like the END block but with 2 instead of 1 I get
Useless use of private array in void context at junk line 13. file2 file1 file2 file1 file2 file1 file2 file1 file2 file3, kidding... file2
Not sure what the warnings for, I guess because one of the array's is empty maybe? I'll bet if you put that into an if/else it wouldn't complain.

There's probably a more elegant solution, but this is what comes to mind.

3) Did you try it? I just ran the code you posted (cleaned up with ';' :-) and got this

use strict; use warnings; $/ = "****"; my @array; while (<DATA>) { chomp; push @array, $_; $/= "####"; } print "@array"; __END__ stuff****more stuff####less
and got
$ perl junk stuff more stuff less

Hope this helps
Ira

"So... What do all these little arrows mean?"
~unknown


In reply to Re: a few basic questions by IraTarball
in thread a few basic questions by maddfisherman

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.