开发者

Perl string in Quote Word?

Seem like my daily road block. Is this possible? String in qw?

#!/usr/bin/perl

use strict;
use warnings;

print "E开发者_StackOverflow中文版nter Your Number\n";
my $usercc = <>;

##split number
$usercc =~ s/(\w)(?=\w)/$1 /g;

print $usercc;

## string in qw, hmm..

my @ccnumber = qw($usercc);

I get Argument "$usercc" isn't numeric in multiplication (*) at

Thanks


No.
From: http://perlmeme.org/howtos/perlfunc/qw_function.html

How it works

qw() extracts words out of your string using embedded whitsepace as the delimiter and returns the words as a list. Note that this happens at compile time, which means that the call to qw() is replaced with the list before your code starts executing.

Additionlly, no interpolation is possible in the string you pass to qw().


Instead of that, use

my @ccnumber = split /\s+/, $usercc;

Which does what you probably want, to split $usercc on whitespace.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜