in reply to Re: Vertical Regex
in thread Vertical Regex

Thank you very much zwon! Your script work just fine for me. I've made some changes to the code so that I can define what is the input file. But I'm not sure whether this is the correct way of doing it or not. Thank you for showing me how the regex work to match certain text i want. Thank you
my ($frg) = @ARGV; $frgfile = "$frg"; open(frgfile) or die("Unable to open FRG file"); while(<frgfile>) { if (/^{FRG/../^}/){ if (/^acc:(\d+)/) { print ">$1\n"; } elsif ( /^seq:/ ) { while(<frgfile>) { last if /^\./; print; } } } }

Replies are listed 'Best First'.
Re^3: Vertical Regex
by zwon (Abbot) on Jun 04, 2009 at 17:18 UTC
    my ($frg) = @ARGV; $frgfile = "$frg"; open(frgfile) or die("Unable to open FRG file");

    That's very confusing form. It's a good practice to always start your scripts with

    use strict; use warnings;
    this may help you to avoid many problems. In this case you would see some warnings. I'd write this as follows:
    open my $fd, '<', $ARGV[0] or die $!; while (<$fd>) { ...
    Note how you can store filehandle in scalar variable.