Hi, thanks for posting your code.
Here is a version that appears to do what you want. Note the following things:
- You need to chomp() the user input to remove the newline so you can use the string in a comparison.
- The sample data you provided doesn't contain anything that would match your first regexp.
- The regexp for matching the start of the line with the user input crudely and *only* matches negative numbers with exactly one integer and one decimal place. You'll need to change it if the user could enter a positive number, or a negative integer, or anything else.
- After capturing the match it is available in the special variable $1, which is used for the comparison.
- I placed your sample data in the script in the __DATA__ section for this demo; it's fine to open and read a file as in your original. I also skipped the writing to an out file.
- I placed multiple "debug statements" in the code, i.e. printing out things to show what's going on. Once the program is working correctly you can remove those, but it's a good technique for discovering problems in your data processing.
#!/usr/bin/perl
use strict;
use warnings;
use feature 'say';
print "The lower the score the more stable the structure.", "\n",
"Please set a limiting value e.g. -3: ", "\n";
chomp( my $value = <STDIN> );
chomp( my @input = <DATA> );
my @trash;
my @treasure;
for ( @input ){
if ( /^>+/ ) {
say "$_ matches '/^>+/'";
push @treasure, $_;
} elsif ( /^None/ ) {
say "$_ matches '/^None/'";
push @trash, $_;
} elsif( /(^[\d\.-]{4})/ ) {
say "$_ matches '/(^[\d\.-]{4})/'";
if ( $1 <= $value ) {
say "$1 is <= $value";
push @treasure, $_;
} else {
say "$1 is > $value";
push @trash, $_;
}
} else {
say "$_ doesn't match anything!";
push @trash, $_;
}
}
say 'Treasure:';
foreach my $stuff ( @treasure ) {
say $stuff;
}
__END__
hsa_circ_0067224|chr3:128345575-128345675-|NM_002950|RPN1 FORWARD
-4.4.. 6 .. 17 xxxxxxxxxxGTGAC CAGT ATGC ACTG AAGATGAGGTTTGTG
-0.9.. 5 .. 18 xxxxxxxxxxxGTGA CCAGT ATGC ACTGA AGATGAGGTTTGTGG
None.. 1 .. 20 xxxxxxxxxxxxxxx GTGACCAGTATGCACTGAAG ATGAGGTTTGTGGAC
Hope this helps!
The way forward always starts with a minimal test.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.