in reply to pull single value

Looking at this code, you want to change it to something like this.
#!/usr/bin/perl use strict; my @record = ( "662-5555", "+1 102 892-1314" ); for (@record) { print if /(^\d{3}-\d{4}$)/; }

Replies are listed 'Best First'.
Re^2: pull single value
by Anonymous Monk on Nov 09, 2009 at 23:59 UTC
    Why did u put this array? my @record = ( "662-5555", "+1 102 892-1314" ); What if they are just individual values? Thanks, Pamela
      Did you want to run the "print if" against both values?
        Actually this code will fetch attribute having multiple values, i want only a single value that matches my pattern. The code above is not working. I even tried this one.
        #!/usr/bin/perl use strict; use warnings; my @array; my $record = "+1 102 892-1314"; $record = "662-5555"; if ($record =~ m/(^\d{3}-\d{4}$)/) { push @array, $record; } print "@array";
        yes.
        How to do that?