how to declare variable in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to declare variable in perl
# 1  
Old 08-23-2012
how to declare variable in perl

how can i declare variable in perl.

Code:
 for BLOCK in /sys/block/emcpow*

# 2  
Old 08-23-2012
That's not even how you declare a variable in shell... I think you mean, how do you *-globbing in perl.

Code:
foreach( </sys/block/emcpow*> )
{
        system("blockdev --setra 16384 $_");
}

Just one thing to realize: system() runs a shell exactly like the shell the scripts I already showed you ran in.

So you are not running perl instead of shell. You're running lots and lots of shells, with a tiny topping of pointless perl. (Sorry, it's a peeve of mine.)

Last edited by Corona688; 08-23-2012 at 06:49 PM..
# 3  
Old 08-23-2012
please check below code is it true.

Code:

foreach( </sys/block/emcpow*> )
{

 system("echo "noop"", "$_");
}

---------- Post updated at 04:55 PM ---------- Previous update was at 04:53 PM ----------

Another code in perl is correct please confirm

Code:
foreach( </sys/block/emcpow*> )
{
        blockdev --setra 16384 $_;
}

---------- Post updated at 05:24 PM ---------- Previous update was at 04:55 PM ----------

sir it is giving error

BLKRASET: Inappropriate ioctl for device when running below perl code.




Quote:
Originally Posted by Corona688
That's not even how you declare a variable in shell... I think you mean, how do you *-globbing in perl.

Code:
foreach( </sys/block/emcpow*> )
{
        system("blockdev --setra 16384 $_");
}

Just one thing to realize: system() runs a shell exactly like the shell the scripts I already showed you ran in.

So you are not running perl instead of shell. You're running lots and lots of shells, with a tiny topping of pointless perl. (Sorry, it's a peeve of mine.)
---------- Post updated at 05:37 PM ---------- Previous update was at 05:24 PM ----------

Please correct this

Code:
        system("echo "noop" > $_");

# 4  
Old 08-25-2012
system() takes one parameter, not two or three or four.

You can't put quotes in quotes like that. If you must, escape them like \".

I repeat. By doing this "in perl", you are actually doing this in lots and lots of shells. Every time you run system(), you are running /bin/sh. There is no purpose to using perl here.

Last edited by Corona688; 08-25-2012 at 04:19 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Declare and grep a variable via ssh/remote/loop

If I am running a bash command, and some awk getting the ethernet adapter on the local machine. It works fine. But if I will run it from the remote, it is EMPTY on echo and throwing error in grep. Thank you This work perfectly fine $ f=`/sbin/ip a|grep 127.127 | awk '{print $NF }' ` ; ip... (2 Replies)
Discussion started by: kenshinhimura
2 Replies

2. Shell Programming and Scripting

Perl help - how to assign output of perl to variable

Hi, guys, i have a script i inherited from a coworker but i'm not perl savy. The script works but i would like it to work better. I want to run this command ./ciscomgrtest.pl -r "show version" -h hosts.router and have the script goto each router in the hosts.router file and run the command... (2 Replies)
Discussion started by: whipuras
2 Replies

3. Shell Programming and Scripting

[CSH]legal to declare a variable like this

I am trying to declare a variable like this #!/bin/csh -f set c_arg = $a $b $c However, since i need it to declare before declaring $a ,$b or $c. As of now i am getting an error which says $a not defined. Is it possible to define a variable c_arg w/o interpreting the values $a $b $c (2 Replies)
Discussion started by: animesharma
2 Replies

4. Shell Programming and Scripting

how to Declare 5 values to one variable with OR operation

what I'm trying to do is ... need to drop tables w/ names like ABC_NY_2001 ABC_ORD_2001 ABC_TX_2001 ABC_CL_2001 For this, I want to write a query "DROP TABLE ABC_var_2001". now "var" should be either NY, ORD, TX or CL. I'm new to programming so don't know how to create a variable w/ OR... (3 Replies)
Discussion started by: ramsowji
3 Replies

5. Shell Programming and Scripting

How to declare a variable which can be accessed globally

Hi I've few shell scripts which are responsible for triggering the continuous builds for a specific module. Each shell script is for a Module. Shell script has some module specific settings in the beginning and then it triggers the builds (which are nothing but some combination of Java programs... (2 Replies)
Discussion started by: kgsrinivas
2 Replies

6. UNIX for Dummies Questions & Answers

declare variable

hi to all, i am trying to declare a variable as an integer in unix shell script. i search the web for a way to do it but it doesnt work. i tried "define -i" and "declare" but that doesnt work. if somebody knows another way to declare a variable as integer please help me. thank you (2 Replies)
Discussion started by: omonoiatis9
2 Replies

7. Shell Programming and Scripting

Unable to declare a variable in Cygwin

I recently installed Cygwin on my windows vista to practice on Linux\unix commands. I am unable to do a simple task of declaring variables on the command prompt I am trying: $ vech=Bus $ echo $vech bash: vech : command not found What am I missing? Do i need to add something to .bashrc? ... (1 Reply)
Discussion started by: erora
1 Replies

8. Programming

declare a variable in mysql

i have created a script to insert 100K rows into mysql db. But the forst line where i declare the variable is giving error. I am new to mysql. Can anyone help me in this? the script is ====================================== DECLARE c INT(10) := 54; BEGIN WHILE c <... (4 Replies)
Discussion started by: amitranjansahu
4 Replies

9. Shell Programming and Scripting

declare number variable in csh

Hi frind, i="1" while do echo "i is $i" data_file=$HYP_ROOT/import/efcextr$i.txt echo "$data_file" i=`expr $i + 1` done This is woring finly in ksh but not in ksh. in ksh it showing error i=1: Command not found i: Undefined variable Kindly help me ...why it is showing the error... (1 Reply)
Discussion started by: deep_kol
1 Replies

10. Shell Programming and Scripting

How to declare hashes in KSH similar to Perl ?

Hi, Is it possible to delcare hashes in KSH the way we do it in Perl. Like I want to declare something like: fruits="Juicy" fruits="healthy" fruits="sour" echo fruits Ofcourse this piece of code does not work in KSH. Please let me know if there is a way of doing it in KSH. ... (2 Replies)
Discussion started by: tipsy
2 Replies
Login or Register to Ask a Question