Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ARGV into a $var

Status
Not open for further replies.

AcidHawk

Technical User
Joined
Mar 14, 2001
Messages
17
Location
ZA
Hi

I'm trying to get the 3rd parameter to the last parameter put into a scalar variable.

I then want to split the scalar var(no problems here though..)

This is not working..
Code:
$var = @ARGV[2..$#ARGV];
print $var;

If i run this like so..

perl prog.pl useless useless var:i:want:up until this

$var prints out as only 'this'

I want $var to be 'var:i:want:up until this'

I don't know how many parameters are going to be sent to the command line.. I do want them all though, hence the need to use something like $#ARGV

is this possible..?
----
Of All the things I've lost in my life it's my mind I miss the most.
 
Yes this can be done using the join command:
Code:
$var = join ":", @ARGV[ 2 .. $#ARGV ];

Cheers, Neil
 
I just put " " around the ARGV stuff and it works..

Code:
$var = "@ARGV[2..$#ARGV]";
print $var;

Cheers
----
Of All the things I've lost in my life it's my mind I miss the most.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top