开发者

Perl string in Quote Word?

开发者 https://www.devze.com 2023-02-22 23:21 出处:网络
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\";

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

精彩评论

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