vis1982, do you mean to extract lines (as your variable names suggest) or characters from a line within a file within the range specified on the commandline?
    From the reply ABOVE, posted as this was prepared, I think the answer is 'yes.' Do others read it thus?

If characters within a line, you need not only to actually read the file (as Corion mentioned); you need to process the current line... and incrementing $count won't do that for you.

Update: adding code (and subsequently, removing some debug matter)

#!/usr/bin/perl use strict; use warnings; # 848449 =head OP says: Question is u have a file A ACEEWSMKIIWSDJDWKDKEKSSAQWE and want to extract lines with option 5-10 with output like SMKII ## ww reads this as: I have a file with lines like ACEEWSMKIIWSDJDWKDKEKSSAQWE 012345678901234567890123456789 0 1 2 and want to extract characters at positions, 5 .. 9, where the character position is 0-based. =cut if ( $#ARGV < 2 ) { print "Usage: extract.pl firstLine lastLine filename\n"; exit 1; } my $start = $ARGV[0]; my $stop = $ARGV[1]; my $file = $ARGV[2]; my ($line_elements, @line_elements); open (FILE, '<', $file) or die "Can't open file $file $!"; while (<FILE>) { my $line = $_; my @line_elements = split (//,$line); my (@wanted, $wanted); for ($start .. ($stop-1) ) { push @wanted, $_; } for $wanted(@wanted) { for ($line_elements[$wanted]) { print "$line_elements[$wanted]"; } } print "\n\tNext line in file: \n"; }

where content of the input file, 848449.3line.txt, exceeds OP's original requirement, and is:

ACEEWSMKIIWSDJDWKDKEKSSAQWE abcdefghijklxxxxmnop 12345---678xxxx

where CLI and output is

>perl 848449.pl 5 10 848449.3line.txt SMKII Next line in file: fghij Next line in file: ---67 Next line in file: >
hth.

In reply to Re: print and extract the line by ww
in thread print and extract the line by vis1982

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.