I have a single input file with entries as follows:

--snip--
USER1 [20090101] note
bla bla bla
bla bla bla

USER2 [20090104] note
bla bla bla
bla bla bla

--snip--

What I'm trying to do is create a single-argument script which displays
all entries for a given user.

So calling it as 'filter.pl user1' will print all entries for USER1.


Here is what I've got so far:

---
my $user = shift;

# slurp file
my $file = do {
    open my $fh, 'inputfile.txt' or die $!;
    local $/;
    <$fh>;
};

if ( $file =~ /(^$user.*?)^$/smg ) {
        print $1;
}
---

Here's my thinking behind the non-functional regex.
It matches a set of lines starting with a line which begins with $user,
followed by all non-empty lines, and terminated with an empty line (^$).

Running my script produces zero output.  My questions are:
1. Is there a simpler way to approach/accomplish this?
2. If not, what's wrong with my regex?



Thanks in advance for any help.

/P

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to