CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Need help with script: Edit Log



Tszs
New User

Apr 22, 2018, 8:28 AM


Views: 5300
Need help with script

Hey all, started learning perl so I need some help with one script:


Code
#!/usr/bin/perl 
print "How much elements in array n:\n";
$n=<>;
print "Number which you wanna change to 0:\n";
$a=<>;
for ($i=1 ; $i<=$n ; $i++){
print "Enter array element:\n";
$array[$i]=<>;
chomp($array[$i]);
}
foreach (@array){
s/$a/0/;
}
print "New array: @array \n";


I need to change all elements which equal to $a which I enter, to 0.


(This post was edited by Tszs on Apr 22, 2018, 8:29 AM)


Edit Log:
Post edited by Tszs (New User) on Apr 22, 2018, 8:29 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives