Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2011-03-02
3
Medium Priority
?
300 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 27

Accepted Solution

by:
wilcoxon earned 2000 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

650 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