in reply to Pattern finding and printing with regex

One way:
use warnings; use strict; my $i = 0; my $pattern; while (my $line = <DATA>) { chomp $line; $pattern = '>'; if ($line =~ s/^$pattern//) { $i++; print "$i: $line \n"; } } __DATA__ >foo

Now it's up to you to figure out how you explain to your professor that someone on the internet did your homework for you.

Replies are listed 'Best First'.
Re^2: Pattern finding and printing with regex
by AppleFritter (Vicar) on Oct 21, 2015 at 20:04 UTC

    Now it's up to you to figure out how you explain to your professor that someone on the internet did your homework for you.

    Your heart is in the right place, but brother, I think you're being too harsh! He didn't ask the monks to do his homework for him, he did what he could and only asked for our help when he got stuck, sharing the code he had already written. Surely that is fair in the Monastery.

Re^2: Pattern finding and printing with regex
by kernelpanic@thedisco (Initiate) on Oct 21, 2015 at 18:40 UTC
    Thanks for your help.