Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: reg exp

by TVSET (Chaplain)
on Oct 27, 2003 at 21:19 UTC ( [id://302522]=note: print w/replies, xml ) Need Help??


in reply to reg exp

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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://302522]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-28 18:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found