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
Solved

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

Posted on 2011-03-02
3
282 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
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

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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

856 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