Solved

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

Posted on 2011-03-02
3
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 35019272
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
ID: 35019665
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
ID: 35021867
$ssc->{solution} = "@ARGV";
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans

705 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