On 09/15/2006 12:54 AM, ubergoonz wrote:
Hi,

I have a certain variables of emplyee number which comes in the format of
[a0000000]  or [u0000000] {whereby 0000000 is some serial numbers}.

I would like to remove the enclosed [ & ] see if it is belong to class a or
u , i can do it as follow

$var = /\[//; $var = /\]//;
if ($var =~ '^a) {
  print "$var is class A";
} elsfi ($var =~ '^u) {
  print '$var is class U";
}
$var = /a//; $var = /u//;

How can i remove the chars all in a single line? and write the code in a
more perl manner ?


regards
rexo


I can think of two good ways of doing this:

    use strict;
    use warnings;
    use Data::Dumper;
    my $string = '[a0000000] [u0000000]';

    # Method 1:
    my $str = $string;
    $str =~ s/[][]//g;
    print $str, "\n";

    # Method 2:
    my @data = grep length, split /[][ ]/, $string;
    print Dumper([EMAIL PROTECTED]);

I can't remember from where I got the [][] syntax. Perhaps it was from FMTEYEWTK for the perl faqs. Thank you whoever you are.






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to