in reply to Perl's POD's description of the use of capturing special variables.

MU. Don't use $1 etc. when you don't have to:
use strict; no warnings; my @data = (1,2,3,undef,4,5); for (@data) { /(\d+)/; print $1 if $1; } print "\n"; for (@data) { my ($numb) = $_ =~ /(\d+)/; print $numb if $numb; } print "\n";
I would like to see more of the second example in the docs. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
  • Comment on Re: Perl's POD's description of the use of capturing special variables.
  • Download Code

Replies are listed 'Best First'.
Re: Re: Perl's POD's description of the use of capturing special variables.
by PodMaster (Abbot) on Apr 06, 2004 at 17:38 UTC
    I think you meant
    /(\d+)/ and print $1; # or print $1 if /(\d+)/; # and print $numb if defined $numb; # since 0 is false
    :)

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.