Each column is separated by one or more white space. so my code should + look something like this,

Why do you think it should look like that?

$ENV{HOME}='C:\Documents and Settings\kompeS\Desktop\PERL SCRIPTS';

Why are you using  $ENV{HOME} to store the directory name? Why not just use a normal lexical variable?

open (FILE,"$file"); close(FILE);

Why are you opening and then closing the file? You should always verify that the file opened correctly.

tie (@data,'Tie::File',$file, mode=>O_RDWR) or die "Can't tie to $file +:$^E\n";

The default mode is already O_RDWR? You should store the object returned from tie so that you can use it later for defer() and flush().

@list=split(/ /,@data);

split's second argument is a scalar so perl will convert @data to a scalar which will be the number of elements in @data. Since there is no whitespace in a number that has the same effect as doing  @list = scalar @data;.

You are iterating over the array @data which means that the current line is in the  $_ variable.

The regular expression  / / will split on a single space character, if you want to split on multiple space characters use  / +/ or just use the default  @list = split; which will split on multiple whitespace characters.


In reply to Re: Problem with split and file processing. Need Help!!! by jwkrahn
in thread Problem with split and file processing. Need Help!!! by sas429s

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.