Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a variable whose data is shown below.I only want to get "0x4443018d" from that variable.Can anyone advise on how can I do that?

$line=M6608BBBBQYMNM1000.data:0x4443018d D debug_mode

Replies are listed 'Best First'.
Re: Splitting data in a variable
by wind (Priest) on May 02, 2011 at 06:48 UTC

    Using a regex:

    my $line = 'M6608BBBBQYMNM1000.data:0x4443018d D debug_mode'; my ($hex) = $line =~ /:(0x[a-f0-9]*)/; print $hex;
Re: Splitting data in a variable
by Nikhil Jain (Monk) on May 02, 2011 at 05:37 UTC

    Use regular expression like

    my $line="M6608BBBBQYMNM1000.data:0x4443018d D debug_mode"; my ($desired_output) = $line =~ m/:([^\s]+)/;

    Output: 0x4443018d

Re: Splitting data in a variable
by toolic (Bishop) on May 02, 2011 at 12:57 UTC
    Another way is to use a POSIX character class (perlre, perlreref):
    use warnings; use strict; my $line = 'M6608BBBBQYMNM1000.data:0x4443018d D debug_mode'; if ($line =~ /(0x[[:xdigit:]]+)/) { print "$1\n"; } __END__ 0x4443018d