On Jun 16, [EMAIL PROTECTED] said:

>I have a file that looks like this:
>
>e4343
>d3434
>34344
>43434
>de434
>
>and I am printing the first 40 lines using
>
>$foo = qw(my/file/with/40+lines);
>print substr ( $foo,0,39 );

No, that's printing the first 39 characters of the string $foo.

If you have a filename in $foo, and you want to print the first 40 lines,
I would suggest doing:

  open FILE, "< $foo" or die "can't read $foo: $!";
  while (<FILE>) {
    print if 1 .. 40;  # ooh, magical
  }
  close FILE;

>but how do I print all of these lines on one line with a space meaning

If that's what you want, then do:

  open FILE, "< $foo" or die "can't read $foo: $!";
  while (<FILE>) {
    chomp;
    print "$_ " if 1 .. 40;  # ooh, magical
  }
  close FILE;
  print "\n";

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
CPAN ID: PINYAN    [Need a programmer?  If you like my work, let me know.]
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to