Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl CPAN issue 3 121
Is it possible to get a piece of info in a line from a big text file with perl? 7 73
Exchange 2010 Transport Rule Regex 28 133
File Find regex problem 4 68
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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

730 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