"R (Chandra) Chandrasekhar" schreef:

> --------
> foreach my $element (@cddb_artist)
>      {
>      $element =~ s/^.*?([0-9,a-f]{8}):.*$/$1/;
>      }
> foreach my $element (@cddb_track)
>      {
>      $element =~ s/^.*?([0-9,a-f]{8}):.*$/$1/;
>      }
> --------

You can write all that as this single line:

    s/^.*?([0-9,a-f]{8}):.*$/$1/ for @cddb_artist, @cddb_track;

Do you really want the comma inside the character class?


> 1. Can this particular regular expression, involving as it does,
> matched sub-pattern variables like $1, be used as a subroutine
> argument, and if so, how? 

Only the first part of the substitution is a regular expression. 

    my $re_hex8 = qr/[[:xdigit:]]{8}/;
    s/^.*?($re_hex8):.*$/$1/ for @cddb_artist, @cddb_track;

Alternative:

perl -wle'
  my @cddb_artist = ("xyz 12345678: abc");
  my @cddb_track  = ("abc fedcba09: xyz");
  my $re_hex8 = qr/[[:xdigit:]]{8}/;
  ($_) = m/($re_hex8)(?=:)/ for @cddb_artist, @cddb_track;
  print for @cddb_artist, @cddb_track;
'
12345678
fedcba09


> 2. Can arbitrary regular expressions, including /PATTERN/REPLACEMENT/
> versions 
> for substitutions, be used as subroutine arguments, and if so, how?

Store the parts in variables. 

-- 
Affijn, Ruud

"Gewoon is een tijger."

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to