Stories
Slash Boxes
Comments

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

petdance (2468)

petdance
  andy@petdance.com
http://www.perlbuzz.com/
AOL IM: petdance (Add Buddy, Send Message)
Yahoo! ID: petdance (Add User, Send Message)
Jabber: petdance@gmail.com

I'm Andy Lester, and I like to test stuff. I also write for the Perl Journal, and do tech edits on books. Sometimes I write code, too.

Journal of petdance (2468)

Thursday November 27, 2003
10:38 PM

Stumper of the day

[ #16049 ]
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 (<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              0.09  M/MA/MARKF/Test-Builder-Tester-0.09.tar.gz

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Hmm (Score:2, Insightful)

    $distro =~ s[-\d+\.\d+\.tar\.gz];
    Hey, that's not a complete statement!
    --
      ---ict / Spoon
    • 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"/
  • #!/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