Stumper of the day

petdance on 2003-11-28T03:38:11

Today's Perl puzzler: What I wanted to print the module name and the distro name without the version number, as in

Test::AtRuntime Test-AtRuntime

but the following code didn't print anything at all. What was my bug?

while () { chomp; my ($module,undef,$distro) = split( / / );

$distro =~ s[.+/][]; $distro =~ s[-\d+\.\d+\.tar\.gz]; print $module, " ", $distro, "\n"; }

__END__ Test::AtRuntime 0.02 M/MS/MSCHWERN/Test-AtRuntime-0.02.tar.gz Test::Builder 0.17 M/MS/MSCHWERN/Test-Simple-0.47.tar.gz Test::Builder::DatabaseRow 1.01 P/PR/PROFERO/Test-DatabaseRow-1.01.tar.gz Test::Builder::Tester 0.09 M/MA/MARKF/Test-Builder-Tester-0.09.tar.gz



Hmm

koschei on 2003-11-28T03:55:40

$distro =~ s[-\d+\.\d+\.tar\.gz];
Hey, that's not a complete statement!

Re:Hmm

vsergu on 2003-12-01T17:53:03

Ah, but that's because you didn't finish it. You only included the opening semicolon delimiter for the replacement. The complete statement is

$distro =~ s[-\d+\.\d+\.tar\.gz];
print $module, " ", $distro, "\n";
which is the same as
$distro =~ s/-\d+\.\d+\.tar\.gz/\n    print $module, " ", $distro, "\n"/

This works for me.

brian_d_foy on 2003-11-28T05:02:20

#!/usr/bin/perl
  while (<DATA>) {
    chomp;
    my( $module, undef, $distro ) = split;
 
    $distro =~ s[.+/][];
    $distro =~ s[-\d+\.\d+\.tar\.gz][];
    print $module, " ", $distro, "\n";
}
 
__END__
Test::AtRuntime                    0.02  M/MS/MSCHWERN/Test-AtRuntime-0.02.tar.gz
Test::Builder                      0.17  M/MS/MSCHWERN/Test-Simple-0.47.tar.gz
Test::Builder::DatabaseRow         1.01  P/PR/PROFERO/Test-DatabaseRow-1.01.tar.gz
Test::Builder::Tester