Solved

How to pass n,1 number of variables to Perl where n is not known?

Posted on 2011-03-02
3
255 Views
Last Modified: 2012-06-21
Hi,
I would like to pass multiple variables to perl. I used $ARGV[0] to capture the first input. However my function call will be like that:

perl mycode.pl 111111 222222 333333 444444 555555 'I am appending this to my field'

Now I don't know how many numbers I will have in the input. So this is unknown. And I will loop through for each of these numbers to append the string to a variable.

What I do is something like this which obviously does not work as expected:

foreach (@ARGV) {

$ssc->{'solution'} .= $ARGV[0];

}

Open in new window


I want to loop through the n number of times where n is the count of these numbers,let's say in this example 5 times, and append the last one to $ssc->{'solution'}

How can I do it?

Thanks,
0
Comment
Question by:Tolgar
3 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
Comment Utility
To double-check, you want the numbers appended to the solution, correct?

What do you want done with the last argument (the string)?
# get "rid" of trailing string
my $str = pop @ARGV;

# loop over numbers
foreach my $arg (@ARGV) {
    $ssc->{solution} .= $arg;
}

Open in new window

0
 

Author Comment

by:Tolgar
Comment Utility
Actually the string is to be appended to the solution. But I figured it out how to do it using your solution.

Thanks,

0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
$ssc->{solution} = "@ARGV";
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video discusses moving either the default database or any database to a new volume.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now