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

$line="123 456 789"; @w=unpack('A3A3A3A3',$line); print "@w";
its is giving output as 123 45 6 7.actually..unpack('A8',"hello   ");# produces "hello" right why it is not working for the prevoius one.

Replies are listed 'Best First'.
Re: help neeed in unpack
by Corion (Patriarch) on Feb 10, 2006 at 07:43 UTC

    unpack counts spaces as characters of their own. You might want the following unpack template:

    $line="123 456 789"; @w=unpack('A3xA3xA3',$line); print "@w";

    Or maybe you just want split:

    my @w = split /\s/, $line;
    A reply falls below the community's threshold of quality. You may see it by logging in.