It is a bit difficult to see what you are trying to do. Maybe, if I will tell you what you are doing you will see the error yourself? :) Here we go:
# Save input from STDIN into $file my $file = <STDIN>; # If $file matches one letter or number, then underscore # and then .dat, then do the block. By the way, you are # missing the closing bracket for the block. :) if ($file=~/[a-zA-Z0-9_]\.dat/){ # Open file or die with some error. open(DATOS, "$file") || die "No se puede abrir el archivo, o no existe + en el directorio"; # Read file line by line while (<DATOS>){ # Initialize array @lines my @lines; # Initialize array @line and make it equal to an # empty array @lines, if the line from file starts with # the digit. my @line = @lines if m/^\d/; # Print empty array @lines print "@lines";
Anyway, after I went through your code and annotated it (grin), I think I know what you are trying to do. ;) If you want to read the file and print out only those lines which start with digit (like you did in your commented out print statement), then you are looking for something like:
# Initialize array @lines my @lines; while (<DATOS>) { # Add line from file to array @lines if line starts with # digit push @lines, $_ if m/^\d/; } # Print array @lines after all processing has been done. print @lines;

In reply to Re: reg exp by TVSET
in thread reg exp by erickfq

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.