Perl Style: Changing <I>en passant</I>

  • You can copy and change all at once:

        chomp($answer = <TTY>);
    
        ($a += $b) *= 2;
    
        # strip to basename
        ($progname = $0)        =~ s!^.*/!!;
    
        # Make All Words Title-Cased
        ($capword  = $word)     =~ s/(\w+)/\u\L$1/g;
    
        # /usr/man/man3/foo.1 changes to /usr/man/cat3/foo.1
        ($catpage  = $manpage)  =~ s/man(?=\d)/cat/;
    
        @bindirs = qw( /usr/bin /bin /usr/local/bin );
        for (@libdirs = @bindirs) { s/bin/lib/ }
        print "@libdirs\n";
      | /usr/lib /lib /usr/local/lib
    

Forward to Negative Array Subscripts
Back to Embrace Pattern Matching
Up to index

Copyright © 1998, Tom Christiansen All rights reserved.

Tags

Feedback

Something wrong with this article? Help us out by opening an issue or pull request on GitHub