in reply to pattern matching

A nifty trick when your one-liners get out of hand is to use B::Deparse on it:

perl -MO=Deparse -lne 'print if s/0010 0010.*\/\/.*\/\///'

which gives you an approximation of what Perl runs:

LINE: while (defined($_ = <ARGV>)) { chomp $_; print $_ if s[0010 0010.*//.*//][]; }

This is some ugly code, so I'd rewrite that to be more sightly:

#!/usr/perl -w use strict; while (defined(my $line = <ARGV>)) { chomp $line; print $line if s[0010 0010.*//.*//][]; }
or, if you're interested in post-processing the lines in your script:
#!/usr/perl -w use strict; my @interesting_lines = map { s[0010 0010.*//.*//][] ? $_ : ()} (<ARGV>); print "Name: $_" for @interesting_lines;

Update: Corrected last snippet to work like the previous snippets

Replies are listed 'Best First'.
Re: Re: pattern matching
by perlcgi (Hermit) on May 04, 2004 at 13:59 UTC
    Be careful using .* as it is one greedy mother. The first .* will swallow everything up to the second last // in your regex.
    So if your source text ever happens to have three or more sets of // on a line you regex will fail. Better to use nongreedy, minimal matching using .*?
    This is probably so obvious to an expert like Corion, he didn't bother mentioning it. I mention it 'cos the OP states that the regex seems to work.