Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Passing digits in perl

by marinersk (Priest)
on Apr 26, 2015 at 23:58 UTC ( [id://1124814]=note: print w/replies, xml ) Need Help??


in reply to Passing digits in perl

The error, translated to newbie terms, is that you didn't define $inp
You define your variables using mymost of the time.

Adding myreveals a slightly less obvious error -- you neglected to end your first printstatement with semi-colon. :-)

Because you wisely did use strict;, it gave the following errors:

D:\PerlMonks>digits1.pl syntax error at D:\PerlMonks\digits1.pl line 5, near "chomp" Global symbol "$inp" requires explicit package name at D:\PerlMonks\di +gits1.pl line 5. Global symbol "$inp" requires explicit package name at D:\PerlMonks\di +gits1.pl line 6. Global symbol "$inp" requires explicit package name at D:\PerlMonks\di +gits1.pl line 7. Execution of D:\PerlMonks\digits1.pl aborted due to compilation errors +. D:\PerlMonks>

Fixed:

use strict; use warnings; print 'Please enter your card number'; chomp(my $inp = <>); $inp =~ s/(\d{4})(\d{4})(\d{4})(\d{4})/$1 $2 $3 $4/; print $inp,"\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1124814]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-16 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found