print FILEOUT "eject 0,0,0 ";
my $count = `wc -l <$ejectapes`;
if ($count <= 40 ) {
while() {
chomp $_;
print FILEOUT "$_ "; # if 1..8
#print substr($a,0,7);
}
close (FILEOUT);
}
The substr is sort of what I want, but is sprintf possible ...what should I use? Here is what my end results will look like if I had a file with 40 E strings:
Exxxx Exxxx Exxxx Exxxx Exxxx Exxxx Exxxx Exxxx \n
x5 \n
anything less but it cannot exceed 8 per line:
Exxxx Exxxx Exxxx Exxxx Exxxx Exxxx Exxxx Exxxx \n
Exxxx ..... \n
thank you,
perldoc -f splice. Keep in mind this is destructive so you might want to do the splicing to a copy rather than your original if you need to use the source array again later.
my @src = 'a' .. 'zz';
my $count = 0;
while( my @cur = splice( @src, 0, 8 ) ) {
print join( "\t", @cur ), "\n";
$count += @cur;
last if $count >= 40;
}
Update: Clarified warning.
while (but where do I go from here to get the remaining E string list? I have not been able to make substr include spaces as my output is all strung together as such.... E2323E3243E2432E543) { chomp $_; print FILEOUT substr($_, 0, 7);
I'm afraid I have no idea of what you are trying to achieve. In your original post you say:
...how to print 8 scalers/elements then \n, then 5 more lines of 8 or less for a max total of 40...
but that makes a maximum total of 48.
And maybe you could show us what your input file looks like?
dave
substr won't include any spaces if your original source string doesn't have any. At any rate, just make an array out of your source string and use what I showed above.
my @src;
{
my $tmp = $a;
push @src, substr( $tmp, 0, 7, "" ) while $tmp;
}
# . . . as above . . .
Update: And looking again at your sample it appears you might have rows of space separated data, in which case you'd want to use something along the lines of while(
Maybe your input file is a list of file names? If that's the case, you seem to know how to get the filename you want. Just use the parts that you need.
If I'm *way* off, I apologize... I'm still pretty new at this :)
my $a = "E1111111E2222222E3333333E4444444E5555555E6666666E7777777E8888888E99999";
my $cnt = 0;
while (length($a)) {
my $b = substr($a,0,8);
print "$b ";
$a = substr($a, 8);
if (!(++$cnt%8)) { print "\n"; }
}
print "\n";
Making a wild stab in the dark given the vagueness of input and output available/desired I am assuming an input file format like:
# input foo bar baz boo foo bar baz bax foo bar baz boo foo bar foo bar baz boo foo bar baz bax foo bar baz boo foo bar baz bax my $max = 40; while(){ chomp; my @elems = split ' '; @elems = grep{ defined $_ }@elems[0..7]; $max -= scalar @elems; last if $max < 0; # exit if printing would make more than 40 elements; print "@elems\n"; last if $. == 6; # exit at 6th line (1+5 more) }
cheers
tachyon
perlmonks.org content © perlmonks.org and drock, Fletch, Not_a_Number, tachyon, TrekNoid
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03