Sponsored Content
Top Forums Shell Programming and Scripting PERL need help splitting argument Post 302432691 by durden_tyler on Friday 25th of June 2010 09:41:44 PM
Old 06-25-2010
Quote:
Originally Posted by 3junior
If i have a script name.pl
I run it like name.pl -v file.txt -t ext2 -u user -j
how can I edit the array @ARGV so when my script calls
$ARGV[0] = -v file.txt
$ARGV[3] = -j
I don't quite understand why you'd want to do that.
What you may want to do instead is - combine elements of @ARGV and assign them to your (separately defined) array. As shown below -

Code:
@x = ("$ARGV[0] $ARGV[1]", "$ARGV[2] $ARGV[3]", "$ARGV[4] $ARGV[5]", $ARGV[6]);

But this involves hard-coding, and you may also want to check for definedness before concatenation.

If you want greater control over your input arguments, you may want to check out the Getopt::Std module from CPAN.

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

splitting on dot in perl

I am trying to split input that looks like ,2005-09-12 01:45:00.000000,2005-09-12 01:48:18.000000, I want to split on the dot . What I am using is ($ev_time,$rol)=split(/\./),$inputfile; This does not recognize the dot as what I want to split on. (2 Replies)
Discussion started by: reggiej
2 Replies

2. Shell Programming and Scripting

not null cheking of an argument in perl

Hi, I have to check whether an argument say $ARGV is not null in an if operator. Please let me know the operator. It would be great if you write a psuedo code. Thanks in advance Ammu (4 Replies)
Discussion started by: ammu
4 Replies

3. Shell Programming and Scripting

Perl - Need help on splitting string

Let's say I have a very long string with no spaces but just words stored in $very_long_string. $very_long_string = "aaaaaaaaaaabbbbbbbbbbbccccccccccccdddddddddddd"; I can do this to split the string into 1 character each and store them in an array: @myArray = split(//, $very_long_string); ... (3 Replies)
Discussion started by: teiji
3 Replies

4. Shell Programming and Scripting

Perl Programming for Splitting

Hi, I am extracting SQL queries into a file and the file is as follows ********************************************************* select BatchKey ,restartStatus ,batchContextBuffer ,batchPgmId ,StartKey , EndKey ,Mcbatchcontrol_ver from qsecminload.Mcbatchcontrol_t where RefId = :1 ... (5 Replies)
Discussion started by: sagarbsa
5 Replies

5. Shell Programming and Scripting

Perl Parsing Argument

i wanna passing an argument which read in a file or a set of files if the files are given in the command line, otherwise use STDIN if no file argument. i got something like that, but it is not really working. so can anyone help me? which one is better to use for and how? Use perl. Thank you ... (0 Replies)
Discussion started by: mingming88
0 Replies

6. Shell Programming and Scripting

How to use perl to run bash with argument?

Hi All, I want to run a bash script using perl. But they are in the different dir. #! /usr/bin/perl -w use strict; my $root=`pwd`; chomp($root); my $cmd=".$root/testdir/ft_623.sh 3 4 5 6 7"; print $cmd; my @line=`$cmd`; foreach (@line){ print $_; } ft_623.sh (0 Replies)
Discussion started by: Damon sine
0 Replies

7. Shell Programming and Scripting

parsing argument in perl

in bash: LIST=`cat $1` for i in $LIST do ... done how will i do this in perl ? $1 is my first arguement. I'm a newbie in perl and will appreciate much your help guys ... (4 Replies)
Discussion started by: linuxgeek
4 Replies

8. Shell Programming and Scripting

perl, splitting out specific parts of the string

Hi there, I have an output from a command like this # ypcat -k netgroup.byuser| grep steven steven.* users_main,users_sysadmin,users_global,users_backup_team and wanted to pull the 'users' netgroups returned into a perl array, that will look like this users_main... (2 Replies)
Discussion started by: rethink
2 Replies

9. Shell Programming and Scripting

Splitting a file into several smaller files using perl

Hi, I'm trying to split a large file into several smaller files the script will have two input arguments argument1=filename and argument2=no of files to be split. In my large input file I have a header followed by 100009 records The first line is a header; I want this header in all my... (9 Replies)
Discussion started by: ramky79
9 Replies

10. Shell Programming and Scripting

perl : splitting the data into 2 different variables

I have a perl variable which contains the below value. $var1 = "2% / 51%" Now I would like to split the data into 2 different variables. For example $part1 = 2 $part2 = 51 Could anyone please help me in this regard ? Regards, GS (4 Replies)
Discussion started by: giridhar276
4 Replies
MooseX::Getopt::ProcessedArgv(3pm)			User Contributed Perl Documentation			MooseX::Getopt::ProcessedArgv(3pm)

NAME
MooseX::Getopt::ProcessedArgv - MooseX::Getopt::ProcessedArgv - Class containing the results of process_argv VERSION
version 0.59 SYNOPSIS
use My::App; my $pa = My::App->process_argv(@params); my $argv_copy = $pa->argv_copy(); my $extra_argv = $pa->extra_argv(); my $usage = $pa->usage(); my $constructor_params = $pa->constructor_params(); my $cli_params = $pa->cli_params(); DESCRIPTION
This object contains the result of a "process_argv" in MooseX::Getopt call. It contains all the information that "new_with_options" in MooseX::Getopt uses when calling new. METHODS
argv_copy Reference to a copy of the original @ARGV array as it originally existed at the time of "new_with_options". extra_arg Arrayref of leftover @ARGV elements that Getopt::Long did not parse. usage Contains the Getopt::Long::Descriptive::Usage object (if Getopt::Long::Descriptive is used). constructor_params Parameters passed to process_argv. cli_param Command-line parameters parsed out of @ARGV. AUTHOR
Stevan Little <stevan@iinteractive.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2007 by Infinity Interactive, Inc. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.18.2 2013-11-30 MooseX::Getopt::ProcessedArgv(3pm)
All times are GMT -4. The time now is 01:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy